o
    —¨ÊhvÂ  ã                   @   s  d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	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mZmZ d dlmZ d dlmZ d dlmZ dd„ Zdd„ Z dd„ Z!dd„ Z"G dd„ dƒZ#G dd„ de#ƒZ$G dd„ de#ƒZ%dd„ Z&dd „ Z'd!d"„ Z(dS )#é    N)Úchain)Úapps)Úsettings)ÚNotRelationFieldÚflattenÚget_fields_from_path)Úchecks)ÚFieldDoesNotExist)Úmodels)Ú
LOOKUP_SEP)Ú
Combinable)ÚBaseModelFormÚBaseModelFormSetÚ_get_foreign_key)Úengines)ÚDjangoTemplates)Úimport_stringc                 C   s"   zt | |ƒW S  ty   Y dS w )zX
    issubclass() variant that doesn't raise an exception if cls isn't a
    class.
    F)Ú
issubclassÚ	TypeError)ÚclsÚ	classinfo© r   úM/var/www/html/env/lib/python3.10/site-packages/django/contrib/admin/checks.pyÚ_issubclass   s
   ÿr   c              	   C   sF   t | ƒ}|D ]}zt |ƒ}W n	 ty   Y qw t||ƒr  dS qdS )z|
    Return whether or not a dotted class path (or a subclass of that class) is
    found in a list of candidate paths.
    TF)r   ÚImportErrorr   )Ú
class_pathÚcandidate_pathsr   ÚpathÚcandidate_clsr   r   r   Ú_contains_subclass   s   þ
ÿr   c                 K   s.   ddl m} g }|D ]
}| | | ¡¡ q
|S )Nr   ©Ú	all_sites)Údjango.contrib.admin.sitesr!   ÚextendÚcheck)Úapp_configsÚkwargsr!   ÚerrorsÚsiter   r   r   Úcheck_admin_app.   s
   r)   c            	      K   sx  ddl m} t d¡sg S g }d}|D ]\}}t |¡s*| tjd| d| d�¡ qt ¡ D ]}t	|t
ƒr;|j} nq/d}|sK| tjd	d
d�¡ n>d|jvr`tdtjƒr`| tjddd�¡ d|jvro| tjddd�¡ tdd„ |D ƒƒ}|r‰d|jvr‰| tjddd�¡ tdtjƒs™| tjddd�¡ tdtjƒs©| tjddd�¡ tdtjƒsº| tjddd d!�¡ |S )"zF
    Check that the admin's dependencies are correctly installed.
    r   r    zdjango.contrib.admin))zdjango.contrib.contenttypesi‘  )zdjango.contrib.authi•  )zdjango.contrib.messagesi–  zE'%s' must be in INSTALLED_APPS in order to use the admin application.z	admin.E%d)ÚidNzƒA 'django.template.backends.django.DjangoTemplates' instance must be configured in TEMPLATES in order to use the admin application.z
admin.E403z+django.contrib.auth.context_processors.authz)django.contrib.auth.backends.ModelBackendz¥'django.contrib.auth.context_processors.auth' must be enabled in DjangoTemplates (TEMPLATES) if using the default auth backend in order to use the admin application.z
admin.E402z3django.contrib.messages.context_processors.messagesz‹'django.contrib.messages.context_processors.messages' must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin application.z
admin.E404c                 s   s   � | ]}|j V  qd S ©N)Úenable_nav_sidebar)Ú.0r(   r   r   r   Ú	<genexpr>z   s   € z%check_dependencies.<locals>.<genexpr>z*django.template.context_processors.requestz‰'django.template.context_processors.request' must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin navigation sidebar.z
admin.W411z7django.contrib.auth.middleware.AuthenticationMiddlewarezv'django.contrib.auth.middleware.AuthenticationMiddleware' must be in MIDDLEWARE in order to use the admin application.z
admin.E408z4django.contrib.messages.middleware.MessageMiddlewarezs'django.contrib.messages.middleware.MessageMiddleware' must be in MIDDLEWARE in order to use the admin application.z
admin.E409z4django.contrib.sessions.middleware.SessionMiddlewarezs'django.contrib.sessions.middleware.SessionMiddleware' must be in MIDDLEWARE in order to use the admin application.zInsert 'django.contrib.sessions.middleware.SessionMiddleware' before 'django.contrib.auth.middleware.AuthenticationMiddleware'.z
admin.E410)Úhintr*   )r"   r!   r   Úis_installedÚappendr   ÚErrorr   ÚallÚ
isinstancer   ÚengineÚcontext_processorsr   r   ÚAUTHENTICATION_BACKENDSÚanyÚWarningÚ
MIDDLEWARE)	r&   r!   r'   Úapp_dependenciesÚapp_nameÚ
error_coder5   Údjango_templates_instanceÚsidebar_enabledr   r   r   Úcheck_dependencies7   sº   

