o
    þÞh*Å  ã                   @   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 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)ÚNotRegistered)Ú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   ú[/var/www/html/premium_crap/venv/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>{   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_coder6   Údjango_templates_instanceÚsidebar_enabledr   r   r   Úcheck_dependencies8   sº   

ÿýÿ€
þüÿ
ÿþþüÿ	ÿüÿÿÿüÿ	ÿýÿÿýÿÿ÷ÿrA   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©rX   rQ   r   r   Ú
<listcomp>Ñ   s    ý
ÿÿzCBaseModelAdminChecks._check_autocomplete_fields.<locals>.<listcomp>)r5   rU   ÚlistÚtupleÚmust_ber   Úfrom_iterableÚ	enumerate©rQ   rX   r   r]   r   rC   Ã   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 z
|j
 |jj ¡}W n tyS   tjd|jj jt|ƒjf |jdd�g Y S w |jsjt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©ÚfieldrW   rX   r+   ú%a foreign key or a many-to-many fieldz
admin.E038rV   zXAn admin for model "%s" has to be registered to be referenced by %s.autocomplete_fields.z
admin.E039©rX   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_manyr5   r   Ú
ForeignKeyra   Ú
admin_siteÚget_model_adminÚremote_fieldr   r	   r3   Ú__name__ÚtypeÚ	__class__Úsearch_fields)rQ   rX   r\   Úlabelrf   Úrelated_adminr   r   r   rY   Ú   sP   
ÿÿüþþøÿÿþþøÿz4BaseModelAdminChecks._check_autocomplete_fields_itemc                    rS   )zZCheck that `raw_id_fields` only contains field names that are listed
        on the model.rT   Úraw_id_fieldsz
admin.E001rV   c                 3   ó&   � | ]\}}ˆ  ˆ |d | ¡V  qdS )zraw_id_fields[%d]N)Ú_check_raw_id_fields_itemrZ   r]   r   r   r/     ó   € ý
ÿ
ÿz<BaseModelAdminChecks._check_raw_id_fields.<locals>.<genexpr>)r5   rx   r_   r`   ra   r   rb   rc   rd   r   r]   r   rD     ó   ÿüÿ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.E002re   rg   z
admin.E003rV   )ri   rj   rk   r
   rl   Únamerm   r5   r   rn   ra   ©rQ   rX   r\   rv   rf   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.
        NrT   Úfieldsz
admin.E004rV   z,Both 'fieldsets' and 'fields' are specified.z
admin.E005rh   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/   Y  s
   € ÿ
ÿz5BaseModelAdminChecks._check_fields.<locals>.<genexpr>)r   r5   r_   r`   ra   Ú	fieldsetsr	   r3   rt   r   ÚlenÚsetr   rb   )rQ   rX   r   r   r]   r   rE   =  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.NrT   r‚   z
admin.E007rV   c                 3   s(   � | ]\}}ˆ  ˆ |d | ˆ¡V  qdS )zfieldsets[%d]N)Ú_check_fieldsets_item)r.   r[   Úfieldset©rX   Úseen_fieldsrQ   r   r   r/   l  s   € ýÿ
ÿz8BaseModelAdminChecks._check_fieldsets.<locals>.<genexpr>)r‚   r5   r_   r`   ra   r   rb   rc   rd   r   r‡   r   rF   _  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.rT   z
admin.E008rV   é   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.E011rh   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   rX   rQ   r   r   r/   š  s
   € ÿ
ÿz=BaseModelAdminChecks._check_fieldsets_item.<locals>.<genexpr>)r5   r_   r`   ra   rƒ   Údictr	   r3   rt   r$   r   r„   r   rb   )rQ   rX   r†   rv   rˆ   r   rŽ   r   r…   t  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_itemrZ   rŽ   r   r   r/   §  ó   € ýÿ
ÿz9BaseModelAdminChecks._check_field_spec.<locals>.<genexpr>)r5   r`   r_   r   rb   rc   r‘   )rQ   rX   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.ú
admin.E013rh   )Úreadonly_fieldsri   rj   rk   r
   r5   r   ÚManyToManyFieldrq   ÚthroughÚauto_createdr	   r3   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.NrT   Úexcludez
admin.E014rV   z3The value of 'exclude' contains duplicate field(s).z
admin.E015rh   )
r˜   r5   r_   r`   ra   rƒ   r„   r	   r3   rt   rd   r   r   r   rG   Ï  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©ÚparentrW   rX   r+   )r   rš   r   Úmust_inherit_fromrd   r   r   r   rH   ã  s
   ÿz BaseModelAdminChecks._check_formc                    rS   )z8Check that filter_vertical is a sequence of field names.rT   Úfilter_verticalz
