3
v^                 @   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             K   s\  | 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r.|j
tjd| |dd t| jtrX|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)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   AUTH_USER_MODELsplitlabel
isinstanceZREQUIRED_FIELDSlisttupleappendr   ErrorZUSERNAME_FIELD_meta	get_fielduniqueAUTHENTICATION_BACKENDSobject_nameWarningZis_anonymousr   Criticalis_authenticated)app_configskwargscls	app_label
model_name
app_configerrors r%   >/usr/lib/python3.6/site-packages/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>e   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*   p   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.   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_permissionsa   sV    





r<   )N)N)	itertoolsr   typesr   django.appsr   django.confr   django.corer   
managementr   r'   r<   r%   r%   r%   r&   <module>   s   
V