
 X                 @   s   d  d l  m Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l 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)    )unicode_literalsN)chain)apps)ErrorTagsregisterc             K   s   g  } |  d  k r! t  j   } n t j d d   |  D  } xh | D]` } t j | j  s | j t d | j	 | j f d | d d  qD | j
 | j |    qD W| S)Nc             s   s   |  ] } | j    Vq d  S)N)
get_models).0Z
app_config r
   M/home/ubuntu/projects/ifolica/build/django/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.objidzmodels.E020)r   r   r   from_iterableinspectZismethodcheckappendr   __name__extend)app_configskwargserrorsmodelsmodelr
   r
   r   check_all_models   s    r   c                s  t   j  | p t    } | s& g  Sd d l m   f d d   t   j   D  d d     f d d       f d	 d
   }    f d d   }   f d d    i | d 6d d 6| d 6   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                s1   i  |  ]' \ } } t  |   j  r | |  q Sr
   )
isinstanceZModelSignal)r	   namesignal)r   r
   r   
<dictcomp>5   s   	 	z*_check_lazy_references.<locals>.<dictcomp>c             S   s~   |  g  i  } } } xZ t  | d  rp | j t | d g   pA g   | j t | d i   p` i   | j } q W| | | 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updater    )r   Z	operationr!   r"   r
   r
   r   extract_operation9   s    
z1_check_lazy_references.<locals>.extract_operationc                sF   y   j  |  d  d |  } Wn  t k
 rA d |  d } Yn X| S)Nr   z#app '%s' doesn't provide model '%s'zapp '%s' isn't installed)Zget_app_configLookupError)	model_keymodel_error)r   r
   r   app_model_errorL   s    z/_check_lazy_references.<locals>.app_model_errorc                sR   d } i d j  |   d 6| d d 6  |   d 6} t | | d | d d d S)	Nz[The field %(field)s was declared with a lazy reference to '%(model)s', but %(model_error)s..r   fieldr)   r   r   zfields.E307)joinr   )r(   r    r!   r"   	error_msgparams)r*   r
   r   field_errorZ   s    z+_check_lazy_references.<locals>.field_errorc       	         s   d } | d } t  | t j  r2 d | j } nA t  | t j  rc d | j j j | j f } n d | j j }  j | j d  } i d j |   d 6| d	 6| d
 6  |   d 6} t	 | | d | 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   receiverr   r)   r   r   zsignals.E001)r   typesFunctionTyper   
MethodType__self__	__class__getr-   r   
__module__)	r(   r    r!   r"   r.   r2   descriptionZsignal_namer/   )r*   model_signalsr
   r   signal_connect_errorf   s    
z4_check_lazy_references.<locals>.signal_connect_errorc                sJ   d } i | d 6d j  |   d 6  |   d 6} t | | d | d d S)	NzC%(op)s contains a lazy reference to %(model)s, but %(model_error)s.opr+   r   r)   r   r   zmodels.E022)r-   r   )r(   r    r!   r"   r.   r/   )r*   r
   r   default_error}   s    z-_check_lazy_references.<locals>.default_errordjango.db.models.fields.relatedresolve_related_classNset_manageddjango.dispatch.dispatcherconnectc                sA   | j  | j f }  j |    } | r= | |  | | |  Sd  S)N)r9   r   r8   )r(   r    r!   r"   keyZerror_fn)r>   
known_lazyr
   r   build_error   s    z+_check_lazy_references.<locals>.build_errorc             3   s8   |  ]. }   j  | D] }  |  |   Vq q d  S)N)_pending_operations)r	   r(   r    )r   rF   r&   r
   r   r      s   z)_check_lazy_references.<locals>.<genexpr>rD   c             S   s   |  j  S)N)msg)errorr
   r
   r   <lambda>   s    z(_check_lazy_references.<locals>.<lambda>)r?   r@   )r?   rA   )rB   zconnect)setrG   Zdjango.db.modelsr   varsitemssortedfilter)r   ignoreZpending_modelsr0   r<   r
   )r*   r   rF   r>   r&   rE   r;   r   r   _check_lazy_references"   s&    %
	rQ   c             K   s
   t  t  S)N)rQ   r   )r   r   r
   r
   r   check_lazy_references   s    rR   )
__future__r   r   r3   	itertoolsr   Zdjango.appsr   Zdjango.core.checksr   r   r   r   r   rQ   rR   r
   r
   r
   r   <module>   s   y