admin.E017rV   c                 3   ry   )zfilter_vertical[%d]N©Ú_check_filter_itemrZ   r]   r   r   r/   ô  r{   z>BaseModelAdminChecks._check_filter_vertical.<locals>.<genexpr>)r5   rž   r_   r`   ra   r   rb   rc   rd   r   r]   r   rI   ì  ó   ÿüÿz+BaseModelAdminChecks._check_filter_verticalc                    rS   )z:Check that filter_horizontal is a sequence of field names.rT   Úfilter_horizontalz
admin.E018rV   c                 3   ry   )zfilter_horizontal[%d]NrŸ   rZ   r]   r   r   r/     r{   z@BaseModelAdminChecks._check_filter_horizontal.<locals>.<genexpr>)r5   r¢   r_   r`   ra   r   rb   rc   rd   r   r]   r   rJ   ü  r¡   z-BaseModelAdminChecks._check_filter_horizontalc              	   C   sŠ   z	|j j |¡}W n ty   t|||dd� Y S w |jr$t|tjƒr,t	d||dd�S |j
jjjsCtjd|› d|› d�|jd	d
�g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.E019re   za many-to-many fieldz
admin.E020rV   úThe value of 'z&' cannot include the ManyToManyField 'z>', because that field manually specifies a relationship model.r“   rh   )ri   rj   rk   r
   rl   rm   r5   r   ÚManyToManyRelra   rq   r–   r—   r	   r3   rt   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.E021rV   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/   0  s   € ü
ÿÿ
ÿz;BaseModelAdminChecks._check_radio_fields.<locals>.<genexpr>)r5   r¦   r�   ra   r_   r   rb   Úitemsrd   r   r]   r   rK   (  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.E022re   zsThe value of '%s' refers to '%s', which is not an instance of ForeignKey, and does not have a 'choices' definition.z
admin.E023rh   )ri   rj   rk   r
   rl   r5   r   rn   Úchoicesr	   r3   rt   r~   r   r   r   r¨   9  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.E024rh   )Údjango.contrib.admin.optionsr®   r¯   r	   r3   rt   )rQ   rX   r«   rv   r®   r¯   r   r   r   r©   Q  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.E025rh   )ÚcallableÚview_on_siter5   Úboolr	   r3   rt   rd   r   r   r   rM   b  s   üÿ	z,BaseModelAdminChecks._check_view_on_site_urlc                    r¥   )zXCheck that `prepopulated_fields` is a dictionary containing allowed
        field types.r‹   Úprepopulated_fieldsz
admin.E026rV   c                 3   r§   )r´   zprepopulated_fields["%s"]N)Ú_check_prepopulated_fields_keyÚ _check_prepopulated_fields_valuerª   r]   r   r   r/   x  s   € úÿ
ÿý
ÿzBBaseModelAdminChecks._check_prepopulated_fields.<locals>.<genexpr>)r5   r´   r�   ra   r_   r   rb   r¬   rd   r   r]   r   rL   o  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.E027re   zyThe value of '%s' refers to '%s', which must not be a DateTimeField, a ForeignKey, a OneToOneField, or a ManyToManyField.z
admin.E028rh   )ri   rj   rk   r
   rl   r5   r   ÚDateTimeFieldrn   r•   r	   r3   rt   r~   r   r   r   rµ   ƒ  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.rT   z
admin.E029rV   c                 3   r�   )z%s[%r]N)Ú%_check_prepopulated_fields_value_item)r.   r[   Úsubfield_namerŽ   r   r   r/   ¦  r’   zHBaseModelAdminChecks._check_prepopulated_fields_value.<locals>.<genexpr>)r5   r_   r`   ra   r   rb   rc   )rQ   rX   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.E030re   )ri   rj   rk   r
   rl   ©rQ   rX   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.NrT   Úorderingz
admin.E031rV   c                 3   ry   )zordering[%d]N)Ú_check_ordering_itemrZ   r]   r   r   r/   Ç  ó
   € ÿ
ÿz7BaseModelAdminChecks._check_ordering.<locals>.<genexpr>)r»   r5   r_   r`   ra   r   rb   rc   rd   r   r]   r   rN   »  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¡}|dkrMg S z
|jj |¡ W g S  tyh   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)r0   rX   r+   ú-Úpkz
admin.E033re   )r5   r   r   ÚOrderByÚascÚ
expressionÚFr}   rƒ   r»   r	   r3   rt   r   Úremoveprefixri   rj   rk   r
   rl   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   rT   r”   z
