
    Vh~"                         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       Zd
dZ eej                        d
d	       Zy)    N)defaultdict)chain)apps)settings)ErrorTagsWarningregisterc                    t        t              }t        t              }t        t              }g }| t        j                         }nt	        j
                  d | D              }|D ]~  }|j                  j                  rR|j                  j                  s<||j                  j                     j                  |j                  j                         t        j                  |j                        s9|j                  t        d|j                   d|j                  d|d             n!|j#                   |j                  di |       |j                  j$                  D ]4  }||j&                     j                  |j                  j                         6 |j                  j(                  D ]4  }	||	j&                     j                  |j                  j                         6  t*        j,                  rt.        d}}
d}n
t        d	}}
d }|j1                         D ]N  \  }}t3        |      d
k7  sdj5                  |      }|j                   |
d|d|d||r||z  nd |             P |j1                         D ]}  \  }}t3        |      d
kD  st7        |      }|j                  t        d|dt3        |      d
k(  rdndddj5                  t9        |            dt3        |      d
k(  rdnd              |j1                         D ]}  \  }}t3        |      d
kD  st7        |      }|j                  t        d|dt3        |      d
k(  rdndddj5                  t9        |            dt3        |      d
k(  rdnd              |S )Nc              3   <   K   | ]  }|j                           y wN)
get_models).0
app_configs     O/home/dcms/DCMS/lib/python3.12/site-packages/django/core/checks/model_checks.py	<genexpr>z#check_all_models.<locals>.<genexpr>   s      %
(2J!!#%
s   zThe 'z2.check()' class method is currently overridden by .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 'z' is used by multiple models: )r   hintr   zindex name 'z' is not unique z	for modelzamong models: zmodels.E029zmodels.E030)r   zconstraint name 'zmodels.E031zmodels.E032 )r   listr   r   r   from_iterable_metamanagedproxydb_tableappendlabelinspectismethodcheckr   __name__extendindexesnameconstraintsr   DATABASE_ROUTERSr	   itemslenjoinsetsorted)app_configskwargsdb_table_modelsr(   r*   errorsmodelsmodelmodel_indexmodel_constrainterror_classerror_id
error_hintr    model_labelsmodel_labels_str
index_nameconstraint_names                     r   check_all_modelsr@      s4   !$'O$Gd#KF"$$ %
6A%
 
  I;;u{{'8'8EKK001889J9JK,MM~~u{{4$	 MM+%++//0 ;;.. 	@KK$$%,,U[[->->?	@ % 7 7 	I(--.55ekk6G6GH	I!I$    'X: 	
 !&}X
"1"7"7"9 ,|!#yy6MM!13 <F*'77D %,MMO  
L|q |,LMM #'*<'8A'=?R		&"67	 ),L(9Q(>}M
 *5):):)< %|q |,LMM ('*<'8A'=?R		&"67	 ),L(9Q(>}M
 M    c                    	
 t         j                        |xs
 t               z
  }|sg S ddlm} t	        |      j                         D ci c]  \  }}t        ||j                        r||  c}}d  fdfd}fd}fd
|d|d	
fd
	t        t        d 	fd|D              d       S c c}}w )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                     | g i }}}t        |d      rQ|j                  t        |dg              |j                  t        |di              |j                  }t        |d      r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updaterE   )r   	operationrF   rG   s       r   extract_operationz1_check_lazy_references.<locals>.extract_operationv   si     %(R4	i(KK	6267OOGIz2>?!I i( $((rA   c                 n    	  j                   | d          d| z  }|S # t        $ r d| d   z  }Y |S w xY w)Nr   z#app '%s' doesn't provide model '%s'zapp '%s' isn't installed)get_app_configLookupError)	model_keymodel_errorr   s     r   app_model_errorz/_check_lazy_references.<locals>.app_model_error   sV    	DD	!-?)KK   	D4y|CK	Ds    44c                 l    d}dj                  |       |d    |       d}t        ||z  |d   d      S )Nz[The field %(field)s was declared with a lazy reference to '%(model)s', but %(model_error)s.r   field)r6   rT   rQ   zfields.E307r   r.   r   rP   rE   rF   rG   	error_msgparamsrR   s         r   field_errorz+_check_lazy_references.<locals>.field_error   sM    3 	
 XXi(g&*95

 Y'Xg->=QQrA   c                    d}|d   }t        |t        j                        rd|j                  z  }net        |t        j                        r2d|j
                  j                  j                  d|j                  d}nd|j                  j                  z  }
j                  |j
                  d      }dj                  |       || 	|       d	}t        ||z  |j                  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 'r   'zAn instance of class '%s'unknown)r6   receiversignalrQ   zsignals.E001r   )
isinstancetypesFunctionTyper&   
MethodType__self__	__class__getr.   r   
__module__)rP   rE   rF   rG   rW   r]   descriptionsignal_namerX   rR   model_signalss            r   signal_connect_errorz4_check_lazy_references.<locals>.signal_connect_error   s    M 	 7 h 2 23-0A0AAK%"2"23!!++44!!K
 68J8J8S8SSK#''yAXXi(#!*95	
 Y'X-@-@^TTrA   c                 `    d}|dj                  |        |       d}t        ||z  |d      S )NzC%(op)s contains a lazy reference to %(model)s, but %(model_error)s.r   )opr6   rQ   zmodels.E022r   rU   rV   s         r   default_errorz-_check_lazy_references.<locals>.default_error   sA    Q 	 XXi(*95

 Y'TmDDrA   N))django.db.models.fields.relatedresolve_related_class)rn   set_managed)zdjango.dispatch.dispatcherconnectc                 v    |j                   |j                  f}j                  |      }|r || |||      S d S r   )rf   r&   re   )rP   rE   rF   rG   keyerror_fnrm   
known_lazys         r   build_errorz+_check_lazy_references.<locals>.build_error   s=    .>>#}5<Dx	4x8N$NrA   c              3   d   K   | ]'  }j                   |   D ]  } |g |         ) y wr   )_pending_operations)r   rP   rE   r   rv   rL   s      r   r   z)_check_lazy_references.<locals>.<genexpr>   sI       44Y?  I@(9$(?@@s   -0c                     | j                   S r   )msg)errors    r   <lambda>z(_check_lazy_references.<locals>.<lambda>   s
    %)) rA   )rs   )
r/   rx   django.db.modelsrC   varsr,   r_   ModelSignalr0   filter)r   ignorepending_modelsrC   r)   r^   rY   rj   rR   rv   rm   rL   ru   ri   s   `       @@@@@@r   _check_lazy_referencesr   ]   s     112foFN 	( !M//1D&fg112 	M)"
RU4	E GR<@3GJO
 !/	
 $
 
Is   #C c                      t        t              S r   )r   r   )r1   r2   s     r   check_lazy_referencesr      s    !$''rA   r   )r#   r`   collectionsr   	itertoolsr   django.appsr   django.confr   django.core.checksr   r   r	   r
   r5   r@   r   r   r   rA   r   <module>r      sa      #     = = 
$++N NbAH 
$++( (rA   