ÿýÿ€
þüÿ
ÿþþüÿ	ÿüÿÿÿüÿ	ÿýÿÿýÿÿ÷ÿr@   c                   @   sä   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7S )8ÚBaseModelAdminChecksc                 K   s†   g |   |¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢|  	|¡¢|  
|¡¢|  |¡¢|  |¡¢S r+   )Ú_check_autocomplete_fieldsÚ_check_raw_id_fieldsÚ_check_fieldsÚ_check_fieldsetsÚ_check_excludeÚ_check_formÚ_check_filter_verticalÚ_check_filter_horizontalÚ_check_radio_fieldsÚ_check_prepopulated_fieldsÚ_check_view_on_site_urlÚ_check_orderingÚ_check_readonly_fields©ÚselfÚ	admin_objr&   r   r   r   r$   ±   s6   ÿþýüûúùø	÷
öõôózBaseModelAdminChecks.checkc                    óD   t ˆ jttfƒstddˆ dd�S tt ‡ ‡fdd„tˆ jƒD ƒ¡ƒS )zV
        Check that `autocomplete_fields` is a list or tuple of model fields.
        úa list or tupleÚautocomplete_fieldsz
admin.E036©ÚoptionÚobjr*   c                    s"   g | ]\}}ˆ  ˆ |d | ¡‘qS )zautocomplete_fields[%d])Ú_check_autocomplete_fields_item©r-   ÚindexÚ
field_name©rW   rP   r   r   Ú
<listcomp>Ð   s    ý
ÿÿzCBaseModelAdminChecks._check_autocomplete_fields.<locals>.<listcomp>)r4   rT   ÚlistÚtupleÚmust_ber   Úfrom_iterableÚ	enumerate©rP   rW   r   r\   r   rB   Â   s   üüÿÿz/BaseModelAdminChecks._check_autocomplete_fieldsc              	   C   sÊ   z	|j j |¡}W n ty   t|||dd� Y S w |js,t|tjƒs,t	d||dd�S |j
j |jj ¡}|du rMtjd|jj jt|ƒjf |jdd	�gS |jsctjd
|jjt|ƒjf |jdd	�gS g S )z¹
        Check that an item in `autocomplete_fields` is a ForeignKey or a
        ManyToManyField and that the item has a related ModelAdmin with
        search_fields defined.
        z
admin.E037©ÚfieldrV   rW   r*   ú%a foreign key or a many-to-many fieldz
admin.E038rU   NzXAn admin for model "%s" has to be registered to be referenced by %s.autocomplete_fields.z
admin.E039©rW   r*   zR%s must define "search_fields", because it's referenced by %s.autocomplete_fields.z
admin.E040)ÚmodelÚ_metaÚ	get_fieldr	   Úrefer_to_missing_fieldÚmany_to_manyr4   r
   Ú
ForeignKeyr`   Ú
admin_siteÚ	_registryÚgetÚremote_fieldr   r2   Ú__name__ÚtypeÚ	__class__Úsearch_fields)rP   rW   r[   Úlabelre   Úrelated_adminr   r   r   rX   Ù   sL   
ÿÿüþþøÿþþøÿz4BaseModelAdminChecks._check_autocomplete_fields_itemc                    rR   )zZCheck that `raw_id_fields` only contains field names that are listed
        on the model.rS   Úraw_id_fieldsz
admin.E001rU   c                 3   ó&   � | ]\}}ˆ  ˆ |d | ¡V  qdS )zraw_id_fields[%d]N)Ú_check_raw_id_fields_itemrY   r\   r   r   r.     ó   € ý
ÿ
ÿz<BaseModelAdminChecks._check_raw_id_fields.<locals>.<genexpr>)r4   rx   r^   r_   r`   r   ra   rb   rc   r   r\   r   rC   
  ó   ÿüÿz)BaseModelAdminChecks._check_raw_id_fieldsc              	   C   sv   z	|j j |¡}W n ty   t|||dd� Y S w |j|kr(t|||dd�S |js9t|tj	ƒs9t
d||dd�S g S )zœCheck an item of `raw_id_fields`, i.e. check that field named
        `field_name` exists in model `model` and is a ForeignKey or a
        ManyToManyField.z
admin.E002rd   rf   z
admin.E003rU   )rh   ri   rj   r	   rk   Únamerl   r4   r
   rm   r`   ©rP   rW   r[   rv   re   r   r   r   rz     s,   
ÿÿ
üüz.BaseModelAdminChecks._check_raw_id_fields_itemc                    sš   ˆ j du rg S tˆ j ttfƒstddˆ dd�S ˆ jr$tjdˆ jdd�gS t	ˆ j ƒ}t
|ƒt
t|ƒƒkr=tjd	ˆ jd
d�gS tt ‡ ‡fdd„ˆ j D ƒ¡ƒS )zœCheck that `fields` only refer to existing fields, doesn't contain
        duplicates. Check if at most one of `fields` and `fieldsets` is defined.
        NrS   Úfieldsz
admin.E004rU   z,Both 'fieldsets' and 'fields' are specified.z
admin.E005rg   z2The value of 'fields' contains duplicate field(s).z
admin.E006c                 3   s   � | ]
}ˆ  ˆ |d ¡V  qdS )r   N©Ú_check_field_spec)r-   r[   r\   r   r   r.   V  s
   € ÿ
ÿz5BaseModelAdminChecks._check_fields.<locals>.<genexpr>)r   r4   r^   r_   r`   Ú	fieldsetsr   r2   rt   r   ÚlenÚsetr   ra   )rP   rW   r   r   r\   r   rD   :  s0   
ýÿ
ýÿþÿz"BaseModelAdminChecks._check_fieldsc                    sX   ˆ j du rg S tˆ j ttfƒstddˆ dd�S g ‰tt ‡ ‡‡fdd„tˆ j ƒD ƒ¡ƒS )zRCheck that fieldsets is properly formatted and doesn't contain
        duplicates.NrS   r‚   z
