
TRNc           @   sO   d  d l  Z  d  d l m Z d  d l m Z d d d     YZ d d  Z d S(   iN(   t   color_style(   t   is_iterablet   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   (    (    sN   /home/panlixing/Python_Projects/gaeseries/django/core/management/validation.pyt   __init__   s    		c         C   s@   |  j  j | | f  |  j j |  j j d | | f   d  S(   Ns   %s: %s
(   R   t   appendR   t   writeR   t   ERROR(   R   t   contextt   error(    (    sN   /home/panlixing/Python_Projects/gaeseries/django/core/management/validation.pyt   add   s    (   t   __name__t
   __module__t   syst   stdoutR   R   (    (    (    sN   /home/panlixing/Python_Projects/gaeseries/django/core/management/validation.pyR      s   c   '      C   sI  d d l  m } d d l m } m } d d l m } d d l m } t	 |   } x- |   j
   D] \ } }	 | j | |	  qb Wx| j |  D]}
 |
 j } x;| j D]0} | j d k r | j r | j j d k r | j | d | j  n  | j j d  r"| j | d	 | j  n  t | | j  ry9 t | j  } | d
 k rl| j | d | j  n  Wqt t f k
 r| j | d | j  qXn  t | | j  rd } y9 t | j  } | d
 k  r| j | | | j  n  Wn. t t f k
 r"| j | | | j  n Xd } y9 t | j  } | d
 k ra| j | | | j  n  Wqt t f k
 r| j | | | j  qXn  t | | j  r| j r| j | d | j  n  t | | j  rDy d d l m  } WqDt! k
 r@y d d l  } WqAt! k
 r<| j | d | j  qAXqDXn  t | | j"  rt# | d t$  r| j | d | j  n  | j% r t | j% t&  st' | j%  r| j | d | j  q xV | j% D]H } t | t( t) f  st* |  d k r| j | d | j  qqWn  | j+ d t- t$ f k rR| j | d | j  n  | j. j/ | | |  | j0 r | j0 j1 | j   k r| j | d | j | j0 j1 f  n  t | j0 j1 t2 t3 f  rq n  | j0 j1 j j4 | j0 j5  j6 s| j | d | j0 j5 | j0 j1 j7 f  n  | j0 j1 j } | | j0 j1 |
 |  j8   } | j9   } | j0 j:   sx | j; D] } | j | k r| j | d | j | j< | j | j f  n  | j | k ro| j | d | j | j< | j | j f  qoqoWx | j= D] } | j | k rC| j | d | j | j< | j | j f  n  | j | k r| j | d | j | j< | j | j f  qqWx | j>   D] } | j8   | k r| j | d | j | j< | j8   | j f  n  | j8   | k r| j | d | j | j< | j8   | j f  qqWx | j?   D] } | j@ | k	 r1| j8   | k r| j | d  | j | j< | j8   | j f  n  | j8   | k r| j | d! | j | j< | j8   | j f  qq1q1Wqq q Wg  } xtA | j=  D]\ } } | j0 j1 | j   k r`| j | d" | j | j0 j1 f  t | j0 j1 t2 t3 f  r`qq`n  | j6 r| j | d# | j  n  | j0 jB d k	 rt | j0 jB t&  r|
 | j0 j1 } } | | k r| j0 jC r| j0 jB j jD r| j | d$  n  t$ t$ d
 } } } x&| j0 jB j j; D]} t# | j0 d% d  }  | | k r	|  | k rc	| d& 7} n  | d k r5
| j | d' | j0 jB j j< | j j< f  q5
q#	|  | k r	| r	| j | d( | j0 jB j j< | j j< f  q5
t- } q#	|  | k r#	| r,
| j | d( | j0 jB j j< |  j j< f  q5
t- } q#	q#	W| j0 jB | j d) t-  k r}
| j | d* | j | j0 jB f  n  | j0 j1 |
 | j0 jB f }! |! | k r
| j | d+ |
 j j< | j0 jB j j< f  n | jE |!  | j0 jB j jD st$ t$ }" }# xi | j0 jB j j; D]U }$ |$ j0 r|" rI|$ j0 j1 | j0 j1 k rIt- }" qg|$ j0 j1 |
 k rgt- }# qgqqW|" sy|# r| j | d, | j | j0 jB j j< | j0 j1 j j< |
 j j< f  qqn; t | j0 jB t&  r| j | d- | j | j0 jB f  n  | j0 j1 j } | | j0 j1 |
 |  j8   } | j9   } | d k	 rx | j; D] } | j | k r| j | d. | j | j< | j | j f  n  | j | k rM| j | d/ | j | j< | j | j f  qMqMWx | j= D] } | j | k r!| j | d0 | j | j< | j | j f  n  | j | k r| j | d1 | j | j< | j | j f  qqWx | j>   D] } | j@ | k	 rp| j8   | k r| j | d2 | j | j< | j8   | j f  n  | j8   | k r| j | d3 | j | j< | j8   | j f  qqpqpWx | j?   D] } | j8   | k rk| j | d4 | j | j< | j8   | j f  n  | j8   | k r!| j | d5 | j | j< | j8   | j f  q!q!WqqW| jF rwx | jF D] }% |% d6 k rqn  |% jG d7  r|% d& }% n  | jH r|% d8 k rqn  d |% k r.qn  y | j4 |% d9 t$ Wq| jI k
 ro| j | d: |%  qXqWn  x | jJ D] }& x |& D] }% y | j4 |% d9 t- } Wn( | jI k
 r| j | d; |%  qXt | j0 | jK  r| j | d< | j  n  | | j k r| j | d= | j  qqWqWq Wt* | jL  S(>   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   settings(   t   modelst
   connection(   t   get_app_errors(   t   RelatedObjectt   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.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.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.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.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   many_to_manys6   "ordering" refers to "%s", a field that doesn't exist.sN   "unique_together" refers to %s, a field that doesn't exist. Check your syntax.sV   "unique_together" refers to %s. ManyToManyFields are not supported in unique_together.s_   "unique_together" refers to %s. This is not in the same model as the unique_together statement.(M   t   django.confR   t	   django.dbR   R   t   django.db.models.loadingR   t   django.db.models.fields.relatedR   R   t   itemsR   t
   get_modelst   _metat   local_fieldst   namet   primary_keyt   pkt   endswitht
   isinstancet	   CharFieldt   intt
   max_lengtht
   ValueErrort	   TypeErrort   DecimalFieldt   decimal_placest
   max_digitst	   FileFieldt	   upload_tot
   ImageFieldt   PILR   t   ImportErrort   BooleanFieldt   getattrt   Falset   choicest
   basestringR   t   listt   tuplet   lent   db_indext   Nonet   Truet
   validationt   validate_fieldt   relR   t   strt   unicodet	   get_fieldt
   field_namet   uniqueR   t   get_accessor_namet   related_query_namet	   is_hiddent   fieldst   object_namet   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   FieldDoesNotExistt   unique_togethert   ManyToManyRelR   ('   R   t   appR   R   R   R   R   t   et   app_nameR   t   clst   optst   fR0   t   decimalp_msgR4   t   mdigits_msgR5   R   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_fkRV   RL   t   ut(    (    sN   /home/panlixing/Python_Projects/gaeseries/django/core/management/validation.pyt   get_validation_errors   s   	+"$	"(!	&!,/3/3262C#		(+				)/3/3292=	 &(    (   R   t   django.core.management.colorR    t   django.utils.itercompatR   R   RD   R{   (    (    (    sN   /home/panlixing/Python_Projects/gaeseries/django/core/management/validation.pyt   <module>   s   
