a
    Lcòf~"  ã                   @   sŽ   d dl Z 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mZ eejƒddd„ƒZdd	d
„Zeejƒddd„ƒZdS )é    N)Údefaultdict)Úchain©Úapps)Úsettings)ÚErrorÚTagsÚWarningÚregisterc                 K   sd  t tƒ}t tƒ}t tƒ}g }| d u r.t ¡ }nt dd„ | D ƒ¡}|D ]²}|jjrp|jjsp||jj	  
|jj¡ t |j¡sž| 
td|j|jf |dd�¡ n| |jf i |¤Ž¡ |jjD ]}||j  
|jj¡ q¼|jjD ]}	||	j  
|jj¡ qÞqFtj�rtd }
}d}ntd }
}d }| ¡ D ]N\}}t|ƒd	k�r(d
 |¡}| 
|
d||f ||�rh|| nd |d�¡ �q(| ¡ D ]j\}}t|ƒd	k�r€t|ƒ}| 
td|t|ƒd	k�rºdndd
 t|ƒ¡f t|ƒd	k�rÞdndd�¡ �q€| ¡ D ]j\}}t|ƒd	k�rôt|ƒ}| 
td|t|ƒd	k�r.dndd
 t|ƒ¡f t|ƒd	k�rRdndd�¡ �qô|S )Nc                 s   s   | ]}|  ¡ V  qd S ©N)Ú
get_models)Ú.0Z
app_config© r   ú\/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/core/checks/model_checks.pyÚ	<genexpr>   s   z#check_all_models.<locals>.<genexpr>z<The '%s.check()' class method is currently overridden by %r.zmodels.E020©ÚobjÚidzmodels.W035ziYou have configured settings.DATABASE_ROUTERS. Verify that %s are correctly routed to separate databases.zmodels.E028é   z, z-db_table '%s' is used by multiple models: %s.)r   Úhintr   z$index name '%s' is not unique %s %s.z	for modelzamong models:zmodels.E029zmodels.E030)r   z)constraint name '%s' is not unique %s %s.zmodels.E031zmodels.E032)r   Úlistr   r   r   Úfrom_iterableÚ_metaZmanagedÚproxyÚdb_tableÚappendÚlabelÚinspectÚismethodÚcheckr   Ú__name__ÚextendÚindexesÚnameÚconstraintsr   ZDATABASE_ROUTERSr	   ÚitemsÚlenÚjoinÚsetÚsorted)Úapp_configsÚkwargsZdb_table_modelsr"   r$   ÚerrorsÚmodelsÚmodelZmodel_indexZmodel_constraintZerror_classZerror_idZ
error_hintr   Zmodel_labelsZmodel_labels_strZ
index_nameZconstraint_namer   r   r   Úcheck_all_models   s–    

ÿ
ÿüÿ	
ÿ

ÿûÿ	ýÿùÿýÿùÿr/   c                    s¾   t ˆjƒ|pt ƒ  }|sg S ddlm‰ ‡fdd„tˆƒ ¡ D ƒ‰dd„ ‰‡fdd„‰ ‡ fd	d
„}‡ ‡fdd„}‡ fdd„‰|d|dœ‰‡‡fdd„‰ttd‡‡‡fdd„|D ƒƒdd„ d�S )at  
    Ensure all lazy (i.e. string) model references have been resolved.

    Lazy references are used in various places throughout Django, primarily in
    related fields and model signals. Identify those common cases and provide
    more helpful error messages for them.

    The ignore parameter is used by StateApps to exclude swappable models from
    this check.
    r   ©Úsignalsc                    s"   i | ]\}}t |ˆ jƒr||“qS r   )Ú
isinstanceZModelSignal)r   r#   Úsignalr0   r   r   Ú
<dictcomp>p   s   þz*_check_lazy_references.<locals>.<dictcomp>c                 S   sP   | g i   }}}t |dƒrF| t|dg ƒ¡ | t|di ƒ¡ |j}q|||fS )aÊ  
        Take a callable found in Apps._pending_operations and identify the
        original callable passed to Apps.lazy_model_operation(). If that
        callable was a partial, return the inner, non-partial function and
        any arguments and keyword arguments that were supplied with it.

        obj is a callback defined locally in Apps.lazy_model_operation() and
        annotated there with a `func` attribute so as to imitate a partial.
        ÚfuncÚargsÚkeywords)Úhasattrr!   ÚgetattrÚupdater5   )r   Z	operationr6   r7   r   r   r   Úextract_operationv   s    