admin.E007rU   c                 3   s(   � | ]\}}ˆ  ˆ |d | ˆ¡V  qdS )zfieldsets[%d]N)Ú_check_fieldsets_item)r-   rZ   Úfieldset©rW   Úseen_fieldsrP   r   r   r.   i  s   € ýÿ
ÿz8BaseModelAdminChecks._check_fieldsets.<locals>.<genexpr>)r‚   r4   r^   r_   r`   r   ra   rb   rc   r   r‡   r   rE   \  s   
ÿüÿz%BaseModelAdminChecks._check_fieldsetsc                    s  t |ttfƒstdˆ ˆdd�S t|ƒdkrtdˆ ˆdd�S t |d tƒs.tdd	ˆ  ˆd
d�S d|d vr@tjdˆ  ˆjdd�gS t |d d ttfƒsUtddˆ  ˆdd�S | 	t
|d d ƒ¡ t|ƒtt|ƒƒkrvtjdˆ  ˆjdd�gS tt ‡ ‡‡fdd„|d d D ƒ¡ƒS )z|Check an item of `fieldsets`, i.e. check that this is a pair of a
        set name and a dictionary containing "fields" key.rS   z
admin.E008rU   é   zof length 2z
admin.E009é   úa dictionaryú%s[1]z
admin.E010r   z3The value of '%s[1]' must contain the key 'fields'.z
admin.E011rg   z%s[1]['fields']z(There are duplicate field(s) in '%s[1]'.z
admin.E012c                 3   s"   � | ]}ˆ  ˆ|d ˆ  ¡V  qdS )z%s[1]["fields"]Nr€   )r-   Úfieldset_fields©rv   rW   rP   r   r   r.   —  s
   € ÿ
ÿz=BaseModelAdminChecks._check_fieldsets_item.<locals>.<genexpr>)r4   r^   r_   r`   rƒ   Údictr   r2   rt   r#   r   r„   r   ra   )rP   rW   r†   rv   rˆ   r   rŽ   r   r…   q  sF   ÿýÿüýÿ
þÿz*BaseModelAdminChecks._check_fieldsets_itemc                    s<   t |tƒrtt ‡ ‡‡fdd„t|ƒD ƒ¡ƒS ˆ ˆ|ˆ ¡S )z²`fields` should be an item of `fields` or an item of
        fieldset[1]['fields'] for any `fieldset` in `fieldsets`. It should be a
        field name or a tuple of field names.c                 3   ó*   � | ]\}}ˆ  ˆ|d ˆ |f ¡V  qdS )z%s[%d]N)Ú_check_field_spec_itemrY   rŽ   r   r   r.   ¤  ó   € ýÿ