admin.E034rV   c                 3   ry   )zreadonly_fields[%d]N)Ú_check_readonly_fields_itemrZ   r]   r   r   r/   þ  r{   z>BaseModelAdminChecks._check_readonly_fields.<locals>.<genexpr>)r”   r5   r_   r`   ra   r   rb   rc   rd   r   r]   r   rO   ó  s   
ÿüÿz+BaseModelAdminChecks._check_readonly_fieldsc              	   C   s|   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 )NziThe value of '%s' refers to '%s', which is not a callable, an attribute of '%s', or an attribute of '%s'.z
admin.E035rh   )r±   Úhasattrri   rj   rk   r
   r	   r3   rt   rr   rv   rº   r   r   r   rÆ     s.   
ðüþöÿÿz0BaseModelAdminChecks._check_readonly_fields_itemN)rr   Ú
__module__Ú__qualname__r%   rC   rY   rD   rz   rE   rF   r…   r�   r‘   rG   rH   rI   rJ   r    rK   r¨   r©   rM   rL   rµ   r¶   r¸   rN   r¼   rO   rÆ   r   r   r   r   rB   ±   s8    3",	&rB   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‡  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_actionsrP   ©rt   r   r   r%   $  s:   
ÿþýüûúùø	÷
öõôóòzModelAdminChecks.checkc                 C   r™   )zCheck save_as is a boolean.ú	a booleanÚsave_asz
admin.E101rV   )r5   rÛ   r³   ra   rd   r   r   r   rÌ   6  ó   zModelAdminChecks._check_save_asc                 C   r™   )zCheck save_on_top is a boolean.rÚ   Úsave_on_topz
admin.E102rV   )r5   rÝ   r³   ra   rd   r   r   r   rÍ   >  rÜ   z#ModelAdminChecks._check_save_on_topc                    rS   )z%Check all inline model admin classes.rT   Úinlinesz
admin.E103rV   c                 3   ry   )zinlines[%d]N)Ú_check_inlines_item©r.   r[   Úitemr]   r   r   r/   O  r½   z2ModelAdminChecks._check_inlines.<locals>.<genexpr>)r5   rÞ   r_   r`   ra   r   rb   rc   rd   r   r]   r   rÎ   F  ó   ÿþÿ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.E104rh   r   )ÚInlineModelAdminz#'%s' must have a 'model' attribute.z
admin.E105za Modelz%s.modelz
admin.E106rV   )rÈ   rr   ÚAttributeErrorr	   r3   rt   r°   rä   r   ri   r   ÚModelra   ro   r%   )rQ   rX   Úinlinerv   Úinline_labelrä   r   r   r   rß   U  s<   ýÿÿ	
ýÿýÿÿz$ModelAdminChecks._check_inlines_itemc                    rS   )zBCheck that list_display only contains fields or usable attributes.rT   Úlist_displayz
admin.E107rV   c                 3   ry   )zlist_display[%d]N)Ú_check_list_display_itemrà   r]   r   r   r/   „  r½   z7ModelAdminChecks._check_list_display.<locals>.<genexpr>)r5   ré   r_   r`   ra   r   rb   rc   rd   r   r]   r   rÏ   {  râ   z$ModelAdminChecks._check_list_displayc                 C   s  t |ƒrg S t||ƒrg S z	|jj |¡}W nQ tyg   zt|j|ƒ}W n? tyd   z
t|j|ƒd }W n+ tt	fya   t
jd|› d|› d|jj› d|jjj› d�	|jdd�g Y  Y  Y S w Y nw Y nw t|d	d
ƒrt|js|jst|dd ƒr�|jjjr�t
jd|› d�|jdd�gS g S )Néÿÿÿÿr£   z' refers to 'z,', which is not a callable or attribute of 'z)', or an attribute, method, or field on 'z'.z
admin.E108rh   Úis_relationFÚrelz<' must not be a many-to-many field or a reverse foreign key.z
admin.E109)r±   rÇ   ri   rj   rk   r
   Úgetattrrå   r   r   r	   r3   rt   rr   rv   rm   Úone_to_manyrí   rf   Úmany_to_one)rQ   rX   rá   rv   rf   r   r   r   rê   Š  sZ   
ÿýúÿÿÿþ€ý
ÿþþ
ýý
üÿ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.E110rV   c                 3   ry   )zlist_display_links[%d]N)Ú_check_list_display_links_itemrZ   r]   r   r   r/   À  r{   z=ModelAdminChecks._check_list_display_links.<locals>.<genexpr>)r°   rñ   rò   r5   r_   r`   ra   Úget_list_displayÚ__func__r   rb   rc   )rQ   rX   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.E111rh   )ré   r	   r3   rt   rº   r   r   r   ró   É  s   
ÿüÿ	z/ModelAdminChecks._check_list_display_links_itemc                    rS   )NrT   Úlist_filterz
admin.E112rV   c                 3   ry   )zlist_filter[%d]N)Ú_check_list_filter_itemrà   r]   r   r   r/   Ý  r½   z6ModelAdminChecks._check_list_filter.<locals>.<genexpr>)r5   rö   r_   r`   ra   r   rb   rc   rd   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.E114rh   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±   r5   r   ÚFieldr   r�   r   r	   r3   rt   r`   r_   r   ri   r   r
   )rQ   rX   rá   rv   rø   rù   rf   Ú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.E117rV   )r5   rý   r³   r_   r`   ra   rd   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.E118rV   )r5   rÿ   Úintra   rd   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.E119rV   )r5   r  r   ra   rd   r   r   r   rÔ   5  r  z)ModelAdminChecks._check_list_max_show_allc                    rS   )zjCheck that list_editable is a sequence of editable fields from
        list_display without first element.rT   Úlist_editablez
admin.E120rV   c                 3   ry   )zlist_editable[%d]N)Ú_check_list_editable_itemrà   r]   r   r   r/   I  r{   z8ModelAdminChecks._check_list_editable.<locals>.<genexpr>)r5   r  r_   r`   ra   r   rb   rc   rd   r   r]   r   rÕ   ?  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.E121re   zKThe value of '%s' refers to '%s', which is not contained in 'list_display'.z
admin.E122rh   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)ri   rj   rk   r
   rl   ré   r	   r3   rt   rò   ÚeditableÚprimary_keyr~   r   r   r   r  Q  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.rT   ru   z
