B
    CVvgN   ã               @   s`   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 ddl
mZ dd	d
„Zddd„ZdS )é    )Úchain)Ú
MethodType)Úapps)Úsettings)Úchecksé   )Ú_get_builtin_permissionsNc                sˆ  | d krt  tj¡‰ n8tj d¡\}}x&| D ]}|j|kr,| |¡‰ P q,W g S g }tˆ jtt	fƒsx| 
tjdˆ dd�¡ ˆ jˆ jkr¨| 
tjddˆ jˆ jf ˆ dd�¡ ˆ j ˆ j¡j�s0t‡ fd	d
„ˆ jjD ƒƒ�s0tjdgk�r
| 
tjdˆ jjˆ jf ˆ dd�¡ n&| 
tjdˆ jjˆ jf dˆ dd�¡ tˆ ƒ jtƒ�rZ| 
tjdˆ  ˆ dd�¡ tˆ ƒ jtƒ�r„| 
tjdˆ  ˆ dd�¡ |S )NÚ.z*'REQUIRED_FIELDS' must be a list or tuple.z	auth.E001)ÚobjÚidzjThe field named as the 'USERNAME_FIELD' for a custom user model must not be included in 'REQUIRED_FIELDS'.zaThe 'USERNAME_FIELD' is currently set to '%s', you should remove '%s' from the 'REQUIRED_FIELDS'.z	auth.E002)Zhintr
   r   c             3   s   | ]}|j ˆ jfkV  qd S )N)ÚfieldsÚUSERNAME_FIELD)Ú.0Ú
constraint)Úcls© ú>/tmp/pip-install-o3oxmrkh/Django/django/contrib/auth/checks.pyú	<genexpr>8   s   z#check_user_model.<locals>.<genexpr>z)django.contrib.auth.backends.ModelBackendzC'%s.%s' must be unique because it is named as the 'USERNAME_FIELD'.z	auth.E003z?'%s.%s' is named as the 'USERNAME_FIELD', but it is not unique.zKEnsure that your authentication backend(s) can handle non-unique usernames.z	auth.W004z�%s.is_anonymous must be an attribute or property rather than a method. Ignoring this is a security issue as anonymous users will be treated as authenticated!z	auth.C009z¡%s.is_authenticated must be an attribute or property rather than a method. Ignoring this is a security issue as anonymous users will be treated as authenticated!z	auth.C010)r   Ú	get_modelr   ZAUTH_USER_MODELÚsplitÚlabelÚ
isinstanceZREQUIRED_FIELDSÚlistÚtupleÚappendr   ÚErrorr   Ú_metaÚ	get_fieldÚuniqueÚanyZtotal_unique_constraintsZAUTHENTICATION_BACKENDSZobject_nameÚWarningZis_anonymousr   ZCriticalÚis_authenticated)Úapp_configsÚkwargsZ	app_labelÚ
model_nameÚ
app_configÚerrorsr   )r   r   Úcheck_user_model   sp    









r'   c          	   K   s  | d krt  ¡ }nt dd„ | D ƒ¡}t  dd¡}|j d¡j}|j d¡j}g }�x²|D �]¨}|j}tt	|ƒƒ}	|	rŒt
dd„ |	 ¡ D ƒƒnd}
|
|krÌ||
t|jƒ  }| tjd	|j||f |d
d�¡ |	ræt
dd„ |	 ¡ D ƒƒnd}||k�r(||t|jƒ  }| tjd|j||f |dd�¡ tƒ }xÔ|jD ]Ê\}}t|ƒ|k�rn| tjd||j|f |dd�¡ t|ƒ|k�rž| tjd||j|f |dd�¡ ||	k�rÊ| tjd||jf |dd�¡ n*||k�rô| tjd||jf |dd�¡ | |¡ �q6W qZW |S )Nc             s   s   | ]}|  ¡ V  qd S )N)Ú
get_models)r   r%   r   r   r   r   m   s    z+check_models_permissions.<locals>.<genexpr>ÚauthÚ
PermissionÚnameÚcodenamec             s   s   | ]}t |ƒV  qd S )N)Úlen)r   r+   r   r   r   r   y   s    r   zzThe verbose_name of model '%s' must be at most %d characters for its builtin permission names to be at most %d characters.z	auth.E007)r
   r   c             s   s   | ]}t |ƒV  qd S )N)r-   )r   r,   r   r   r   r   �   s    zvThe name of model '%s' must be at most %d characters for its builtin permission codenames to be at most %d characters.z	auth.E011zEThe permission named '%s' of model '%s' is longer than %d characters.z	auth.E008zIThe permission codenamed '%s' of model '%s' is longer than %d characters.z	auth.E012zOThe permission codenamed '%s' clashes with a builtin permission for model '%s'.z	auth.E005z;The permission codenamed '%s' is duplicated for model '%s'.z	auth.E006)r   r(   r   Úfrom_iterabler   r   r   Ú
max_lengthÚdictr   ÚmaxÚvaluesr-   Zverbose_name_rawr   r   r   r   Úkeysr$   ÚsetÚpermissionsÚadd)r"   r#   Úmodelsr*   Zpermission_name_max_lengthZpermission_codename_max_lengthr&   ÚmodelÚoptsZbuiltin_permissionsZ"max_builtin_permission_name_lengthZverbose_name_max_lengthZ&max_builtin_permission_codename_lengthZmodel_name_max_lengthZ	codenamesr,   r+   r   r   r   Úcheck_models_permissionsi   s‚    










r:   )N)N)Ú	itertoolsr   Útypesr   Zdjango.appsr   Zdjango.confr   Zdjango.corer   Z
managementr   r'   r:   r   r   r   r   Ú<module>   s   
^