ÿz9BaseModelAdminChecks._check_field_spec.<locals>.<genexpr>)r4   r_   r^   r   ra   rb   r‘   )rP   rW   r   rv   r   rŽ   r   r�   �  s   
üÿ	z&BaseModelAdminChecks._check_field_specc                 C   sp   ||j v rg S z	|jj |¡}W n ty   g  Y S w t|tjƒr6|jj	jj
s6tjd||f |jdd�gS g S )NzvThe value of '%s' cannot include the ManyToManyField '%s', because that field manually specifies a relationship model.z
admin.E013rg   )Úreadonly_fieldsrh   ri   rj   r	   r4   r
   ÚManyToManyFieldrq   ÚthroughÚauto_createdr   r2   rt   r~   r   r   r   r‘   ®  s(   
ý
ÿ
þþûÿ
z+BaseModelAdminChecks._check_field_spec_itemc                 C   s^   |j du rg S t|j ttfƒstdd|dd�S t|j ƒtt|j ƒƒkr-tjd|j	dd�gS g S )	z4Check that exclude is a sequence without duplicates.NrS   Úexcludez
admin.E014rU   z3The value of 'exclude' contains duplicate field(s).z
admin.E015rg   )
r—   r4   r^   r_   r`   rƒ   r„   r   r2   rt   rc   r   r   r   rF   Ì  s   
ÿýÿz#BaseModelAdminChecks._check_excludec                 C   ó    t |jtƒstdd|dd�S g S )z)Check that form subclasses BaseModelForm.r   Úformz
admin.E016©ÚparentrV   rW   r*   )r   r™   r   Úmust_inherit_fromrc   r   r   r   rG   à  s
   ÿz BaseModelAdminChecks._check_formc                    rR   )z8Check that filter_vertical is a sequence of field names.rS   Úfilter_verticalz
admin.E017rU   c                 3   ry   )zfilter_vertical[%d]N©Ú_check_filter_itemrY   r\   r   r   r.   ñ  r{   z>BaseModelAdminChecks._check_filter_vertical.<locals>.<genexpr>)r4   r�   r^   r_   r`   r   ra   rb   rc   r   r\   r   rH   é  ó   ÿüÿz+BaseModelAdminChecks._check_filter_verticalc                    rR   )z:Check that filter_horizontal is a sequence of field names.rS   Úfilter_horizontalz
admin.E018rU   c                 3   ry   )zfilter_horizontal[%d]Nrž   rY   r\   r   r   r.     r{   z@BaseModelAdminChecks._check_filter_horizontal.<locals>.<genexpr>)r4   r¡   r^   r_   r`   r   ra   rb   rc   r   r\   r   rI   ù  r    z-BaseModelAdminChecks._check_filter_horizontalc              	   C   sP   z	|j j |¡}W n ty   t|||dd� Y S w |js&td||dd�S g S )z€Check one item of `filter_vertical` or `filter_horizontal`, i.e.
        check that given field exists and is a ManyToManyField.z
admin.E019rd   za many-to-many fieldz
admin.E020rU   )rh   ri   rj   r	   rk   rl   r`   r~   r   r   r   rŸ   	  s   
ÿÿÿz'BaseModelAdminChecks._check_filter_itemc                    ó@   t ˆ jtƒstddˆ dd�S tt ‡ ‡fdd„ˆ j ¡ D ƒ¡ƒS )z*Check that `radio_fields` is a dictionary.r‹   Úradio_fieldsz
admin.E021rU   c                 3   ó4   � | ]\}}ˆ  ˆ |d ¡ˆ ˆ |d| ¡ V  qdS )r£   zradio_fields["%s"]N)Ú_check_radio_fields_keyÚ_check_radio_fields_value©r-   r[   Úvalr\   r   r   r.   #  s   € ü
ÿÿ
ÿz;BaseModelAdminChecks._check_radio_fields.<locals>.<genexpr>)r4   r£   r�   r`   r^   r   ra   Úitemsrc   r   r\   r   rJ     s   ÿûÿz(BaseModelAdminChecks._check_radio_fieldsc              	   C   sh   z	|j j |¡}W n ty   t|||dd� Y S w t|tjƒs2|js2t	j
d||f |jdd�gS g S )zŒCheck that a key of `radio_fields` dictionary is name of existing
        field and that the field is a ForeignKey or has `choices` defined.z
admin.E022rd   zsThe value of '%s' refers to '%s', which is not an instance of ForeignKey, and does not have a 'choices' definition.z
admin.E023rg   )rh   ri   rj   r	   rk   r4   r
   rm   Úchoicesr   r2   rt   r~   r   r   r   r¥   ,  s"   
ÿÿþûÿ
z,BaseModelAdminChecks._check_radio_fields_keyc                 C   s8   ddl m}m} |||fvrtjd| |jdd�gS g S )z3Check type of a value of `radio_fields` dictionary.r   )Ú
HORIZONTALÚVERTICALzDThe value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL.z
admin.E024rg   )Údjango.contrib.admin.optionsr«   r¬   r   r2   rt   )rP   rW   r¨   rv   r«   r¬   r   r   r   r¦   D  s   ÿüÿ	z.BaseModelAdminChecks._check_radio_fields_valuec                 C   s.   t |jƒst|jtƒstjd|jdd�gS g S )NzBThe value of 'view_on_site' must be a callable or a boolean value.z
admin.E025rg   )ÚcallableÚview_on_siter4   Úboolr   r2   rt   rc   r   r   r   rL   U  s   üÿ	z,BaseModelAdminChecks._check_view_on_site_urlc                    r¢   )zXCheck that `prepopulated_fields` is a dictionary containing allowed
        field types.r‹   Úprepopulated_fieldsz
admin.E026rU   c                 3   r¤   )r±   zprepopulated_fields["%s"]N)Ú_check_prepopulated_fields_keyÚ _check_prepopulated_fields_valuer§   r\   r   r   r.   k  s   € úÿ
ÿý
ÿzBBaseModelAdminChecks._check_prepopulated_fields.<locals>.<genexpr>)r4   r±   r�   r`   r^   r   ra   r©   rc   r   r\   r   rK   b  s   ÿùÿz/BaseModelAdminChecks._check_prepopulated_fieldsc              	   C   sl   z	|j j |¡}W n ty   t|||dd� Y S w t|tjtjtj	fƒr4t
jd||f |jdd�gS g S )z›Check a key of `prepopulated_fields` dictionary, i.e. check that it
        is a name of existing field and the field is one of the allowed types.
        z
admin.E027rd   zyThe value of '%s' refers to '%s', which must not be a DateTimeField, a ForeignKey, a OneToOneField, or a ManyToManyField.z
admin.E028rg   )rh   ri   rj   r	   rk   r4   r
   ÚDateTimeFieldrm   r”   r   r2   rt   r~   r   r   r   r²   v  s&   
