Ñò
ÙônMc           @   sè   d  d k  l Z d  d k l Z d  d k l Z d  d k l Z l Z l	 Z	 l
 Z
 d  d k l Z l Z d  d k l Z l Z l Z l Z d g Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿ(   t   ImproperlyConfigured(   t   models(   t   FieldDoesNotExist(   t   BaseModelFormt   BaseModelFormSett   fields_for_modelt   _get_foreign_key(   t   get_fields_from_patht   NotRelationField(   t   flatten_fieldsetst   BaseModelAdmint
   HORIZONTALt   VERTICALt   validatec         C   s¼  t  i ƒ  | i } t |  | ƒ t |  d ƒ ot |  d |  i ƒ xþ t |  i ƒ D]é \ } } t | ƒ pÐ t |  | ƒ p¼ t | | ƒ pY y | i	 | ƒ Wq4t  i
 j
 o2 t d |  i | | |  i | i i f ƒ ‚ q4Xq8t |  | | d | | ƒ } t | t  i ƒ o  t d |  i | | f ƒ ‚ q8q<qS qS Wn t |  d ƒ og t |  d |  i ƒ xQ t |  i ƒ D]< \ } } | |  i j o  t d |  i | | f ƒ ‚ qwqwWn t |  d ƒ o‚ t |  d |  i ƒ xl t |  i ƒ D]W \ } } y t | | ƒ Wqît t
 f j
 o% } t d |  i | | f ƒ ‚ qîXqîWn t |  d	 ƒ o+ t |  i t ƒ o t d
 |  i ƒ ‚ n t |  d ƒ oi|  i o_t |  d |  i ƒ xIt |  i ƒ D]4\ } } y | i | ƒ d } Wn8 t  i
 j
 o) t d |  i | | | i f ƒ ‚ n X| |  i j o  t d |  i | | f ƒ ‚ n | |  i j o# t d | |  i |  i f ƒ ‚ n |  i o> |  i d |  i j o' t d |  i | |  i d f ƒ ‚ n | i p  t d |  i | | f ƒ ‚ qÅqÅWn t |  d ƒ o t |  d |  i ƒ n |  i oR t	 |  | | d |  i ƒ } t | t  i t  i f ƒ p t d |  i ƒ ‚ q„n |  i oÑ t |  d |  i ƒ x» t |  i ƒ D]¦ \ } } | d j o- t |  i ƒ d j o t d |  i ƒ ‚ n | d j o q±n | i  d ƒ o | d } n d | j o q±n t	 |  | | d | | ƒ q±Wn t |  d ƒ o t! |  | | ƒ n xD d& D]< }	 t t" |  |	 ƒ t# ƒ p t d  |  i |	 f ƒ ‚ qŠqŠWt |  d! ƒ oÞ t |  d! |  i$ ƒ xÈ t |  i$ ƒ D]³ \ } }
 t% |
 t& ƒ p t d" |  i | f ƒ ‚ n |
 i' p t d# |  i | f ƒ ‚ n t% |
 i' t  i( ƒ p t d$ |  i | f ƒ ‚ n t |
 |
 i' ƒ t) |
 |  | ƒ qýWn d% S('   sÛ   
    Does basic ModelAdmin option validation. Calls custom validation
    classmethod in the end if it is provided in cls. The signature of the
    custom validation classmethod should be: def validate(cls, model).
    t   list_displaysY   %s.list_display[%d], %r is not a callable or an attribute of %r or found in the model %r.s   list_display[%d]sH   '%s.list_display[%d]', '%s' is a ManyToManyField which is not supported.t   list_display_linkssR   '%s.list_display_links[%d]' refers to '%s' which is not defined in 'list_display'.t   list_filtersD   '%s.list_filter[%d]' refers to '%s' which does not refer to a Field.t   list_per_pages'   '%s.list_per_page' should be a integer.t   list_editablei    sB   '%s.list_editable[%d]' refers to a field, '%s', not defined on %s.sM   '%s.list_editable[%d]' refers to '%s' which is not defined in 'list_display'.sE   '%s' cannot be in both '%s.list_editable' and '%s.list_display_links's}   '%s.list_editable[%d]' refers to the first field in list_display, '%s', which can't be used unless list_display_links is set.sW   '%s.list_editable[%d]' refers to a field, '%s', which isn't editable through the admin.t   search_fieldst   date_hierarchysI   '%s.date_hierarchy is neither an instance of DateField nor DateTimeField.t   orderingt   ?i   s‚   '%s.ordering' has the random ordering marker '?', but contains other fields as well. Please either remove '?' or the other fields.t   -t   __s   ordering[%d]t   readonly_fieldst   list_select_relatedt   save_ast   save_on_tops   '%s.%s' should be a boolean.t   inliness6   '%s.inlines[%d]' does not inherit from BaseModelAdmin.s4   'model' is a required attribute of '%s.inlines[%d]'.s:   '%s.inlines[%d].model' does not inherit from models.Model.N(   R   R   R   (*   R   t   get_appst   _metat   validate_baset   hasattrt   check_isseqR   t	   enumeratet   callablet	   get_fieldR   R    t   __name__t   object_namet
   fetch_attrt
   isinstancet   ManyToManyFieldR   R   R   R   R   t   intR   t   get_field_by_namet   editableR   R   t	   DateFieldt   DateTimeFieldR   t   lent
   startswitht   check_readonly_fieldst   getattrt   boolR   t
   issubclassR
   t   modelt   Modelt   validate_inline(   t   clsR6   t   optst   idxt   fieldt   ft   fpatht   et
   field_namet   attrt   inline(    (    sI   /usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.pyR      sÎ    
	 .* " #$ !"!
"

 #"  
c         C   s¸  |  i  oR t |  |  i |  i i d |  i  ƒ } t | t i ƒ p t d |  i ƒ ‚ q\ n t	 | |  i d |  i  d t
 ƒ} t |  i t ƒ p t d |  i ƒ ‚ n t |  d d  ƒ } | d  j	 o( t | t ƒ o t d |  i ƒ ‚ n t |  d ƒ o+ t |  i t ƒ o t d |  i ƒ ‚ n t |  d	 ƒ oN |  i oD | o9 | i |  i j o& t d
 |  i | i | i f ƒ ‚ q‡n t |  d ƒ o t |  |  i |  i i ƒ n d  S(   Nt   fk_names4   '%s.fk_name is not an instance of models.ForeignKey.t   can_fails   '%s.extra' should be a integer.t   max_nums4   '%s.max_num' should be an integer or None (default).t   formsets4   '%s.formset' does not inherit from BaseModelFormSet.t   excludesR   %s cannot exclude the field '%s' - this is the foreign key to the parent model %s.R   (   RC   R%   R6   R   R)   R   t
   ForeignKeyR    R&   R   t   Truet   extraR+   R3   t   NoneR!   R5   RF   R   RG   t   nameR2   (   R9   t   parentt   parent_modelR=   t   fkRE   (    (    sI   /usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.pyR8   Ÿ   s,    
$!$$c   
      C   s¥  | i  } t |  d ƒ o‹ t |  d |  i ƒ xu t |  i ƒ D]` \ } } t |  | | d | ƒ } t | t i t i	 f ƒ p  t
 d |  i | | f ƒ ‚ q< q< Wn |  i o+t |  d |  i ƒ x´ |  i D]© } | |  i j o qË n t |  | | d | ƒ y | i | ƒ } Wn t i j
 o
 qË n Xt | t i	 ƒ o4 | i i i  i o  t
 d |  i | | f ƒ ‚ qË qË W|  i o t
 d |  i ƒ ‚ n t |  i ƒ t t |  i ƒ ƒ j o t
 d |  i ƒ ‚ qÙn |  i o÷t |  d |  i ƒ x˜t |  i ƒ D]‡\ } } t |  d | | ƒ t | ƒ d	 j o t
 d
 |  i | f ƒ ‚ n t |  d | | d ƒ d | d j o t
 d |  i | f ƒ ‚ n xî | d d D]Þ } t | ƒ t j o | f } n xµ | D]­ } | |  i j o qØn t |  | | d | | ƒ y] | i | ƒ } t | t i	 ƒ o7 | i i i  i o# t
 d |  i | | | f ƒ ‚ n WqØt i j
 o qØXqØWq«WqWt |  i ƒ } t | ƒ t t | ƒ ƒ j o t
 d |  i ƒ ‚ qÚn |  i o¬ t |  d |  i ƒ xV |  i D]K } t |  | | d | ƒ y | i | ƒ } Wqt i j
 o
 qqXqWt |  i ƒ t t |  i ƒ ƒ j o t
 d |  i ƒ ‚ qn t |  d ƒ o+ t |  i t ƒ o t
 d |  i ƒ ‚ n t |  d ƒ o t |  d |  i ƒ xi t |  i ƒ D]T \ } } t |  | | d | ƒ } t | t i	 ƒ p t
 d |  i | f ƒ ‚ qþqþWn t |  d ƒ o t |  d |  i ƒ xi t |  i ƒ D]T \ } } t |  | | d | ƒ } t | t i	 ƒ p t
 d |  i | f ƒ ‚ qqWn t |  d ƒ o¹ t |  d |  i  ƒ x£ |  i  i! ƒ  D]Ž \ } }	 t |  | | d | ƒ } t | t i ƒ p | i" p t
 d |  i | f ƒ ‚ n |	 t# t$ f j o t
 d |  i | f ƒ ‚ qqWn t |  d ƒ oß t |  d |  i% ƒ xÉ |  i% i! ƒ  D]´ \ } }	 t |  | | d | ƒ } t | t i& t i t i	 f ƒ o t
 d |  i | f ƒ ‚ n t |  d | |	 ƒ x: t |	 ƒ D], \ } } t |  | | d | | f | ƒ qiWqåWn d  S(    Nt   raw_id_fieldssL   '%s.raw_id_fields[%d]', '%s' must be either a ForeignKey or ManyToManyField.t   fieldssk   '%s.fields' can't include the ManyToManyField field '%s' because '%s' manually specifies a 'through' model.s.   Both fieldsets and fields are specified in %s.s)   There are duplicate field(s) in %s.fieldst	   fieldsetss   fieldsets[%d]i   s6   '%s.fieldsets[%d]' does not have exactly two elements.s   fieldsets[%d][1]i   sC   'fields' key is required in %s.fieldsets[%d][1] field options dict.s   fieldsets[%d][1]['fields']s   '%s.fieldsets[%d][1]['fields']' can't include the ManyToManyField field '%s' because '%s' manually specifies a 'through' model.s,   There are duplicate field(s) in %s.fieldsetsRG   s*   There are duplicate field(s) in %s.excludet   forms,   %s.form does not inherit from BaseModelForm.t   filter_verticals3   '%s.filter_vertical[%d]' must be a ManyToManyField.t   filter_horizontals5   '%s.filter_horizontal[%d]' must be a ManyToManyField.t   radio_fieldssW   '%s.radio_fields['%s']' is neither an instance of ForeignKey nor does have choices set.sG   '%s.radio_fields['%s']' is neither admin.HORIZONTAL nor admin.VERTICAL.t   prepopulated_fieldssl   '%s.prepopulated_fields['%s']' is either a DateTimeField, ForeignKey or ManyToManyField. This isn't allowed.s   prepopulated_fields['%s']s   prepopulated_fields['%s'][%d]('   R   R!   R"   RP   R#   R%   R)   R   RH   R*   R    R&   RQ   R   t   check_formfieldR   t   relt   throught   auto_createdRR   R0   t   sett   check_isdictt   typet   tupleR	   RG   R5   RS   R   RT   RU   RV   t   itemst   choicesR   R   RW   R/   (
   R9   R6   R:   R;   R<   R=   t   fieldsetRQ   t   flattened_fieldsetst   val(    (    sI   /usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.pyR    Ä   sà    	 "

 '
%
   '!

 %$     c         C   s7   t  | t t f ƒ p t d |  i | f ƒ ‚ n d  S(   Ns    '%s.%s' must be a list or tuple.(   R)   t   listR_   R    R&   (   R9   t   labelt   obj(    (    sI   /usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.pyR"   U  s    c         C   s1   t  | t ƒ p t d |  i | f ƒ ‚ n d  S(   Ns   '%s.%s' must be a dictionary.(   R)   t   dictR    R&   (   R9   Rf   Rg   (    (    sI   /usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.pyR]   Y  s    c         C   sP   y | i  | ƒ SWn8 t i j
 o) t d |  i | | | i f ƒ ‚ n Xd  S(   Ns=   '%s.%s' refers to field '%s' that is missing from model '%s'.(   R%   R   R   R    R&   (   R9   R6   R:   Rf   R<   (    (    sI   /usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.pyR%   ]  s
    c         C   s¬   t  |  i d d  ƒ oH y |  i i | Wq¨ t j
 o# t d |  i | | f ƒ ‚ q¨ XnK t | ƒ } y | | Wn/ t j
 o# t d |  i | | f ƒ ‚ n Xd  S(   Nt   base_fieldss;   '%s.%s' refers to field '%s' that is missing from the form.(   R3   RS   RK   Ri   t   KeyErrorR    R&   R   (   R9   R6   R:   Rf   R<   RQ   (    (    sI   /usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.pyRX   d  s    c      	   C   sw   y | i  | ƒ SWn t i j
 o n Xy t | | ƒ SWn5 t j
 o) t d |  i | | | i f ƒ ‚ n Xd  S(   NsQ   '%s.%s' refers to '%s' that is neither a field, method or property of model '%s'.(   R%   R   R   R3   t   AttributeErrorR    R&   (   R9   R6   R:   Rf   R<   (    (    sI   /usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.pyR(   s  s    c         C   sÅ   t  |  d |  i ƒ x« t |  i ƒ D]š \ } } t | ƒ p t |  | ƒ pm t | | ƒ pY y | i | ƒ Wqµ t i j
 o2 t d |  i	 | | |  i	 | i
 i f ƒ ‚ qµ Xq¹ q½ q# q# Wd  S(   NR   s\   %s.readonly_fields[%d], %r is not a callable or an attribute of %r or found in the model %r.(   R"   R   R#   R$   R!   R%   R   R   R    R&   R   R'   (   R9   R6   R:   R;   R<   (    (    sI   /usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.pyR2   ~  s     N(   t   django.core.exceptionsR    t	   django.dbR   t   django.db.models.fieldsR   t   django.forms.modelsR   R   R   R   t   django.contrib.admin.utilR   R   t   django.contrib.admin.optionsR	   R
   R   R   t   __all__R   R8   R    R"   R]   R%   RX   R(   R2   (    (    (    sI   /usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.pyt   <module>   s   ""		’	%	‘					