z1_check_lazy_references.<locals>.extract_operationc                    s>   zˆ   | d ¡ d|  }W n ty8   d| d  }Y n0 |S )Nr   z#app '%s' doesn't provide model '%s'zapp '%s' isn't installed)Zget_app_configÚLookupError)Ú	model_keyÚmodel_errorr   r   r   Úapp_model_error‡   s    z/_check_lazy_references.<locals>.app_model_errorc                    s4   d}d  | ¡|d ˆ | ƒdœ}t|| |d dd�S )Nz[The field %(field)s was declared with a lazy reference to '%(model)s', but %(model_error)s.Ú.Úfield)r.   rA   r>   zfields.E307r   ©r'   r   ©r=   r5   r6   r7   Ú	error_msgÚparams©r?   r   r   Úfield_error•   s    ÿýz+_check_lazy_references.<locals>.field_errorc           	         sŒ   d}|d }t |tjƒr$d|j }n.t |tjƒrFd|jjj|jf }nd|jj }ˆ |jd¡}d | ¡||ˆ | ƒdœ}t	|| |j
d	d
�S )Nz{%(receiver)s was connected to the '%(signal)s' signal with a lazy reference to the sender '%(model)s', but %(model_error)s.r   zThe function '%s'zBound method '%s.%s'zAn instance of class '%s'Úunknownr@   )r.   Úreceiverr3   r>   zsignals.E001r   )r2   ÚtypesÚFunctionTyper    Ú
MethodTypeÚ__self__Ú	__class__Úgetr'   r   Ú
__module__)	r=   r5   r6   r7   rD   rI   ÚdescriptionZsignal_namerE   )r?   Úmodel_signalsr   r   Úsignal_connect_error¡   s$    ÿþüz4_check_lazy_references.<locals>.signal_connect_errorc                    s,   d}|d  | ¡ˆ | ƒdœ}t|| |dd�S )NzC%(op)s contains a lazy reference to %(model)s, but %(model_error)s.r@   )Úopr.   r>   zmodels.E022r   rB   rC   rF   r   r   Údefault_error»   s    ÿýz-_check_lazy_references.<locals>.default_errorN))údjango.db.models.fields.relatedZresolve_related_class)rV   Zset_managed)zdjango.dispatch.dispatcherÚconnectc                    s.   |j |jf}ˆ |ˆ ¡}|r*|| |||ƒS d S r   )rP   r    rO   )r=   r5   r6   r7   ÚkeyZerror_fn)rU   Ú
known_lazyr   r   Úbuild_errorÏ   s    z+_check_lazy_references.<locals>.build_errorc                 3   s2   | ]*}ˆ j | D ]}ˆ|gˆ|ƒ¢R Ž V  qqd S r   )Ú_pending_operations)r   r=   r5   )r   rZ   r;   r   r   r   ×   s   þz)_check_lazy_references.<locals>.<genexpr>c                 S   s   | j S r   )Úmsg)Úerrorr   r   r   Ú<lambda>Ý   ó    z(_check_lazy_references.<locals>.<lambda>)rX   )r(   r[   Zdjango.db.modelsr1   Úvarsr%   r)   Úfilter)r   ÚignoreZpending_modelsrG   rS   r   )r?   r   rZ   rU   r;   rY   rR   r1   r   Ú_check_lazy_references]   s4    

þýþþ÷rc   c                 K   s   t tƒS r   )rc   r   )r*   r+   r   r   r   Úcheck_lazy_referencesá   s    rd   )N)N)N)r   rJ   Úcollectionsr   Ú	itertoolsr   Zdjango.appsr   Zdjango.confr   Zdjango.core.checksr   r   r	   r
   r-   r/   rc   rd   r   r   r   r   Ú<module>   s   Q
 