ÿÿÿþûÿ
z3BaseModelAdminChecks._check_prepopulated_fields_keyc                    sB   t |ttfƒstdˆ ˆdd�S tt ‡ ‡‡fdd„t|ƒD ƒ¡ƒS )zdCheck a value of `prepopulated_fields` dictionary, i.e. it's an
        iterable of existing fields.rS   z
admin.E029rU   c                 3   r�   )z%s[%r]N)Ú%_check_prepopulated_fields_value_item)r-   rZ   Úsubfield_namerŽ   r   r   r.   ™  r’   zHBaseModelAdminChecks._check_prepopulated_fields_value.<locals>.<genexpr>)r4   r^   r_   r`   r   ra   rb   )rP   rW   r¨   rv   r   rŽ   r   r³   ‘  s   üÿz5BaseModelAdminChecks._check_prepopulated_fields_valuec              	   C   s8   z
|j j |¡ W g S  ty   t|||dd� Y S w )zYFor `prepopulated_fields` equal to {"slug": ("title",)},
        `field_name` is "title".z
admin.E030rd   )rh   ri   rj   r	   rk   ©rP   rW   r[   rv   r   r   r   rµ   ¡  s   û
ÿÿz:BaseModelAdminChecks._check_prepopulated_fields_value_itemc                    sR   ˆ j du rg S tˆ j ttfƒstddˆ dd�S tt ‡ ‡fdd„tˆ j ƒD ƒ¡ƒS )z;Check that ordering refers to existing fields or is random.NrS   Úorderingz
admin.E031rU   c                 3   ry   )zordering[%d]N)Ú_check_ordering_itemrY   r\   r   r   r.   º  ó
   € ÿ
ÿz7BaseModelAdminChecks._check_ordering.<locals>.<genexpr>)r¸   r4   r^   r_   r`   r   ra   rb   rc   r   r\   r   rM   ®  s   
ÿþÿz$BaseModelAdminChecks._check_orderingc              	   C   sÞ   t |ttjfƒr t |tjƒs| ¡ }t |jtjƒr|jj}ng S |dkr6t|j	ƒdkr6t
jdd|jdd�gS |dkr<g S t|v rBg S | d¡rM|dd… }|d	krSg S z
|jj |¡ W g S  tyn   t|||d
d� Y S w )z0Check that `ordering` refers to existing fields.ú?rŠ   z^The value of 'ordering' has the random ordering marker '?', but contains other fields as well.z2Either remove the "?", or remove the other fields.z
admin.E032)r/   rW   r*   ú-NÚpkz
admin.E033rd   )r4   r   r
   ÚOrderByÚascÚ
