
TQc           @   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 d f  d     YZ e d	  Z d
   Z d S(   iN(   t   settings(   t   color_style(   t	   force_str(   t   is_iterable(   t   sixt   ModelErrorCollectionc           B   s    e  Z e j d   Z d   Z RS(   c         C   s"   g  |  _  | |  _ t   |  _ d  S(   N(   t   errorst   outfileR   t   style(   t   selfR   (    (    s:   ../Django//lib/python/django/core/management/validation.pyt   __init__   s    		c         C   sF   |  j  j | | f  |  j j |  j j t d | | f    d  S(   Ns   %s: %s
(   R   t   appendR   t   writeR   t   ERRORR   (   R	   t   contextt   error(    (    s:   ../Django//lib/python/django/core/management/validation.pyt   add   s    (   t   __name__t
   __module__t   syst   stdoutR
   R   (    (    (    s:   ../Django//lib/python/django/core/management/validation.pyR      s   c   .      C   sV  d d l  m } m } d d l m } d d l m } d d l m } m	 } t
 |   } x- |   j   D] \ }	 }
 | j |	 |
  qh Wx| j | d t D]} | j } | j r2y | j j d  \ } } Wn+ t k
 r | j | d | j  q n X| j | |  s | j | d	 | j  q q n  t j d
 | j | j f k r| j | j k rv| j | d  n  | j | j  j s| j | d  qn  x		| j D]} | j d k r| j r| j  j d k r| j | d | j  n  | j j! d  r"| j | d | j  n  | j r[| j" r[| j# j$ r[| j | d | j  n  t% | | j&  ry9 t' | j(  } | d k r| j | d | j  n  Wqt t) f k
 r| j | d | j  qXn  t% | | j*  r#t+ t+ } } d } y? t' | j,  } | d k  r7| j | | | j  n t } Wn. t t) f k
 rn| j | | | j  n Xd } y? t' | j-  } | d k r| j | | | j  n t } Wn. t t) f k
 r| j | | | j  n Xd } | r#| r#| | k r | j | | | j  q q#n  t% | | j.  rY| j/ rY| j | d | j  n  t% | | j0  ry d d l1 m2 } Wqt3 k
 ry d d l2 } Wqt3 k
 r| j | d | j  qXqXn  t% | | j4  rt5 | d t+  r| j | d | j  n  t% | | j6  rN| j7 p0| j8 rN| j | d | j  n  | j9 rt% | j9 t: j;  s|t< | j9  r| j | d | j  qxV | j9 D]H } t% | t= t> f  st? |  d k r| j | d  | j  qqWn  | j@ d t t+ f k r!| j | d! | j  n  | jB jC | | |  | jD rtE | jD d"  r| jD jF | k r| j" r| j | d# | j  q| jD jF | k r| jG   r| j | d$ | j  qn  | jD r| jD jH | j   k rt% | jD jH t: j;  rZ| jD jH j j rZ| j | d% | j | jD jH j j | jD jH j j | jD jH j j f  q| j | d& | j | jD jH f  n  t% | jD jH t: j;  rqn  | jD jH j j | jD jI  j s| j | d' | jD jI | jD jH jJ f  n  | jD jH j } | | jD jH | |  jK   } | jL   } | jD jM   s
