ó
®â0_c           @  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 „ ƒ Z d d „ Z e e
 j ƒ d d „ ƒ Z d S(	   iÿÿÿÿ(   t   unicode_literalsN(   t   chain(   t   apps(   t   Errort   Tagst   registerc         K  s©   g  } |  d  k r! t j ƒ  } n t j d „  |  Dƒ ƒ } xh | D]` } t j | j ƒ s‹ | j t	 d | j
 | j f d | d d ƒƒ qA | j | j |   ƒ qA W| S(   Nc         s  s   |  ] } | j  ƒ  Vq d  S(   N(   t
   get_models(   t   .0t
   app_config(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pys	   <genexpr>   s    u<   The '%s.check()' class method is currently overridden by %r.t   objt   idu   models.E020(   t   NoneR   R   R   t   from_iterablet   inspectt   ismethodt   checkt   appendR   t   __name__t   extend(   t   app_configst   kwargst   errorst   modelst   model(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   check_all_models   s    c           sÿ   t  ˆ j ƒ | p t  ƒ  } | s& g  Sd d l m ‰ ‡ f d †  t ˆ ƒ j ƒ  Dƒ ‰ d „  ‰ ‡ f d †  ‰  ‡  f d †  } ‡  ‡ f d †  } ‡  f d †  ‰ i | d 6d d 6| d 6‰ ‡ ‡ f d †  ‰ t t d ‡ ‡ ‡ f d †  | Dƒ ƒ d d „  ƒS(   ut  
    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.
    iÿÿÿÿ(   t   signalsc           s1   i  |  ]' \ } } t  | ˆ  j ƒ r | | “ q S(    (   t
   isinstancet   ModelSignal(   R   t   namet   signal(   R   (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pys
   <dictcomp>5   s   	 	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(   uÊ  
        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.
        u   funcu   argsu   keywords(   t   hasattrR   t   getattrt   updatet   func(   R	   t	   operationt   argst   keywords(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   extract_operation9   s    
c           sE   y ˆ  j  |  d ƒ d |  } Wn t k
 r@ d |  d } n X| S(   Ni    u#   app '%s' doesn't provide model '%s'u   app '%s' isn't installed(   t   get_app_configt   LookupError(   t	   model_keyt   model_error(   R   (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   app_model_errorL   s    c           sR   d } i d j  |  ƒ d 6| d d 6ˆ  |  ƒ d 6} t | | d | d d d ƒS(	   Nu[   The field %(field)s was declared with a lazy reference to '%(model)s', but %(model_error)s.u   .u   modelu   fieldu   model_errorR	   R
   u   fields.E307(   t   joinR   (   R(   R!   R#   R$   t	   error_msgt   params(   R*   (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   field_errorZ   s    c   	        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(   Nu{   %(receiver)s was connected to the '%(signal)s' signal with a lazy reference to the sender '%(model)s', but %(model_error)s.i    u   The function '%s'u   Bound method '%s.%s'u   An instance of class '%s'u   unknownu   .u   modelu   receiveru   signalu   model_errorR	   R
   u   signals.E001(   R   t   typest   FunctionTypeR   t
   MethodTypet   __self__t	   __class__t   getR+   R   t
   __module__(	   R(   R!   R#   R$   R,   t   receivert   descriptiont   signal_nameR-   (   R*   t   model_signals(    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   signal_connect_errorf   s    
c           sJ   d } i | d 6d j  |  ƒ d 6ˆ  |  ƒ d 6} t | | d | d d ƒS(	   NuC   %(op)s contains a lazy reference to %(model)s, but %(model_error)s.u   opu   .u   modelu   model_errorR	   R
   u   models.E022(   R+   R   (   R(   R!   R#   R$   R,   R-   (   R*   (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   default_error}   s    u   django.db.models.fields.relatedu   resolve_related_classu   set_managedu   django.dispatch.dispatcheru   connectc           sA   | j  | j f } ˆ j | ˆ  ƒ } | r= | |  | | | ƒ Sd  S(   N(   R5   R   R4   R   (   R(   R!   R#   R$   t   keyt   error_fn(   R;   t
   known_lazy(    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   build_error   s    c         3  s8   |  ]. } ˆ  j  | D] } ˆ | ˆ | ƒ Œ Vq q d  S(   N(   t   _pending_operations(   R   R(   R!   (   R   R?   R%   (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pys	   <genexpr>•   s   R<   c         S  s   |  j  S(   N(   t   msg(   t   error(    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   <lambda>˜   t    (   u   django.db.models.fields.relatedu   resolve_related_classN(   u   django.db.models.fields.relatedu   set_managed(   u   django.dispatch.dispatcheru   connect(	   t   setR@   t   django.db.modelsR   t   varst   itemsR   t   sortedt   filter(   R   t   ignoret   pending_modelsR.   R:   (    (   R*   R   R?   R;   R%   R>   R9   R   sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   _check_lazy_references"   s&    "	
	c         K  s
   t  t ƒ S(   N(   RM   R   (   R   R   (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   check_lazy_references›   s    (   t
   __future__R    R   R/   t	   itertoolsR   t   django.appsR   t   django.core.checksR   R   R   R   R   R   RM   RN   (    (    (    sA   /tmp/pip-unpacked-wheel-BAJOf3/django/core/checks/model_checks.pyt   <module>   s   y