expressionÚFr}   rƒ   r¸   r   r2   rt   r   Ú
startswithrh   ri   rj   r	   rk   r·   r   r   r   r¹   À  s<   
ûÿ	
û
ÿÿz)BaseModelAdminChecks._check_ordering_itemc                    sR   ˆ j dkrg S tˆ j ttfƒstddˆ dd�S tt ‡ ‡fdd„tˆ j ƒD ƒ¡ƒS )z?Check that readonly_fields refers to proper attribute or field.r   rS   r“   z
admin.E034rU   c                 3   ry   )zreadonly_fields[%d]N)Ú_check_readonly_fields_itemrY   r\   r   r   r.   ò  r{   z>BaseModelAdminChecks._check_readonly_fields.<locals>.<genexpr>)r“   r4   r^   r_   r`   r   ra   rb   rc   r   r\   r   rN   ç  s   
ÿüÿz+BaseModelAdminChecks._check_readonly_fieldsc                 C   sz   t |ƒrg S t||ƒrg S t|j|ƒrg S z
|jj |¡ W g S  ty<   tjd||jj	|jjj
f |jdd�g Y S w )NzSThe value of '%s' is not a callable, an attribute of '%s', or an attribute of '%s'.z
admin.E035rg   )r®   Úhasattrrh   ri   rj   r	   r   r2   rt   rr   rv   r·   r   r   r   rÃ   ú  s,   
ñýþ÷ÿÿz0BaseModelAdminChecks._check_readonly_fields_itemN)rr   Ú
__module__Ú__qualname__r$   rB   rX   rC   rz   rD   rE   r…   r�   r‘   rF   rG   rH   rI   rŸ   rJ   r¥   r¦   rL   rK   r²   r³   rµ   rM   r¹   rN   rÃ   r   r   r   r   rA   °   s8    1",	'rA   c                       s´   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Z‡  ZS ))ÚModelAdminChecksc                    sœ   g t ƒ  |¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢|  	|¡¢|  
|¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢S r+   )Úsuperr$   Ú_check_save_asÚ_check_save_on_topÚ_check_inlinesÚ_check_list_displayÚ_check_list_display_linksÚ_check_list_filterÚ_check_list_select_relatedÚ_check_list_per_pageÚ_check_list_max_show_allÚ_check_list_editableÚ_check_search_fieldsÚ_check_date_hierarchyÚ _check_action_permission_methodsÚ_check_actions_uniquenessrO   ©rt   r   r   r$     s>   
ÿþýüûúùø	÷
öõôóòñzModelAdminChecks.checkc                 C   r˜   )zCheck save_as is a boolean.ú	a booleanÚsave_asz
admin.E101rU   )r4   rÙ   r°   r`   rc   r   r   r   rÉ   *  ó   zModelAdminChecks._check_save_asc                 C   r˜   )zCheck save_on_top is a boolean.rØ   Úsave_on_topz
admin.E102rU   )r4   rÛ   r°   r`   rc   r   r   r   rÊ   2  rÚ   z#ModelAdminChecks._check_save_on_topc                    rR   )z%Check all inline model admin classes.rS   Úinlinesz
admin.E103rU   c                 3   ry   )zinlines[%d]N)Ú_check_inlines_item©r-   rZ   Úitemr\   r   r   r.   C  rº   z2ModelAdminChecks._check_inlines.<locals>.<genexpr>)r4   rÜ   r^   r_   r`   r   ra   rb   rc   r   r\   r   rË   :  ó   ÿþÿzModelAdminChecks._check_inlinesc                 C   sÀ   z
|j d |j }W n ty   tjd| |jdd�g Y S w ddlm} t||ƒs7tjd| |jdd�gS |j	sFtjd| |jdd�gS t|j	t
jƒsWtd	d
| |dd�S ||j	|jƒ ¡ S )zCheck one inline model admin.Ú.z*'%s' must inherit from 'InlineModelAdmin'.z
admin.E104rg   r   )ÚInlineModelAdminz#'%s' must have a 'model' attribute.z
admin.E105za Modelz%s.modelz
admin.E106rU   )rÅ   rr   ÚAttributeErrorr   r2   rt   r­   râ   r   rh   r
   ÚModelr`   rn   r$   )rP   rW   Úinlinerv   Úinline_labelrâ   r   r   r   rÝ   I  s<   ýÿÿ	
ýÿýÿÿz$ModelAdminChecks._check_inlines_itemc                    rR   )zBCheck that list_display only contains fields or usable attributes.rS   Úlist_displayz
admin.E107rU   c                 3   ry   )zlist_display[%d]N)Ú_check_list_display_itemrÞ   r\   r   r   r.   x  rº   z7ModelAdminChecks._check_list_display.<locals>.<genexpr>)r4   rç   r^   r_   r`   r   ra   rb   rc   r   r\   r   rÌ   o  rà   z$ModelAdminChecks._check_list_displayc                 C   sº   t |ƒrg S t||ƒrg S z	|jj |¡}W n2 tyH   zt|j|ƒ}W n  tyE   tj	d|||j
j|jjjf |j
dd�g Y  Y S w Y nw t|tjƒr[tj	d| |j
dd�gS g S )NzsThe value of '%s' refers to '%s', which is not a callable, an attribute of '%s', or an attribute or method on '%s'.z
admin.E108rg   z0The value of '%s' must not be a ManyToManyField.z
admin.E109)r®   rÄ   rh   ri   rj   r	   Úgetattrrã   r   r2   rt   rr   rv   r4   r
   r”   )rP   rW   rß   rv   re   r   r   r   rè   ~  sB   
üý	õÿÿÿþýÿz)ModelAdminChecks._check_list_display_itemc                    sp   ddl m} ˆ jdu rg S tˆ jttfƒstddˆ dd�S ˆ jj|ju r6tt	 
‡ ‡fdd	„tˆ jƒD ƒ¡ƒS g S )
zACheck that list_display_links is a unique subset of list_display.r   )Ú
ModelAdminNza list, a tuple, or NoneÚlist_display_linksz
admin.E110rU   c                 3   ry   )zlist_display_links[%d]N)Ú_check_list_display_links_itemrY   r\   r   r   r.   ²  r{   z=ModelAdminChecks._check_list_display_links.<locals>.<genexpr>)r­   rê   rë   r4   r^   r_   r`   Úget_list_displayÚ__func__r   ra   rb   )rP   rW   rê   r   r\   r   rÍ   ¢  s"   
üüÿz*ModelAdminChecks._check_list_display_linksc                 C   s*   ||j vrtjd||f |jdd�gS g S )NzIThe value of '%s' refers to '%s', which is not defined in 'list_display'.z
admin.E111rg   )rç   r   r2   rt   r·   r   r   r   rì   »  s   
ÿüÿ	z/ModelAdminChecks._check_list_display_links_itemc                    rR   )NrS   Úlist_filterz
admin.E112rU   c                 3   ry   )zlist_filter[%d]N)Ú_check_list_filter_itemrÞ   r\   r   r   r.   Ï  rº   z6ModelAdminChecks._check_list_filter.<locals>.<genexpr>)r4   rï   r^   r_   r`   r   ra   rb   rc   r   r\   r   rÎ   È  s   ÿþÿz#ModelAdminChecks._check_list_filterc              	   C   sæ   ddl m}m} t|ƒr2t|tjƒs2t||ƒstd||dd�S t	||ƒr0t
jd| |jdd�gS g S t|ttfƒrN|\}}t||ƒsLtd	d
| |dd�S g S |}z	t|j|ƒ W g S  ttfyr   t
jd||f |jdd�g Y S w )aG  
        Check one item of `list_filter`, i.e. check if it is one of three options:
        1. 'field' -- a basic field filter, possibly w/ relationships (e.g.
           'field__rel')
        2. ('field', SomeFieldListFilter) - a field-based list filter class
        3. SomeListFilter - a non-field list filter class
        r   )ÚFieldListFilterÚ
