
TQc           @@ s  d  Z  d d l m Z m Z d d l m Z m Z m Z d d l m	 Z	 d d l
 m Z m Z d d l m Z m Z d d l m Z m Z d d l m Z d d	 l m Z m Z m Z m Z d d
 l m Z m Z d d l m Z d d l m  Z  d d l! m" Z" m# Z# d d l$ m% Z& m' Z' d d d d d d d f Z( e) e) d  Z* e) d e+ e) e+ d  Z, e) e) d  Z- e) e) e) e) d  Z. d e/ f d     YZ0 d e1 f d     YZ2 d e f d      YZ3 d! e  j4 e2 e3  f d"     YZ5 e5 e) e) e) e) d#  Z6 d$ e f d%     YZ7 e5 e) e7 d& e8 e8 e) e) e) d' 	 Z9 d( e7 f d)     YZ: e) e8 d*  Z; e5 e: e) e) e) d+ e8 e+ e) e) d, 
 Z< d- e f d.     YZ= d/ e f d0     YZ> d1 e/ f d2     YZ? d3 e f d4     YZ@ d5 e@ f d6     YZA d7 S(8   u[   
Helper functions for creating Form classes from Django models
and database field objects.
i    (   t   absolute_importt   unicode_literals(   t   ValidationErrort   NON_FIELD_ERRORSt
   FieldError(   t   EMPTY_VALUES(   t   Fieldt   ChoiceField(   t   BaseFormt   get_declared_fields(   t   BaseFormSett   formset_factory(   t	   ErrorList(   t   SelectMultiplet   HiddenInputt   MultipleHiddenInputt   media_property(   t
   smart_textt
   force_text(   t
   SortedDict(   t   six(   t   get_text_listt   capfirst(   t   ugettext_lazyt   ugettextu	   ModelFormu   BaseModelFormu   model_to_dictu   fields_for_modelu   save_instanceu   ModelChoiceFieldu   ModelMultipleChoiceFieldc   	   	   C@ s  d d l  m } | j } |  j } g  } x | j D] } | j s2 t | | j  s2 | j | k ri q2 n  | d k	 r | j | k r q2 n  | r | j | k r q2 n  t | | j
  r | j |  q2 | j | | | j  q2 Wx% | D] } | j | | | j  q W| S(   u   
    Constructs and returns a model instance from the bound ``form``'s
    ``cleaned_data``, but does not save the returned instance to the
    database.
    i    (   t   modelsN(   t	   django.dbR   t   _metat   cleaned_datat   fieldst   editablet
   isinstancet	   AutoFieldt   namet   Nonet	   FileFieldt   appendt   save_form_data(	   t   formt   instanceR   t   excludeR   t   optsR   t   file_field_listt   f(    (    s,   ../Django//lib/python/django/forms/models.pyt   construct_instance   s$    		u   savedc         @ s   | r t      |   n   j    j rL t d  j | f   n       f d   } | r~  j   |   n	 |   _  S(   u-  
    Saves bound Form ``form``'s cleaned_data into model instance ``instance``.

    If commit=True, then the changes to ``instance`` will be saved to the
    database. Returns ``instance``.

    If construct=False, assume ``instance`` has already been constructed and
    just needs to be saved.
    u8   The %s could not be %s because the data didn't validate.c          @ se     j  }  xU  j D]J }  r4 | j  k r4 q n  | j |  k r | j  |  | j  q q Wd  S(   N(   R   t   many_to_manyR!   R%   (   R   R+   (   R&   R   R'   R)   (    s,   ../Django//lib/python/django/forms/models.pyt   save_m2mN   s    	(   R,   R   t   errorst
   ValueErrort   object_namet   saveR.   (   R&   R'   R   t   fail_messaget   commitR(   t	   constructR.   (    (   R&   R   R'   R)   s,   ../Django//lib/python/django/forms/models.pyt   save_instance;   s    		

	c         C@ s   d d l  m } |  j } i  } x | j | j D] } | j sE q0 n  | r` | j | k r` q0 n  | r{ | j | k r{ q0 n  t | |  r |  j d k r g  | | j <q t
 | j |   j d d t  | | j <q0 | j |   | | j <q0 W| S(   u  
    Returns a dict containing the data in ``instance`` suitable for passing as
    a Form's ``initial`` keyword argument.

    ``fields`` is an optional list of field names. If provided, only the named
    fields will be included in the returned dict.

    ``exclude`` is an optional list of field names. If provided, the named
    fields will be excluded from the returned dict, even if they are listed in
    the ``fields`` argument.
    i    (   t   ManyToManyFieldu   pkt   flatN(   t   django.db.models.fields.relatedR7   R   R   R-   R   R!   R   t   pkR"   t   listt   value_from_objectt   values_listt   True(   R'   R   R(   R7   R)   t   dataR+   (    (    s,   ../Django//lib/python/django/forms/models.pyt   model_to_dictb   s     		.c      	   C@ s  g  } g  } |  j  } xt | j | j  D] } | j sA q, n  | d k	 rb | j | k rb q, n  | r} | j | k r} q, n  | r | j | k r i | | j d 6}	 n i  }	 | d k r | j |	   }
 n* t |  s t	 d   n | | |	  }
 |
 r| j
 | j |
 f  q, | j
 | j  q, Wt |  } | rt g  | D]@ } | se| rF| | k rF| | k rF| | j |  f ^ qF } n  | S(   u6  
    Returns a ``SortedDict`` containing form fields for the given model.

    ``fields`` is an optional list of field names. If provided, only the named
    fields will be included in the returned fields.

    ``exclude`` is an optional list of field names. If provided, the named
    fields will be excluded from the returned fields, even if they are listed
    in the ``fields`` argument.

    ``widgets`` is a dictionary of model field names mapped to a widget

    ``formfield_callback`` is a callable that takes a model field and returns
    a form field.
    u   widgetu1   formfield_callback must be a function or callableN(   R   t   sortedR   R-   R   R"   R!   t	   formfieldt   callablet	   TypeErrorR$   R   t   get(   t   modelR   R(   t   widgetst   formfield_callbackt
   field_listt   ignoredR)   R+   t   kwargsRB   t
   field_dict(    (    s,   ../Django//lib/python/django/forms/models.pyt   fields_for_model   s6    		Ft   ModelFormOptionsc           B@ s   e  Z d d   Z RS(   c         C@ sX   t  | d d   |  _ t  | d d   |  _ t  | d d   |  _ t  | d d   |  _ d  S(   Nu   modelu   fieldsu   excludeu   widgets(   t   getattrR"   RF   R   R(   RG   (   t   selft   options(    (    s,   ../Django//lib/python/django/forms/models.pyt   __init__   s    N(   t   __name__t
   __module__R"   RR   (    (    (    s,   ../Django//lib/python/django/forms/models.pyRN      s   t   ModelFormMetaclassc           B@ s   e  Z d    Z RS(   c         C@ s  | j  d d   } y, g  | D] } t | t  r | ^ q } Wn t k
 rW d  } n Xt | | t  } t t |   j	 |  | | |  } | s | Sd | k r t
 |  | _ n  t t | d d    }	 | _ |	 j rt |	 j |	 j |	 j |	 j |  }
 g  t j |
  D] \ } } | s| ^ q} t |  t | j    } | rd } | d j |  |	 j j f } t |   n  |
 j |  n | }
 | | _ |
 | _ | S(   Nu   formfield_callbacku   mediau   Metau&   Unknown field(s) (%s) specified for %su   , (   t   popR"   t
   issubclasst	   ModelFormt	   NameErrorR	   t   Falset   superRU   t   __new__R   t   mediaRN   RO   R   RF   RM   R   R(   RG   R   t	   iteritemst   sett   keyst   joinRS   R   t   updatet   declared_fieldst   base_fields(   t   clsR!   t   basest   attrsRH   t   bt   parentsRc   t	   new_classR)   R   t   kt   vt   none_model_fieldst   missing_fieldst   message(    (    s,   ../Django//lib/python/django/forms/models.pyR\      s:    ,
		.			(   RS   RT   R\   (    (    (    s,   ../Django//lib/python/django/forms/models.pyRU      s   t   BaseModelFormc        
   B@ sn   e  Z d	 d	 d  d	 d	 e d e d	 d 	 Z d   Z d   Z d   Z d   Z	 d   Z
 e d  Z e e _ RS(
   u   id_%su   :c
      	   C@ s   |  j  }
 |	 d  k rK |
 j d  k r3 t d   n  |
 j   |  _ i  } n! |	 |  _ t |	 |
 j |
 j  } | d  k	 r | j |  n  t	 |  _
 t t |   j | | | | | | | |  d  S(   Nu'   ModelForm has no model class specified.(   R   R"   RF   R0   R'   R@   R   R(   Rb   RZ   t   _validate_uniqueR[   Rp   RR   (   RP   R?   t   filest   auto_idt   prefixt   initialt   error_classt   label_suffixt   empty_permittedR'   R)   t   object_data(    (    s,   ../Django//lib/python/django/forms/models.pyRR      s    				c         C@ s   xg | j    D]Y \ } } | t k r |  j j | |  j    j |  | |  j k rf |  j | =qf q q Wt | k r | t } |  j j t |  j    j |  n  d  S(   N(   t   itemsR   t   _errorst
   setdefaultRv   t   extendR   (   RP   t   message_dictRk   Rl   t   messages(    (    s,   ../Django//lib/python/django/forms/models.pyt   _update_errors   s    "
c         C@ s.  g  } x!|  j  j j D]} | j } | |  j k rG | j | j  q |  j j rx | |  j j k rx | j | j  q |  j j r | |  j j k r | j | j  q | |  j j   k r | j | j  q |  j | } |  j j	 | d  } | j r | j r | t k r | j | j  q q W| S(   u   
        For backwards-compatibility, several types of fields need to be
        excluded from model validation. See the following tickets for
        details: #12507, #12521, #12553
        N(   R'   R   R   R!   R$   R(   R{   R`   R   RE   R"   t   blankt   requiredR   (   RP   R(   R+   t   fieldt
   form_fieldt   field_value(    (    s,   ../Django//lib/python/django/forms/models.pyt   _get_validation_exclusions
  s     		 c         C@ s   t  |  _ |  j S(   N(   R>   Rq   R   (   RP   (    (    s,   ../Django//lib/python/django/forms/models.pyt   clean4  s    	c         C@ s
  |  j  } t |  |  j | j | j  |  _ |  j   } x< |  j j   D]+ \ } } t | t  rF | j	 |  qF qF Wy |  j j
 d |  Wn# t k
 r } |  j | j  n Xy |  j j   Wn* t k
 r } |  j i | j t 6 n X|  j r|  j   n  d  S(   NR(   (   R   R,   R'   R   R(   R   Rz   R   t   InlineForeignKeyFieldR$   t   clean_fieldsR   R   R~   R   R   R   Rq   t   validate_unique(   RP   R)   R(   t   f_nameR   t   e(    (    s,   ../Django//lib/python/django/forms/models.pyt   _post_clean8  s     	!		c         C@ sM   |  j    } y |  j j d |  Wn# t k
 rH } |  j | j  n Xd S(   u   
        Calls the instance's validate_unique() method and updates the form's
        validation errors if any were raised.
        R(   N(   R   R'   R   R   R   R~   (   RP   R(   R   (    (    s,   ../Django//lib/python/django/forms/models.pyR   Z  s
    c         C@ sF   |  j  j d k r d } n d } t |  |  j  |  j j | | d t S(   u   
        Saves this ``form``'s cleaned_data into model instance
        ``self.instance``.

        If commit=True, then the changes to ``instance`` will be saved to the
        database. Returns ``instance``.
        u   createdu   changedR5   N(   R'   R:   R"   R6   R   R   RZ   (   RP   R4   R3   (    (    s,   ../Django//lib/python/django/forms/models.pyR2   e  s
    	N(   RS   RT   R"   R   RZ   RR   R   R   R   R   R   R>   R2   t   alters_data(    (    (    s,   ../Django//lib/python/django/forms/models.pyRp      s   			*		"	RX   c           B@ s   e  Z RS(    (   RS   RT   (    (    (    s,   ../Django//lib/python/django/forms/models.pyRX   v  s   c         C@ s   i |  d 6} | d k	 r& | | d <n  | d k	 r? | | d <n  | d k	 rX | | d <n  t f } t | d  r | j t f } n  t t d  | |  } |  j t d  }	 i | d 6| d 6}
 t |  |	 | f |
  S(	   u2  
    Returns a ModelForm containing form fields for the given model.

    ``fields`` is an optional list of field names. If provided, only the named
    fields will be included in the returned fields.

    ``exclude`` is an optional list of field names. If provided, the named
    fields will be excluded from the returned fields, even if they are listed
    in the ``fields`` argument.

    ``widgets`` is a dictionary of model field names mapped to a widget.

    ``formfield_callback`` is a callable that takes a model field and returns
    a form field.
    u   modelu   fieldsu   excludeu   widgetsu   Metau   Formu   formfield_callbackN(   R"   t   objectt   hasattrt   Metat   typet   strRS   (   RF   R&   R   R(   RH   RG   Rg   t   parentR   t
   class_namet   form_class_attrs(    (    s,   ../Django//lib/python/django/forms/models.pyt   modelform_factoryy  s     	
t   BaseModelFormSetc           B@ s   e  Z d  Z d Z d d d d d d  Z d   Z d   Z d   Z d   Z	 e
 d  Z e
 d  Z e
 d	  Z d
   Z d   Z d   Z d   Z d   Z e
 d  Z e
 d  Z d   Z RS(   uO   
    A ``FormSet`` for editing a queryset and/or adding new objects to it.
    u   id_%sc         K@ sg   | |  _  | j d d   |  _ i | d 6| d 6| d 6| d 6} | j |  t t |   j |   d  S(   Nu   initialu   datau   filesu   auto_idu   prefix(   t   querysetRV   R"   t   initial_extraRb   R[   R   RR   (   RP   R?   Rr   Rs   Rt   R   RK   t   defaults(    (    s,   ../Django//lib/python/django/forms/models.pyRR     s
    	"c         C@ s5   |  j  p |  j s" t |  j    St t |   j   S(   u>   Returns the number of forms that are required in this FormSet.(   R?   Rr   t   lent   get_querysetR[   R   t   initial_form_count(   RP   (    (    s,   ../Django//lib/python/django/forms/models.pyR     s    c         C@ sS   t  |  d  sC t g  |  j   D] } | j | f ^ q  |  _ n  |  j j |  S(   Nu   _object_dict(   R   t   dictR   R:   t   _object_dictRE   (   RP   R:   t   o(    (    s,   ../Django//lib/python/django/forms/models.pyt   _existing_object  s    4c         K@ sf  |  j  r | |  j   k  r d d l m } d |  j |  |  j j j j f } |  j	 | } |  j j j } | j
 d | d | |  j   j } t | t  r | d } n  |  j |  | d <n  | |  j   k  r | j d  r |  j   | | d <n  | |  j   k rM|  j rMy |  j | |  j   | d <WqMt k
 rIqMXn  t t |   j | |  S(   Ni    (   t   connectionsu   %s-%su   exactt
   connectionu   instanceu   initial(   t   is_boundR   R   R   t
   add_prefixRF   R   R:   R!   R?   t   get_db_prep_lookupR   t   dbR   R;   R   RE   R   t
   IndexErrorR[   R   t   _construct_form(   RP   t   iRK   R   t   pk_keyR:   t   pk_field(    (    s,   ../Django//lib/python/django/forms/models.pyR     s$    %"c         C@ sv   t  |  d  so |  j d  k	 r* |  j } n |  j j j   } | j sc | j |  j j j	 j
  } n  | |  _ n  |  j S(   Nu	   _queryset(   R   R   R"   RF   t   _default_managert   get_query_sett   orderedt   order_byR   R:   R!   t	   _queryset(   RP   t   qs(    (    s,   ../Django//lib/python/django/forms/models.pyR     s    	c         C@ s   | j  d |  S(   u:   Saves and returns a new model instance for the given form.R4   (   R2   (   RP   R&   R4   (    (    s,   ../Django//lib/python/django/forms/models.pyt   save_new  s    c         C@ s   | j  d |  S(   u@   Saves and returns an existing model instance for the given form.R4   (   R2   (   RP   R&   R'   R4   (    (    s,   ../Django//lib/python/django/forms/models.pyt   save_existing  s    c         @ sD   | s* g    _    f d   } |   _ n    j |    j |  S(   u   Saves model instances for every form, adding and changing instances
        as necessary, and returns the list of instances.
        c          @ s"   x   j  D] }  |  j   q
 Wd  S(   N(   t   saved_formsR.   (   R&   (   RP   (    s,   ../Django//lib/python/django/forms/models.pyR.     s    (   R   R.   t   save_existing_objectst   save_new_objects(   RP   R4   R.   (    (   RP   s,   ../Django//lib/python/django/forms/models.pyR2     s
    	c         C@ s   |  j    d  S(   N(   R   (   RP   (    (    s,   ../Django//lib/python/django/forms/models.pyR     s    c         C@ s  t    } t    } xt |  j D]i } | j   s4 q n  | j   } | j j d |  \ } } | j t  |   } | j t  |   } q Wg  } x| D]\ } }	 t    }
 x |  j D] } | j   s q n  t g  |	 D]" } | | j k r | j | ^ q  } | r d  | k r | |
 k r| j
 |  j |	   |  j |  j   g  | j t <x- |	 D]" } | | j k r\| j | =q\q\Wn  |
 j |  q q Wq Wx=| D]5} t    }
 | \ } } } } x|  j D]} | j   sqn  | j r| j | d  k	 r| j | d  k	 r| d k rJ| j | } | j | j | j f } n t | j | |  f } | j | f | } | |
 k r| j
 |  j |   |  j |  j   g  | j t <| j | =n  |
 j |  qqWqW| rt |   n  d  S(   NR(   u   date(   R_   t   formst   is_validR   R'   t   _get_unique_checkst   uniont   tupleR   R"   R$   t   get_unique_error_messageRv   t   get_form_errorR{   R   t   addt   yeart   montht   dayRO   t   get_date_error_messageR   (   RP   t   all_unique_checkst   all_date_checksR&   R(   t   unique_checkst   date_checksR/   t   uclasst   unique_checkt	   seen_dataR   t   row_datat
   date_checkt   lookupt
   unique_fort   datet	   date_dataR?   (    (    s,   ../Django//lib/python/django/forms/models.pyR     sX    			5	c         C@ s\   t  |  d k r+ t d  i | d d 6St d  i t | t j t d    d 6Sd  S(   Ni   u0   Please correct the duplicate data for %(field)s.i    u   fielduF   Please correct the duplicate data for %(field)s, which must be unique.u   and(   R   R   R   R   t	   text_typet   _(   RP   R   (    (    s,   ../Django//lib/python/django/forms/models.pyR   I  s    	c         C@ s8   t  d  i | d d 6| d d 6t j | d  d 6S(   Nuo   Please correct the duplicate data for %(field_name)s which must be unique for the %(lookup)s in %(date_field)s.i   u
   field_namei   u
   date_fieldi   u   lookup(   R   R   R   (   RP   R   (    (    s,   ../Django//lib/python/django/forms/models.pyR   T  s
    	c         C@ s
   t  d  S(   Nu*   Please correct the duplicate values below.(   R   (   RP   (    (    s,   ../Django//lib/python/django/forms/models.pyR   \  s    c   	      C@ sB  g  |  _  g  |  _ |  j s g  Sg  } y |  j } Wn t k
 rK g  } n Xx |  j D] } |  j j } | j |  } | j | j	 |  } t
 | d |  } |  j |  } | | k r |  j j |  | j   qV n  | j   rV |  j  j | | j f  | j |  j | | d |  | s:|  j j |  q:qV qV W| S(   Nu   pkR4   (   t   changed_objectst   deleted_objectst   initial_formst   deleted_formst   AttributeErrort	   _pk_fieldR!   t
   _raw_valueR   R   RO   R   R$   t   deletet   has_changedt   changed_dataR   R   (	   RP   R4   t   saved_instancest   forms_to_deleteR&   t   pk_namet   raw_pk_valuet   pk_valuet   obj(    (    s,   ../Django//lib/python/django/forms/models.pyR   _  s2    			

c         C@ s   g  |  _  xy |  j D]n } | j   s+ q n  |  j rI |  j |  rI q n  |  j  j |  j | d |  | s |  j j |  q q W|  j  S(   NR4   (   t   new_objectst   extra_formsR   t
   can_deletet   _should_delete_formR$   R   R   (   RP   R4   R&   (    (    s,   ../Django//lib/python/django/forms/models.pyR     s    	c      
   @ sk  d d l  m  m } m } |  j j j |  _ }    f d       |  sb | j | j	 k rN| j
 rz | j j } nF y, | d k	 r |  j   | j } n d } Wn t k
 r d } n Xt | |  s t | |  r | j j j j   } n |  j j j   } | j | j j j  } t | d | d t d t | j	 |  j j <n  t t |   j | |  d S(   u0   Add a hidden field for the object's primary key.i    (   R    t   OneToOneFieldt
   ForeignKeyc         @ sM   |  j  pL |  j pL t |     pL |  j oL |  j j oL  |  j j j j  S(   N(   R   t   auto_createdR   t   relt   parent_linkt   toR   R:   (   R:   (   R    t   pk_is_not_editable(    s,   ../Django//lib/python/django/forms/models.pyR     s    "Ru   R   t   widgetN(   t   django.db.modelsR    R   R   RF   R   R:   R   R!   R   R   R'   R"   R   R   R   R   R   R   R   t   usingt   _stateR   t   ModelChoiceFieldRZ   R   R[   R   t
   add_fields(   RP   R&   t   indexR   R   R:   R   R   (    (   R   R    s,   ../Django//lib/python/django/forms/models.pyR     s$    	

.N(   RS   RT   t   __doc__R"   RF   RR   R   R   R   R   R>   R   R   R2   R   R   R   R   R   R   R   R   (    (    (    s,   ../Django//lib/python/django/forms/models.pyR     s&   						B			 i   c
         C@ sX   t  |  d | d | d |	 d | } t | | d | d | d | d | }
 |  |
 _ |
 S(	   uC   
    Returns a FormSet class for the given Django model class.
    R&   R   R(   RH   t   extrat   max_numt	   can_orderR   (   R   R   RF   (   RF   R&   RH   t   formsetR   R   R   R   R   R(   t   FormSet(    (    s,   ../Django//lib/python/django/forms/models.pyt   modelformset_factory  s    		t   BaseInlineFormSetc           B@ sh   e  Z d  Z d d d e d d d  Z d   Z d   Z e d    Z	 e
 d  Z d   Z d   Z RS(	   u0   A formset for child objects related to a parent.c   
      K@ s   d d l  m } | d  k r4 |  j j j   |  _ n	 | |  _ | |  _ | |  j j j |  j |  j  j	   |  _
 | d  k r |  j j } n  |  j j r | j i |  j |  j j 6  }	 n | j d g   }	 t t |   j | | d | d |	 | d  S(   Ni    (   t   RelatedObjectt   pk__inRt   R   (   R9   R   R"   t   fkR   R   R'   t   save_as_newRF   t   get_accessor_namet   rel_nameR   R:   t   filterR!   R[   R   RR   (
   RP   R?   Rr   R'   R  Rt   R   RK   R   R   (    (    s,   ../Django//lib/python/django/forms/models.pyRR     s    		*"c         C@ s    |  j  r d St t |   j   S(   Ni    (   R  R[   R   R   (   RP   (    (    s,   ../Django//lib/python/django/forms/models.pyR     s    	c         K@ s   t  t |   j | |  } |  j r_ d  | j | j |  j j  <d  | j | j |  j	 j  <n  t
 | j |  j	 j   |  j j  | S(   N(   R[   R   R   R  R"   R?   R   R   R!   R   t   setattrR'   t   get_attnameR:   (   RP   R   RK   R&   (    (    s,   ../Django//lib/python/django/forms/models.pyR     s    	"c         C@ sA   d d l  m } | |  j j j |  j |  j  j   j d d  S(   Ni    (   R   u   +u    (   R9   R   R   R   R   RF   R  t   replace(   Re   R   (    (    s,   ../Django//lib/python/django/forms/models.pyt   get_default_prefix  s    c         C@ s   | j  d t  } t |  j |  j j j  } t | |  j j   t | d |   | re | j    n  | r t	 | d  r | j
   n  | S(   NR4   u   pku   save_m2m(   R2   RZ   RO   R'   R   R   t
   field_nameR  R  R   R.   (   RP   R&   R4   R   R   (    (    s,   ../Django//lib/python/django/forms/models.pyR     s    %c         C@ s6  t  t |   j | |  |  j |  j k rG |  j j } i t d 6} nz |  j j } i t | j j	 |  d t
 |  j j   d 6} |  j j j |  j j j j j j k r |  j j j | d <n  t |  j |  | j | <| j j r2t | j j t  rt | j j  | j _ n  | j j j |  j j  n  d  S(   Nu   pk_fieldu   labelu   to_field(   R[   R   R   R   R   R!   R>   RO   R   RE   R   t   verbose_nameR   R	  R   R   R:   R   R'   R   R   R;   R$   (   RP   R&   R   R!   RK   (    (    s,   ../Django//lib/python/django/forms/models.pyR     s    .'c         C@ sA   g  | D] } | |  j  j k r | ^ q } t t |   j |  S(   N(   R   R!   R[   R   R   (   RP   R   R   (    (    s,   ../Django//lib/python/django/forms/models.pyR     s    +N(   RS   RT   R   R"   RZ   RR   R   R   t   classmethodR  R>   R   R   R   (    (    (    s,   ../Django//lib/python/django/forms/models.pyR     s   				c   	      C@ s  d d l  m } | j } | r g  | j D] } | j | k r) | ^ q) } t |  d k r | d } t | |  s | j j |  k r | j j |  j j	   k r t
 d | |  f   q qt |  d k rt
 d | | f   qn g  | j D]H } t | |  r | j j |  k s9| j j |  j j	   k r | ^ q } t |  d k rd| d } nK t |  d k r| rd St
 d | |  f   n t
 d | |  f   | S(	   uH  
    Finds and returns the ForeignKey from model to parent if there is one
    (returns None if can_fail is True and no such field exists). If fk_name is
    provided, assume it is the name of the ForeignKey field. Unles can_fail is
    True, an exception is raised if there is no ForeignKey from model to
    parent_model.
    i    (   R   i   u&   fk_name '%s' is not a ForeignKey to %su   %s has no field named '%s'Nu   %s has no ForeignKey to %su#   %s has more than 1 ForeignKey to %s(   R   R   R   R   R!   R   R   R   R   t   get_parent_listt	   Exception(	   t   parent_modelRF   t   fk_namet   can_failR   R)   R+   t   fks_to_parentR   (    (    s,   ../Django//lib/python/django/forms/models.pyt   _get_foreign_key  s0    		+
'i   c         C@ s   t  |  | d | } | j r' d }
 n  i	 | d 6| d 6| d 6| d 6|	 d 6| d 6| d	 6| d
 6|
 d 6} t | |  } | | _ | S(   u   
    Returns an ``InlineFormSet`` for the given kwargs.

    You must provide ``fk_name`` if ``model`` has more than one ``ForeignKey``
    to ``parent_model``.
    R  i   u   formu   formfield_callbacku   formsetu   extrau
   can_deleteu	   can_orderu   fieldsu   excludeu   max_num(   R  t   uniqueR   R   (   R  RF   R&   R   R  R   R(   R   R   R   R   RH   R   RK   R   (    (    s,   ../Django//lib/python/django/forms/models.pyt   inlineformset_factory=  s     		
	t   InlineForeignKeyHiddenInputc           B@ s   e  Z d    Z RS(   c         C@ s   t  S(   N(   RZ   (   RP   Ru   R?   (    (    s,   ../Django//lib/python/django/forms/models.pyt   _has_changed_  s    (   RS   RT   R  (    (    (    s,   ../Django//lib/python/django/forms/models.pyR  ^  s   R   c           B@ s3   e  Z d  Z i e d  d 6Z d   Z d   Z RS(   uw   
    A basic integer field that deals with validating the given value to a
    given parent instance in an inline.
    uE   The inline foreign key did not match the parent instance primary key.u   invalid_choicec         O@ s   | |  _  | j d t  |  _ | j d d   |  _ |  j  d  k	 rz |  j rg t |  j  |  j  | d <qz |  j  j | d <n  t | d <t | d <t	 t
 |   j | |   d  S(   Nu   pk_fieldu   to_fieldu   initialu   requiredu   widget(   t   parent_instanceRV   RZ   R   R"   t   to_fieldRO   R:   R  R[   R   RR   (   RP   R  t   argsRK   (    (    s,   ../Django//lib/python/django/forms/models.pyRR   k  s    		

c         C@ s   | t  k r  |  j r d  S|  j S|  j rA t |  j |  j  } n |  j j } t |  t |  k r{ t |  j	 d   n  |  j S(   Nu   invalid_choice(
   R   R   R"   R  R  RO   R:   R   R   t   error_messages(   RP   t   valuet   orig(    (    s,   ../Django//lib/python/django/forms/models.pyR   x  s    		(   RS   RT   R   R   t   default_error_messagesRR   R   (    (    (    s,   ../Django//lib/python/django/forms/models.pyR   b  s
   	t   ModelChoiceIteratorc           B@ s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C@ s   | |  _  | j |  _ d  S(   N(   R   R   (   RP   R   (    (    s,   ../Django//lib/python/django/forms/models.pyRR     s    	c         c@ s   |  j  j d  k	 r& d |  j  j f Vn  |  j  j r |  j  j d  k rx g  |  j j   D] } |  j |  ^ qT |  j  _ n  xD |  j  j D] } | Vq Wn( x% |  j j   D] } |  j |  Vq Wd  S(   Nu    (   R   t   empty_labelR"   t   cache_choicest   choice_cacheR   t   allt   choice(   RP   R   R#  (    (    s,   ../Django//lib/python/django/forms/models.pyt   __iter__  s    4c         C@ s   t  |  j  S(   N(   R   R   (   RP   (    (    s,   ../Django//lib/python/django/forms/models.pyt   __len__  s    c         C@ s"   |  j  j |  |  j  j |  f S(   N(   R   t   prepare_valuet   label_from_instance(   RP   R   (    (    s,   ../Django//lib/python/django/forms/models.pyR#    s    (   RS   RT   RR   R$  R%  R#  (    (    (    s,   ../Django//lib/python/django/forms/models.pyR    s   			R   c        	   B@ s   e  Z d  Z i e d  d 6Z d e e d d d d d d  Z d   Z	 d   Z
 d   Z e e
 e  Z d   Z d	   Z e e e j  Z d
   Z d   Z d   Z RS(   u1   A ChoiceField whose choices are a model QuerySet.uG   Select a valid choice. That choice is not one of the available choices.u   invalid_choiceu	   ---------c
      
   O@ sq   | r | d  k	 r d  |  _ n	 | |  _ | |  _ t j |  | | | | | |
 |  | |  _ d  |  _ |	 |  _ d  S(   N(   R"   R  R   R   RR   R   R!  t   to_field_name(   RP   R   R  R   R   R   t   labelRu   t	   help_textR(  R  RK   (    (    s,   ../Django//lib/python/django/forms/models.pyRR     s    		
		c         C@ s(   t  t |   j |  } | j | _ | S(   N(   R[   R   t   __deepcopy__R   (   RP   t   memot   result(    (    s,   ../Django//lib/python/django/forms/models.pyR+    s    c         C@ s   |  j  S(   N(   R   (   RP   (    (    s,   ../Django//lib/python/django/forms/models.pyt   _get_queryset  s    c         C@ s   | |  _  |  j |  j _ d  S(   N(   R   t   choicesR   (   RP   R   (    (    s,   ../Django//lib/python/django/forms/models.pyt   _set_queryset  s    	c         C@ s
   t  |  S(   u   
        This method is used to convert objects into strings; it's used to
        generate the labels for the choices presented by this object. Subclasses
        can override this method to customize the display of the choices.
        (   R   (   RP   R   (    (    s,   ../Django//lib/python/django/forms/models.pyR'    s    c         C@ s    t  |  d  r |  j St |   S(   Nu   _choices(   R   t   _choicesR  (   RP   (    (    s,   ../Django//lib/python/django/forms/models.pyt   _get_choices  s    	c         C@ sH   t  | d  r2 |  j r( | j |  j  S| j Sn  t t |   j |  S(   Nu   _meta(   R   R(  t   serializable_valueR:   R[   R   R&  (   RP   R  (    (    s,   ../Django//lib/python/django/forms/models.pyR&    s
    	
c         C@ sv   | t  k r d  Sy, |  j p d } |  j j i | | 6  } Wn3 t |  j j j f k
 rq t |  j	 d   n X| S(   Nu   pku   invalid_choice(
   R   R"   R(  R   RE   R0   RF   t   DoesNotExistR   R  (   RP   R  t   key(    (    s,   ../Django//lib/python/django/forms/models.pyt	   to_python  s    c         C@ s   t  j |  |  S(   N(   R   t   validate(   RP   R  (    (    s,   ../Django//lib/python/django/forms/models.pyR7    s    N(   RS   RT   R   R   R  RZ   R>   R"   RR   R+  R.  R0  t   propertyR   R'  R2  R   t   _set_choicesR/  R&  R6  R7  (    (    (    s,   ../Django//lib/python/django/forms/models.pyR     s    							
t   ModelMultipleChoiceFieldc           B@ st   e  Z d  Z e Z e Z i e d  d 6e d  d 6e d  d 6Z e	 e
 d
 d
 d
 d
 d  Z d   Z d	   Z RS(   u9   A MultipleChoiceField whose choices are a model QuerySet.u   Enter a list of values.u   listu>   Select a valid choice. %s is not one of the available choices.u   invalid_choiceu,   "%s" is not a valid value for a primary key.u   invalid_pk_valuec   
      O@ s5   t  t |   j | d  | | | | | | | |	  d  S(   N(   R[   R:  RR   R"   (
   RP   R   R   R   R   R)  Ru   R*  R  RK   (    (    s,   ../Django//lib/python/django/forms/models.pyRR     s    c      
   C@ sn  |  j  r& | r& t |  j d   n |  j  rD | rD |  j j   St | t t f  so t |  j d   n  |  j p{ d } xT | D]L } y |  j j	 i | | 6  Wq t
 k
 r t |  j d |   q Xq W|  j j	 i | d | 6  } t g  | D] } t t | |   ^ q  } x: | D]2 } t |  | k r't |  j d |   q'q'W|  j |  | S(   Nu   requiredu   listu   pku   invalid_pk_valueu   %s__inu   invalid_choice(   R   R   R  R   t   noneR   R;   R   R(  R  R0   R_   R   RO   t   run_validators(   RP   R  R5  R:   R   R   t   pkst   val(    (    s,   ../Django//lib/python/django/forms/models.pyR     s&    .c         C@ sq   t  | d  r[ t | t j  r[ t  | d  r[ g  | D] } t t |   j |  ^ q9 St t |   j |  S(   Nu   __iter__u   _meta(   R   R   R   R   R[   R:  R&  (   RP   R  Rl   (    (    s,   ../Django//lib/python/django/forms/models.pyR&  "  s
    )N(   RS   RT   R   R   R   R   t   hidden_widgetR   R  RZ   R>   R"   RR   R   R&  (    (    (    s,   ../Django//lib/python/django/forms/models.pyR:    s   		N(B   R   t
   __future__R    R   t   django.core.exceptionsR   R   R   t   django.core.validatorsR   t   django.forms.fieldsR   R   t   django.forms.formsR   R	   t   django.forms.formsetsR
   R   t   django.forms.utilR   t   django.forms.widgetsR   R   R   R   t   django.utils.encodingR   R   t   django.utils.datastructuresR   t   django.utilsR   t   django.utils.textR   R   t   django.utils.translationR   R   R   t   __all__R"   R,   R>   R6   R@   RM   R   RN   R   RU   Rp   t   with_metaclassRX   R   R   RZ   R   R   R  R  R  R   R  R   R:  (    (    (    s,   ../Django//lib/python/django/forms/models.pyt   <module>   sV   "&$2'"	3	X(%Y