x | jN D] } | j | k r| j | d( | j | j | j | j f  n  | j | k r=| j | d) | j | j | j | j f  q=q=Wx | jO D] } | j | k r	| j | d* | j | j | j | j f  n  | j | k r| j | d+ | j | j | j | j f  qqWx | jP   D] } | jK   | k r	| j | d, | j | j | jK   | j f  n  | jK   | k r`	| j | d- | j | j | jK   | j f  q`	q`	Wx | jQ   D] } | jR | k	 r	| jK   | k rX
| j | d. | j | j | jK   | j f  n  | jK   | k r
| j | d/ | j | j | jK   | j f  q
q	q	Wq
qqWg  } xJtS | jO  D]9\ } } | jD jH | j   k rt% | jD jH t: j;  r\| jD jH j j r\| j | d% | j | jD jH j j | jD jH j j | jD jH j j f  n# | j | d0 | j | jD jH f  t% | jD jH t: j;  rq
qn  | j r| j | d1 | j  n  | jD jT d k	 rt% | jD jT t: j;  r| | jD jH }  }! |  |! k r?| jD jU r?| jD jT j jV r?| j | d2  n  t+ t+ d }" }# }$ x&| jD jT j jN D]}% t5 |% jD d3 d  }& |  |! k r|& |  k r|$ d4 7}$ n  |$ d k rx| j | d5 | jD jT j j |  j j f  qxqf|& |  k r.|" r%| j | d6 | jD jT j j |  j j f  qxt }" qf|& |! k rf|# ro| j | d6 | jD jT j j |& j j f  qxt }# qfqfW| jD jT | j d7 t  k r| j | d8 | j | jD jT f  n  | jD jH | | jD jT f }' |' | k r| j | d9 | j j | jD jT j j f  n | jW |'  | jD jT j jV sDt+ t+ }( }) xi | jD jT j jN D]U }* |* jD rU|( r|* jD jH | jD jH k rt }( q|* jD jH | k rt }) qqUqUW|( s|) r| j | d: | j | jD jT j j | jD jH j j | j j f  qqDn> t% | jD jT t: j;  rD| j | d; | j | jD jT f  n  | jD jH j } | | jD jH | |  jK   } | jL   } | d k	 r
x | jN D] } | j | k r| j | d< | j | j | j | j f  n  | j | k r| j | d= | j | j | j | j f  qqWx | jO D] } | j | k rg| j | d> | j | j | j | j f  n  | j | k r#| j | d? | j | j | j | j f  q#q#Wx | jP   D] } | jR | k	 r| jK   | k r| j | d@ | j | j | jK   | j f  n  | jK   | k rV| j | dA | j | j | jK   | j f  qVqqWx | jQ   D] } | jK   | k r| j | dB | j | j | jK   | j f  n  | jK   | k rg| j | dC | j | j | jK   | j f  qgqgWq
q
W| jX rx | jX D] }+ |+ dD k r+qn  |+ jY dE  rG|+ d4 }+ n  | jZ rb|+ dF k rbqn  dG |+ k rtqn  |+ dH k rqn  y | j |+ dI t+ Wq| j[ k
 r| j | dJ |+  qXqWn  x$ | j\ D] }, t] | | dK |,  qWt% | j^ t_ j`  s| j | dL  q x$ | j^ D] }- t] | | dM |-  q(Wq Wt? | ja  S(N   s   
    Validates all models that are part of the specified app. If no app name is provided,
    validates all models of all installed apps. Writes errors, if any, to outfile.
    Returns number of errors.
    i(   t   modelst
   connection(   t   get_app_errors(   t   RelatedObject(   t   SET_NULLt   SET_DEFAULTt   include_swappedt   .s+   %s is not of the form 'app_label.app_name'.sP   Model has been swapped out for '%s' which has not been installed or is abstract.s   %s.%ssj   The field named as the USERNAME_FIELD should not be included in REQUIRED_FIELDS on a swappable User model.sK   The USERNAME_FIELD must be unique. Add unique=True to the field parameters.t   ids   "%s": You can't use "id" as a field name, because each model automatically gets an "id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field or add primary_key=True to a field.t   _se   "%s": Field names cannot end with underscores, because this would lead to ambiguous queryset filters.s/   "%s": Primary key fields cannot have null=True.i    sM   "%s": CharFields require a "max_length" attribute that is a positive integer.sX   "%s": DecimalFields require a "decimal_places" attribute that is a non-negative integer.sP   "%s": DecimalFields require a "max_digits" attribute that is a positive integer.s   "%s": DecimalFields require a "max_digits" attribute value that is greater than or equal to the value of the "decimal_places" attribute.s2   "%s": FileFields require an "upload_to" attribute.(   t   ImageNs}   "%s": To use ImageFields, you need to install the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ .t   nullsN   "%s": BooleanFields do not accept null values. Use a NullBooleanField instead.sO   "%s": FilePathFields must have either allow_files or allow_folders set to True.s;   "%s": "choices" should be iterable (e.g., a tuple or list).i   s3   "%s": "choices" should be a sequence of two-tuples.s6   "%s": "db_index" should be either None, True or False.t	   on_deletes6   '%s' specifies on_delete=SET_NULL, but cannot be null.s?   '%s' specifies on_delete=SET_DEFAULT, but has no default value.sx   '%s' defines a relation with the model '%s.%s', which has been swapped out. Update the relation to point at settings.%s.sV   '%s' has a relation with model %s, which has either not been installed or is abstract.s?   Field '%s' under model '%s' must have a unique=True constraint.sk   Accessor for field '%s' clashes with field '%s.%s'. Add a related_name argument to the definition for '%s'.su   Reverse query name for field '%s' clashes with field '%s.%s'. Add a related_name argument to the definition for '%s'.so   Accessor for field '%s' clashes with m2m field '%s.%s'. Add a related_name argument to the definition for '%s'.sy   Reverse query name for field '%s' clashes with m2m field '%s.%s'. Add a related_name argument to the definition for '%s'.sw   Accessor for field '%s' clashes with related m2m field '%s.%s'. Add a related_name argument to the definition for '%s'.s   Reverse query name for field '%s' clashes with related m2m field '%s.%s'. Add a related_name argument to the definition for '%s'.ss   Accessor for field '%s' clashes with related field '%s.%s'. Add a related_name argument to the definition for '%s'.s}   Reverse query name for field '%s' clashes with related field '%s.%s'. Add a related_name argument to the definition for '%s'.s[   '%s' has an m2m relation with model %s, which has either not been installed or is abstract.sG   ManyToManyFields cannot be unique.  Remove the unique argument on '%s'.sC   Many-to-many fields with intermediate tables cannot be symmetrical.t   toi   sd   Intermediary model %s has more than two foreign keys to %s, which is ambiguous and is not permitted.sc   Intermediary model %s has more than one foreign key to %s, which is ambiguous and is not permitted.t   include_auto_createdsN   '%s' specifies an m2m relation through model %s, which has not been installed.s   The model %s has two manually-defined m2m relations through the model %s, which is not permitted. Please consider using an extra field on your intermediary model instead.sg   '%s' is a manually-defined m2m relation through model %s, which does not have foreign keys to %s and %ssM   '%s' specifies an m2m relation through model %s, which has not been installedso   Accessor for m2m field '%s' clashes with field '%s.%s'. Add a related_name argument to the definition for '%s'.sy   Reverse query name for m2m field '%s' clashes with field '%s.%s'. Add a related_name argument to the definition for '%s'.ss   Accessor for m2m field '%s' clashes with m2m field '%s.%s'. Add a related_name argument to the definition for '%s'.s}   Reverse query name for m2m field '%s' clashes with m2m field '%s.%s'. Add a related_name argument to the definition for '%s'.s{   Accessor for m2m field '%s' clashes with related m2m field '%s.%s'. Add a related_name argument to the definition for '%s'.s   Reverse query name for m2m field '%s' clashes with related m2m field '%s.%s'. Add a related_name argument to the definition for '%s'.sw   Accessor for m2m field '%s' clashes with related field '%s.%s'. Add a related_name argument to the definition for '%s'.s   Reverse query name for m2m field '%s' clashes with related field '%s.%s'. Add a related_name argument to the definition for '%s'.t   ?t   -t   _ordert   __t   pkt   many_to_manys6   "ordering" refers to "%s", a field that doesn't exist.t   unique_togethers    "index_together" must a sequencet   index_together(b   t	   django.dbR   R   t   django.db.models.loadingR   t   django.db.models.fields.relatedR   t   django.db.models.deletionR   R   R   t   itemsR   t
   get_modelst   Truet   _metat   swappedt   splitt
   ValueErrort	   swappablet	   get_modelR    t   AUTH_USER_MODELt	   app_labelt   object_namet   USERNAME_FIELDt   REQUIRED_FIELDSt	   get_fieldt   uniquet   local_fieldst   namet   primary_keyR(   t   endswithR    t   featurest!   interprets_empty_strings_as_nullst
   isinstancet	   CharFieldt   intt
   max_lengtht	   TypeErrort   DecimalFieldt   Falset   decimal_placest
   max_digitst	   FileFieldt	   upload_tot
   ImageFieldt   PILR   t   ImportErrort   BooleanFieldt   getattrt   FilePathFieldt   allow_filest   allow_folderst   choicesR   t   string_typesR   t   listt   tuplet   lent   db_indext   Nonet
   validationt   validate_fieldt   relt   hasattrR!   t   has_defaultR"   t
   field_nameR   t   get_accessor_namet   related_query_namet	   is_hiddent   fieldst   local_many_to_manyt$   get_all_related_many_to_many_objectst   get_all_related_objectst   fieldt	   enumeratet   throught   symmetricalt   auto_createdR   t   orderingt
   startswitht   order_with_respect_tot   FieldDoesNotExistR*   t   validate_local_fieldsR+   t   collectionst   SequenceR   (.   R   t   appR   R   R   R   R   R   t   et   app_nameR   t   clst   optsR:   t
   model_namet   fRI   t   decimalp_okt
   mdigits_okt   decimalp_msgRM   t   mdigits_msgRN   t   invalid_values_msgR   t   ct   rel_optst   rel_namet   rel_query_namet   rt   seen_intermediary_signaturest   it
   from_modelt   to_modelt	   seen_fromt   seen_tot	   seen_selft   inter_fieldt   rel_tot	   signaturet   seen_related_fkt   seen_this_fkRm   Re   t   utt   it(    (    s:   ../Django//lib/python/django/core/management/validation.pyt   get_validation_errors   s   		+

 "$%	%(!	+J&!,/3/3262C+J#		++				)/3/3292=	c         C   s  d d l  m } t | t j  s9 |  j | d |  n x | D] } y | j | d t } Wn. | j k
 r |  j | d | | f  q@ Xt | j	 | j
  r |  j | d | | j | f  n  | | j k r@ |  j | d | | j | f  q@ q@ Wd  S(   Ni(   R   s!   all %s elements must be sequencesR)   s.   "%s" refers to %s, a field that doesn't exist.s<   "%s" refers to %s. ManyToManyFields are not supported in %s.sE   "%s" refers to %s. This is not in the same model as the %s statement.(   R,   R   RF   Rw   Rx   R   R>   R2   Ru   Rb   t   ManyToManyRelRA   R@   (   Rz   R}   Re   Ri   R   Rm   R   (    (    s:   ../Django//lib/python/django/core/management/validation.pyRv   \  s    #(   Rw   R   t   django.confR    t   django.core.management.colorR   t   django.utils.encodingR   t   django.utils.itercompatR   t   django.utilsR   R   R_   R   Rv   (    (    (    s:   ../Django//lib/python/django/core/management/validation.pyt   <module>   s    G