ListFilterrò   z
admin.E113rš   z:The value of '%s' must not inherit from 'FieldListFilter'.z
admin.E114rg   rñ   rŒ   z
admin.E115zBThe value of '%s' refers to '%s', which does not refer to a Field.z
admin.E116)Údjango.contrib.adminrñ   rò   r®   r4   r
   ÚFieldr   rœ   r   r   r2   rt   r_   r^   r   rh   r   r	   )rP   rW   rß   rv   rñ   rò   re   Úlist_filter_classr   r   r   rð   Õ  sP   
ÿ
ÿüÿ	
üöÿüÿÿz(ModelAdminChecks._check_list_filter_itemc                 C   s&   t |jtttfƒstdd|dd�S g S )z?Check that list_select_related is a boolean, a list or a tuple.za boolean, tuple or listÚlist_select_relatedz
admin.E117rU   )r4   rö   r°   r^   r_   r`   rc   r   r   r   rÏ     s   üz+ModelAdminChecks._check_list_select_relatedc                 C   r˜   )z'Check that list_per_page is an integer.ú
an integerÚlist_per_pagez
admin.E118rU   )r4   rø   Úintr`   rc   r   r   r   rÐ     ó
   ÿz%ModelAdminChecks._check_list_per_pagec                 C   r˜   )z+Check that list_max_show_all is an integer.r÷   Úlist_max_show_allz
admin.E119rU   )r4   rû   rù   r`   rc   r   r   r   rÑ   '  rú   z)ModelAdminChecks._check_list_max_show_allc                    rR   )zjCheck that list_editable is a sequence of editable fields from
        list_display without first element.rS   Úlist_editablez
admin.E120rU   c                 3   ry   )zlist_editable[%d]N)Ú_check_list_editable_itemrÞ   r\   r   r   r.   ;  r{   z8ModelAdminChecks._check_list_editable.<locals>.<genexpr>)r4   rü   r^   r_   r`   r   ra   rb   rc   r   r\   r   rÒ   1  r|   z%ModelAdminChecks._check_list_editablec              	   C   sð   z	|j j |¡}W n ty   t|||dd� Y S w ||jvr.tjd||f |jdd�gS |j	rB||j	v rBtjd| |jdd�gS |jd |krb|j	sb|j	d urbtjd	||jd f |jd
d�gS |j
rh|jrvtjd||f |jdd�gS g S )Nz
admin.E121rd   zKThe value of '%s' refers to '%s', which is not contained in 'list_display'.z
admin.E122rg   zMThe value of '%s' cannot be in both 'list_editable' and 'list_display_links'.z
admin.E123r   z~The value of '%s' refers to the first field in 'list_display' ('%s'), which cannot be used unless 'list_display_links' is set.z
admin.E124zJThe value of '%s' refers to '%s', which is not editable through the admin.z
admin.E125)rh   ri   rj   r	   rk   rç   r   r2   rt   rë   ÚeditableÚprimary_keyr~   r   r   r   rý   C  s^   
ÿÿ
ÿüÿÿüÿÿ
þûÿ	ÿüÿ	z*ModelAdminChecks._check_list_editable_itemc                 C   s$   t |jttfƒstdd|dd�S g S )z"Check search_fields is a sequence.rS   ru   z
admin.E126rU   )r4   ru   r^   r_   r`   rc   r   r   r   rÓ   y  s
   ÿz%ModelAdminChecks._check_search_fieldsc              	   C   s|   |j du rg S zt|j|j ƒd }W n ttfy*   tjd|j  |jdd�g Y S w t|t	j
t	jfƒs<tdd|dd	�S g S )
z?Check that date_hierarchy refers to DateField or DateTimeField.NéÿÿÿÿzNThe value of 'date_hierarchy' refers to '%s', which does not refer to a Field.z
admin.E127rg   za DateField or DateTimeFieldÚdate_hierarchyz
admin.E128rU   )r  r   rh   r   r	   r   r2   rt   r4   r
   Ú	DateFieldr´   r`   )rP   rW   re   r   r   r   rÔ   ƒ  s,   
ÿüÿÿ
üz&ModelAdminChecks._check_date_hierarchyc           	   	   C   sr   |  ¡ }g }|D ].\}}}t|dƒsq|jD ]}d| }t||ƒs5| tjd|jj||jf |jdd�¡ qq|S )z 
        Actions with an allowed_permission attribute require the ModelAdmin to
        implement a has_<perm>_permission() method for each permission.
        Úallowed_permissionszhas_%s_permissionz/%s must define a %s() method for the %s action.z
admin.E129rg   )Ú_get_base_actionsrÄ   r  r1   r   r2   rt   rr   )	rP   rW   Úactionsr'   Úfuncr}   Ú_Ú
permissionÚmethod_namer   r   r   rÕ   Ÿ  s.   


