3
(h(                 @   sl   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lmZ dd
dZdddZd	S )    )unicode_literals)chain)apps)settings)checks)six   )_get_builtin_permissionsNc             K   sd  | d krt jtj}n8tjjd\}}x&| D ]}|j|kr,|j|}P q,W g S g }t|jtt	fsx|j
tjd|dd |j|jkr|j
tjd|dd |jj|jjstjdgkr|j
tjd|jj|jf |d	d n&|j
tjd
|jj|jf d|dd t| jtjjr2|j
tjd| |dd t| jtjjr`|j
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'.z	auth.E002z)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.W004)Zhintr   r   z%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   ErrorZUSERNAME_FIELD_meta	get_fielduniqueZAUTHENTICATION_BACKENDSobject_nameWarningZis_anonymousr   types
MethodTypeZCriticalis_authenticated)app_configskwargscls	app_labelZ
model_name
app_configerrors r#   >/tmp/pip-install-q3hcpn_q/Django/django/contrib/auth/checks.pycheck_user_model   sh    







r%   c          	   K   s  | d krt j }ntjdd | D }t jdd}|jjdj}g }x4|D ]*}|j}tt	|}|r~t
dd |j D nd}	|	|kr||	t|j  }
|jtjd|j|j|
|f |d	d
 t }x|jD ]\}}t||kr|jtjd||j|j|f |dd
 ||kr<|jtjd||j|jf |dd
 n.||krj|jtjd||j|jf |dd
 |j| qW qLW |S )Nc             s   s   | ]}|j  V  qd S )N)
get_models).0r!   r#   r#   r$   	<genexpr>h   s    z+check_models_permissions.<locals>.<genexpr>auth
Permissionnamec             s   s   | ]}t |V  qd S )N)len)r'   r+   r#   r#   r$   r(   s   s    r   z}The verbose_name of model '%s.%s' must be at most %d characters for its builtin permission names to be at most %d characters.z	auth.E007)r   r   zHThe permission named '%s' of model '%s.%s' is longer than %d characters.z	auth.E008zRThe permission codenamed '%s' clashes with a builtin permission for model '%s.%s'.z	auth.E005z>The permission codenamed '%s' is duplicated for model '%s.%s'.z	auth.E006)r   r&   r   from_iterabler   r   r   
max_lengthdictr	   maxvaluesr,   Zverbose_name_rawr   r   r   r    r   setpermissionsadd)r   r   modelsr*   Zpermission_name_max_lengthr"   modeloptsZbuiltin_permissionsZ"max_builtin_permission_name_lengthZverbose_name_max_lengthZ	codenamescodenamer+   r#   r#   r$   check_models_permissionsd   sV    





r9   )N)N)
__future__r   	itertoolsr   Zdjango.appsr   Zdjango.confr   Zdjango.corer   Zdjango.utilsr   Z
managementr	   r%   r9   r#   r#   r#   r$   <module>   s   
V