admin.E126rV   )r5   ru   r_   r`   ra   rd   r   r   r   rÖ   ‡  s
   ÿz%ModelAdminChecks._check_search_fieldsc              	   C   sv   |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 | ¡ dvr9t	dd|d	d
�S g S )z?Check that date_hierarchy refers to DateField or DateTimeField.Nrë   zNThe value of 'date_hierarchy' refers to '%s', which does not refer to a Field.z
admin.E127rh   >   Ú	DateFieldr·   za DateField or DateTimeFieldÚdate_hierarchyz
admin.E128rV   )
r  r   ri   r   r
   r	   r3   rt   Úget_internal_typera   )rQ   rX   rf   r   r   r   r×   ‘  s,   
ÿüÿÿ
üz&ModelAdminChecks._check_date_hierarchyc              	   C   sÄ   g }|  ¡ }|D ].\}}}t|dƒsq|jD ]}d| }t||ƒs5| tjd|jj||jf |jdd�¡ qqt 	dd„ |D ƒ¡}	|	 
¡ D ]\}}
|
dkr_| tjd	|jj|f |jd
d�¡ qE|S )NÚallowed_permissionszhas_%s_permissionz/%s must define a %s() method for the %s action.z
admin.E129rh   c                 s   s   � | ]\}}}|V  qd S r,   r   )r.   Ú_r}   r   r   r   r/   Æ  s   € z2ModelAdminChecks._check_actions.<locals>.<genexpr>rŠ   zS__name__ attributes of actions defined in %s must be unique. Name %r is not unique.z
admin.E130)Ú_get_base_actionsrÇ   r
  r2   r	   r3   rt   rr   ÚcollectionsÚCounterr¬   )rQ   rX   r(   ÚactionsÚfuncr}   r  Ú
permissionÚmethod_nameÚnamesÚcountr   r   r   rØ   ­  sL   


ýÿøÿ€ýþþøÿ€zModelAdminChecks._check_actions)rr   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)rQ   Ú
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.E201rh   )rË   rG   r  r˜   r   ri   r   r}   r	   r3   rj   rv   rt   )rQ   rX   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.E202rh   )r   ri   r   Ú
ValueErrorr	   r3   Úargsrt   )rQ   rX   r  Úer   r   r   r    s   ý&€ÿz&InlineModelAdminChecks._check_relationc                 C   r™   )zCheck that extra is an integer.rþ   Úextraz
admin.E203rV   )r5   r%  r   ra   rd   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.E204rV   )r'  r5   r   ra   rd   r   r   r   r    ó
   
z%InlineModelAdminChecks._check_max_numc                 C   r&  )z!Check that min_num is an integer.Nrþ   Úmin_numz
admin.E205rV   )r)  r5   r   ra   rd   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�   rd   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.rh   ©r	   r3   rt   )rs   rW   rX   r+   r   r   r   ra   3  ó   
ýÿra   c                 C   r+  )Nz)The value of '%s' must inherit from '%s'.rh   r,  r›   r   r   r   r�   =  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'.rh   )r	   r3   ri   rj   rv   rt   re   r   r   r   rl   G  s   ÿüÿrl   )+r  Ú	itertoolsr   Údjango.appsr   Údjango.confr   Údjango.contrib.admin.exceptionsr   Ú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*   rA   rB   rÊ   r  ra   r�   rl   r   r   r   r   Ú<module>   s@    	y    v   8[