ýÿøÿ€ýz1ModelAdminChecks._check_action_permission_methodsc                 C   s^   g }t  dd„ | ¡ D ƒ¡}| ¡ D ]\}}|dkr,| tjd|jj|f |jdd�¡ q|S )z.Check that every action has a unique __name__.c                 s   s   � | ]\}}}|V  qd S r+   r   )r-   r  r}   r   r   r   r.   ½  s   € z=ModelAdminChecks._check_actions_uniqueness.<locals>.<genexpr>rŠ   zS__name__ attributes of actions defined in %s must be unique. Name %r is not unique.z
admin.E130rg   )	ÚcollectionsÚCounterr  r©   r1   r   r2   rt   rr   )rP   rW   r'   Únamesr}   Úcountr   r   r   rÖ   º  s"   þþøÿ€z*ModelAdminChecks._check_actions_uniqueness)rr   rÅ   rÆ   r$   rÉ   rÊ   rË   rÝ   rÌ   rè   rÍ   rì   rÎ   rð   rÏ   rÐ   rÑ   rÒ   rý   rÓ   rÔ   rÕ   rÖ   Ú__classcell__r   r   r×   r   rÇ     s*    &$;

6
rÇ   c                       sP   e Zd Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	‡  Z
S )ÚInlineModelAdminChecksc                    sV   |j }g tƒ  |¡¢|  ||¡¢|  ||¡¢|  |¡¢|  |¡¢|  |¡¢|  |¡¢S r+   )	Úparent_modelrÈ   r$   Ú_check_relationÚ_check_exclude_of_parent_modelÚ_check_extraÚ_check_max_numÚ_check_min_numÚ_check_formset)rP   Ú
inline_objr&   r  r×   r   r   r$   Ð  s    
ÿ
þ
ýüûúùzInlineModelAdminChecks.checkc                    sv   t ƒ  |¡}|r
g S |  ||¡rg S |jd u rg S t||j|jd�}|j|jv r9tj	d|j|j
jf |jdd�gS g S )N©Úfk_namezVCannot exclude the field '%s', because it is the foreign key to the parent model '%s'.z
admin.E201rg   )rÈ   rF   r  r—   r   rh   r  r}   r   r2   ri   rv   rt   )rP   rW   r  r'   Úfkr×   r   r   r  Ü  s(   
þþøÿz5InlineModelAdminChecks._check_exclude_of_parent_modelc              
   C   sX   zt ||j|jd� W g S  ty+ } ztj|jd |jdd�gW  Y d }~S d }~ww )Nr  r   z
admin.E202rg   )r   rh   r  Ú
ValueErrorr   r2   Úargsrt   )rP   rW   r  Úer   r   r   r  û  s   ý&€ÿz&InlineModelAdminChecks._check_relationc                 C   r˜   )zCheck that extra is an integer.r÷   Úextraz
admin.E203rU   )r4   r  rù   r`   rc   r   r   r   r    rÚ   z#InlineModelAdminChecks._check_extrac                 C   ó.   |j du rg S t|j tƒstdd|dd�S g S )z!Check that max_num is an integer.Nr÷   Úmax_numz
admin.E204rU   )r   r4   rù   r`   rc   r   r   r   r    ó
   
z%InlineModelAdminChecks._check_max_numc                 C   r  )z!Check that min_num is an integer.Nr÷   Úmin_numz
admin.E205rU   )r"  r4   rù   r`   rc   r   r   r   r    r!  z%InlineModelAdminChecks._check_min_numc                 C   r˜   )z0Check formset is a subclass of BaseModelFormSet.r   Úformsetz
admin.E206rš   )r   r#  r   rœ   rc   r   r   r   r    rú   z%InlineModelAdminChecks._check_formset)rr   rÅ   rÆ   r$   r  r  r  r  r  r  r  r   r   r×   r   r  Ï  s    

r  c                 C   ó   t jd|| f |j|d�gS )NzThe value of '%s' must be %s.rg   ©r   r2   rt   )rs   rV   rW   r*   r   r   r   r`   *  ó   
ýÿr`   c                 C   r$  )Nz)The value of '%s' must inherit from '%s'.rg   r%  rš   r   r   r   rœ   4  r&  rœ   c                 C   s$   t jd|| |jjjf |j|d�gS )Nz?The value of '%s' refers to '%s', which is not a field of '%s'.rg   )r   r2   rh   ri   rv   rt   rd   r   r   r   rk   >  s   ÿüÿrk   ))r
  Ú	itertoolsr   Údjango.appsr   Údjango.confr   Údjango.contrib.admin.utilsr   r   r   Údjango.corer   Údjango.core.exceptionsr	   Ú	django.dbr
   Údjango.db.models.constantsr   Údjango.db.models.expressionsr   Údjango.forms.modelsr   r   r   Údjango.templater   Údjango.template.backends.djangor   Údjango.utils.module_loadingr   r   r   r)   r@   rA   rÇ   r  r`   rœ   rk   r   r   r   r   Ú<module>   s>    	y    j   <[

