
}Mc           @   s  d  Z  d d k l Z l Z d d k l Z d d k l Z l Z d d k	 l
 Z l Z d d k l Z l Z l Z d d k l Z d d k l Z d d	 k l Z l Z d d
 k l Z l Z d d k l Z l Z l Z d d k l Z d d k  l! Z! l" Z" d3 Z# d2 d2 d  Z% d2 d e& d2 e& d  Z' d2 d2 d  Z( d2 d2 d2 d2 d  Z) d e* f d     YZ+ d e, f d     YZ- d e f d     YZ. d e. f d     YZ/ e/ d2 d2 d2 d   Z0 d! e! f d"     YZ1 e/ d2 e1 d# e2 e2 d2 d2 d2 d$ 	 Z3 d% e1 f d&     YZ4 d2 e2 d'  Z5 e/ e4 d2 d2 d2 d( e2 e& d2 d2 d) 
 Z6 d* e f d+     YZ7 d, e f d-     YZ8 d. e* f d/     YZ9 d e f d0     YZ: d e: f d1     YZ; d2 S(4   s[   
Helper functions for creating Form classes from Django models
and database field objects.
i(   t   smart_unicodet   force_unicode(   t
   SortedDict(   t   get_text_listt   capfirst(   t   ugettext_lazyt   ugettext(   t   ValidationErrort   NON_FIELD_ERRORSt
   FieldError(   t   EMPTY_VALUES(   t	   ErrorList(   t   BaseFormt   get_declared_fields(   t   Fieldt   ChoiceField(   t   SelectMultiplet   HiddenInputt   MultipleHiddenInput(   t   media_property(   t   BaseFormSett   formset_factoryt	   ModelFormt   BaseModelFormt   model_to_dictt   fields_for_modelt   save_instancet   ModelChoiceFieldt   ModelMultipleChoiceFieldc   	      C   s  d d k  l } | i } |  i } g  } x | i D] } | i p# t | | i  p | i | j o q2 n | d j	 o | i | j o q2 n | o | i | j o q2 n t | | i
  o | i |  q2 | i | | | i  q2 Wx% | D] } | i | | | i  q W| S(   s   
    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=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   construct_instance   s(    		
  t   savedc            s   | o t      |   n  i    i o t d  i | f   n      f d   } | o  i   |   n
 |   _  S(   s-  
    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.
    s8   The %s could not be %s because the data didn't validate.c             sj     i  }  xZ  i D]O }  o | i  j o q n | i |  j o | i  |  | i  q q Wd  S(   N(   R    t   many_to_manyR%   R)   (   R    R/   (   R*   R!   R+   R-   (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   save_m2mL   s    	
 (   R0   R   t   errorst
   ValueErrort   object_namet   saveR3   (   R*   R+   R!   t   fail_messaget   commitR,   t	   constructR3   (    (   R*   R!   R+   R-   s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   9   s    	

	c   	      C   s
  d d k  l } |  i } h  } x | i | i D] } | i p q0 n | o | i | j o q0 n | o | i | j o q0 n t | |  oY |  i d j o g  | | i <qg  } | i
 |   D] } | | i q ~ | | i <q0 | i
 |   | | i <q0 W| S(   s  
    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   ManyToManyFieldN(   t   django.db.models.fields.relatedR;   R   R!   R2   R"   R%   R#   t   pkR&   t   value_from_object(	   R+   R!   R,   R;   R-   t   dataR/   t   _[1]t   obj(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   `   s"    	 
8c      	   C   s  g  } g  } |  i  } x| i | i D]} | i p q& n | d j	 o | i | j o q& n | o | i | j o q& n | o( | i | j o h | | i d 6}	 n h  }	 | d j o | i |	   }
 n- t |  p t d   n | | |	  }
 |
 o | i	 | i |
 f  q& | i	 | i  q& Wt
 |  } | og t
 g  } | D]I } | p | o | | j o' | | j o | | | i |  f qVqV~  } n | S(   s  
    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.
    t   widgets1   formfield_callback must be a function or callableN(   R   R!   R2   R"   R&   R%   t	   formfieldt   callablet	   TypeErrorR(   R   t   get(   t   modelR!   R,   t   widgetst   formfield_callbackt
   field_listt   ignoredR-   R/   t   kwargsRC   t
   field_dictR@   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR      s8    	 
S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(   NRG   R!   R,   RH   (   t   getattrR&   RG   R!   R,   RH   (   t   selft   options(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   __init__   s    N(   t   __name__t
   __module__R&   RR   (    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyRN      s   t   ModelFormMetaclassc           B   s   e  Z d    Z RS(   c         C   s  | i  d d   } y9 g  } | D]! } t | t  o | | q  q  ~ } Wn t j
 o d  } n Xt | | t  } t t |   i	 |  | | |  }	 | p |	 Sd | j o t
 |	  |	 _ n t t |	 d d    }
 |	 _ |
 i o t |
 i |
 i |
 i |
 i |  } g  } | i   D] \ } } | p | | q$q$~ } t |  t | i    } | o5 d } | d i |  |
 i i f } t |   n | i |  n | } | |	 _ | |	 _ |	 S(   NRI   t   mediat   Metas&   Unknown field(s) (%s) specified for %ss   , (   t   popR&   t
   issubclassR   t	   NameErrorR   t   Falset   superRU   t   __new__R   RV   RN   RO   R   RG   R   R!   R,   RH   t	   iteritemst   sett   keyst   joinRS   R	   t   updatet   declared_fieldst   base_fields(   t   clsR%   t   basest   attrsRI   R@   t   bt   parentsRc   t	   new_classR-   R!   t   _[2]t   kt   vt   none_model_fieldst   missing_fieldst   message(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR]      s:    9	
8			(   RS   RT   R]   (    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyRU      s   c        
   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(
   s   id_%st   :c
      	   C   s   |  i  }
 |	 d  j o9 |
 i d  j o t d   n |
 i   |  _ h  } n" |	 |  _ t |	 |
 i |
 i  } | d  j	 o | i |  n t	 |  _
 t t |   i | | | | | | | |  d  S(   Ns'   ModelForm has no model class specified.(   R   R&   RG   R5   R+   R   R!   R,   Rb   R[   t   _validate_uniqueR\   R   RR   (   RP   R?   t   filest   auto_idt   prefixt   initialt   error_classt   label_suffixt   empty_permittedR+   R-   t   object_data(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyRR      s    	
		c         C   s   xk | i    D]] \ } } | t j oD |  i i | |  i    i |  | |  i j o |  i | =qj q q Wt | j o0 | t } |  i i t |  i    i |  n d  S(   N(   t   itemsR   t   _errorst
   setdefaultRw   t   extendR    (   RP   t   message_dictRl   Rm   t   messages(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   _update_errors   s     "
c         C   s<  g  } x/|  i  i i D]} | i } | |  i j o | i | i  q |  i i o' | |  i i j o | i | i  q |  i i o' | |  i i j o | i | i  q | |  i i   j o | i | i  q |  i | } |  i i	 | d  } | i o, | i o! | t j o | i | i  q q W| S(   s   
        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    RF   R&   t   blankt   requiredR
   (   RP   R,   R/   t   fieldt
   form_fieldt   field_value(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   _get_validation_exclusions  s"     	  	#c         C   s   t  |  _ |  i S(   N(   t   TrueRr   R    (   RP   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   clean-  s    	c      
   C   s  |  i  } t |  |  i | i | i  |  _ |  i   } x> |  i i   D]- \ } } t | t  o | i	 |  qF qF Wy |  i i
 d |  Wn% t j
 o } |  i | i  n Xy |  i i   Wn, t j
 o  } |  i h | i t 6 n X|  i o |  i   n d  S(   NR,   (   R   R0   R+   R!   R,   R   R{   R#   t   InlineForeignKeyFieldR(   t   clean_fieldsR   R   R   R   R   R   Rr   t   validate_unique(   RP   R-   R,   t   f_nameR   t   e(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   _post_clean1  s"    	!	 
c         C   sO   |  i    } y |  i i d |  Wn% t j
 o } |  i | i  n Xd S(   s   
        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=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   S  s
    c         C   sH   |  i  i d j o
 d } n d } t |  |  i  |  i i | | d t S(   s   
        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``.
        t   createdt   changedR:   N(   R+   R=   R&   R   R   R!   R[   (   RP   R9   R8   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR7   ^  s
    
N(   RS   RT   R&   R   R[   RR   R   R   R   R   R   R   R7   t   alters_data(    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR      s   			*		"	c           B   s   e  Z e Z RS(    (   RS   RT   RU   t   __metaclass__(    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   o  s   c   
      C   s   h |  d 6} | d  j	 o | | d <n | d  j	 o | | d <n t f } t | d  o | i t f } n t d | |  } |  i d } h | d 6| d 6}	 t | | f |	  S(   NRG   R!   R,   RW   t   FormRI   (   R&   t   objectt   hasattrRW   t   typeRS   RU   (
   RG   R*   R!   R,   RI   Rg   t   parentRW   t
   class_namet   form_class_attrs(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   modelform_factoryr  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(   sO   
    A ``FormSet`` for editing a queryset and/or adding new objects to it.
    s   id_%sc         K   sR   | |  _  h | d 6| d 6| d 6| d 6} | i |  t t |   i |   d  S(   NR?   Rs   Rt   Ru   (   t   querysetRb   R\   R   RR   (   RP   R?   Rs   Rt   Ru   R   RL   t   defaults(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyRR     s    	"c         C   s8   |  i  p |  i p t |  i    St t |   i   S(   s>   Returns the number of forms that are required in this FormSet.(   R?   Rs   t   lent   get_querysetR\   R   t   initial_form_count(   RP   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s    c         C   s]   t  |  d  p= t g  } |  i   D] } | | i | f q$ ~  |  _ n |  i i |  S(   Nt   _object_dict(   R   t   dictR   R=   R   RF   (   RP   R=   R@   t   o(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   _existing_object  s    =c         K   s  |  i  o | |  i   j  o d d k l } d |  i |  |  i i i i f } |  i	 | } |  i i i } | i
 d | d | |  i   i } t | t  o | d } n |  i |  | d <n | |  i   j  o) | i d  o |  i   | | d <n t t |   i | |  S(   Ni(   t   connectionss   %s-%st   exactt
   connectioni    R+   (   t   is_boundR   R   R   t
   add_prefixRG   R   R=   R%   R?   t   get_db_prep_lookupR   t   dbR#   t   listR   RF   R\   R   t   _construct_form(   RP   t   iRL   R   t   pk_keyR=   t   pk_field(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s    %$c         C   s|   t  |  d  pe |  i d  j	 o |  i } n |  i i i   } | i p | i |  i i i	 i
  } n | |  _ n |  i S(   Nt	   _queryset(   R   R   R&   RG   t   _default_managert   get_query_sett   orderedt   order_byR   R=   R%   R   (   RP   t   qs(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s    
c         C   s   | i  d |  S(   s:   Saves and returns a new model instance for the given form.R9   (   R7   (   RP   R*   R9   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   save_new  s    c         C   s   | i  d |  S(   s@   Saves and returns an existing model instance for the given form.R9   (   R7   (   RP   R*   R+   R9   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   save_existing  s    c            sF   | p% g    _    f d   } |   _ n   i |    i |  S(   s   Saves model instances for every form, adding and changing instances
        as necessary, and returns the list of instances.
        c             s"   x   i  D] }  |  i   q
 Wd  S(   N(   t   saved_formsR3   (   R*   (   RP   (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR3     s    
 (   R   R3   t   save_existing_objectst   save_new_objects(   RP   R9   R3   (    (   RP   s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR7     s
    	c         C   s   |  i    d  S(   N(   R   (   RP   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s    c      
   C   s  t    } t    } xy |  i D]n } t | d  p q n | i   } | i i d |  \ } } | i t  |   } | i t  |   } q Wg  } x | D] \ } }	 t    }
 x |  i D] } t | d  p q n t g  } |	 D]( } | | i j o | | i | q q ~  } | ok d  | j o^ | |
 j o@ | i
 |  i |	   |  i |  i   g  | i t <| ` Pn |
 i |  q q Wq WxG| D]?} t    }
 | \ } } } } x|  i D]} t |  d  p qn | i o | i | d  j	 o | i | d  j	 o | d j o) | i | } | i | i | i f } n t | i | |  f } | i | f | } | |
 j o@ | i
 |  i |   |  i |  i   g  | i t <| ` Pn |
 i |  qqWqW| o t |   n d  S(   NR    R,   t   date(   R_   t   formsR   R   R+   t   _get_unique_checkst   uniont   tupleR    R&   R(   t   get_unique_error_messageRw   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_checksR4   t   uclasst   unique_checkt	   seen_dataR@   R   t   row_datat
   date_checkt   lookupt
   unique_forR   t	   date_dataR?   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     sb    		
  	
 B 	
 c         C   s[   t  |  d j o t d  h | d d 6St d  h t | t t d    d 6Sd  S(   Ni   s0   Please correct the duplicate data for %(field)s.i    R   sF   Please correct the duplicate data for %(field)s, which must be unique.t   and(   R   R   R   t   unicodet   _(   RP   R   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   *  s    	c         C   s5   t  d  h | d d 6| d d 6t | d  d 6S(   Nso   Please correct the duplicate data for %(field_name)s which must be unique for the %(lookup)s in %(date_field)s.i   t
   field_namei   t
   date_fieldi   R   (   R   R   (   RP   R   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   5  s
    	c         C   s
   t  d  S(   Ns*   Please correct the duplicate values below.(   R   (   RP   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   =  s    c         C   s3  g  |  _  g  |  _ |  i   p g  Sg  } x|  i D] } |  i i } | i |  } | i | i |  } t	 | d |  } |  i
 |  } |  i o1 |  i |  o! |  i i |  | i   q4 n | i   oW |  i  i | | i f  | i |  i | | d |  | p |  i i |  q+q4 q4 W| S(   NR=   R9   (   t   changed_objectst   deleted_objectsR   t   initial_formst	   _pk_fieldR%   t
   _raw_valueR!   R   RO   R   t
   can_deletet   _should_delete_formR(   t   deletet   has_changedt   changed_dataR   R   (   RP   R9   t   saved_instancesR*   t   pk_namet   raw_pk_valuet   pk_valueRA   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   @  s,    		
 
c         C   s   g  |  _  x |  i D]u } | i   p q n |  i o |  i |  o q n |  i  i |  i | d |  | p |  i i |  q q W|  i  S(   NR9   (   t   new_objectst   extra_formsR   R   R   R(   R   R   (   RP   R9   R*   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   \  s    	
 c            sw  d d k  l  l } l } |  i i i |  _ }    f d       |  p | i | i	 j o | i
 o | i i } nK y. | d j	 o |  i   | i } n d } Wn t j
 o d } n Xt | |  p t | |  o | i i i i   } n |  i i i   } | i | i i i  } t | d | d t d t | i	 |  i i <n t t |   i | |  d S(   s0   Add a hidden field for the object's primary key.i(   R$   t   OneToOneFieldt
   ForeignKeyc            sR   |  i  pG |  i p= t |     p- |  i o# |  i i o  |  i i i i  S(   N(   R"   t   auto_createdR#   t   relt   parent_linkt   toR   R=   (   R=   (   R$   t   pk_is_not_editable(    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   s  s    %Rv   R   RB   N(   t   django.db.modelsR$   R   R   RG   R   R=   R   R%   R!   R   R+   R&   R   t
   IndexErrorR#   R   R   R   R   t   usingt   _stateR   R   R[   R   R\   R   t
   add_fields(   RP   R*   t   indexR   R   R=   R   R   (    (   R   R$   s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   j  s$     

 /N(   RS   RT   t   __doc__R&   RG   RR   R   R   R   R   R   R   R   R7   R   R   R   R   R   R   R   R   (    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s&   						C			i   c
         C   sX   t  |  d | d | d |	 d | } t | | d | d | d | d | }
 |  |
 _ |
 S(	   sC   
    Returns a FormSet class for the given Django model class.
    R*   R!   R,   RI   t   extrat   max_numt	   can_orderR   (   R   R   RG   (   RG   R*   RI   t   formsetR   R   R   R   R!   R,   t   FormSet(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   modelformset_factory  s    		t   BaseInlineFormSetc           B   sn   e  Z d  Z d d d e d d d  Z d   Z d   Z d   Z e	 e  Z e
 d  Z d   Z d   Z RS(	   s0   A formset for child objects related to a parent.c   	      C   s   d d k  l } | d  j o |  i i i   |  _ n
 | |  _ | |  _ | |  i i i |  i |  i  i	   |  _
 | d  j o |  i i } n | i h |  i |  i i 6  } t t |   i | | d | d | d  S(   Ni(   t   RelatedObjectRu   R   (   R<   R   R&   t   fkR   R   R+   t   save_as_newRG   t   get_accessor_namet   rel_nameR   t   filterR%   R\   R   RR   (	   RP   R?   Rs   R+   R  Ru   R   R   R   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyRR     s    		*c         C   s"   |  i  o d St t |   i   S(   Ni    (   R  R\   R   R   (   RP   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s    
c         K   s   t  t |   i | |  } |  i o< d  | i | i |  i i  <d  | i | i |  i	 i  <n t
 | i |  i	 i   |  i i  | S(   N(   R\   R   R   R  R&   R?   R   R   R%   R   t   setattrR+   t   get_attnameR=   (   RP   R   RL   R*   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s    
 "c         C   sA   d d k  l } | |  i i i |  i |  i  i   i d d  S(   Ni(   R   t   +t    (   R<   R   R   R   R   RG   R  t   replace(   Re   R   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   get_default_prefix  s    c         C   s   | i  d t  } t |  i |  i i i  } t | |  i i   t | d |   | o | i    n | o t	 | d  o | i
   n | S(   NR9   R=   R3   (   R7   R[   RO   R+   R   R   R   R  R  R   R3   (   RP   R*   R9   RA   R   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s    %c         C   s>  t  t |   i | |  |  i |  i j o |  i i } h t d 6} n} |  i i } h t | i i	 |  d t
 |  i i   d 6} |  i i i |  i i i i i i j o |  i i i | d <n t |  i |  | i | <| i i oO t | i i t  o t | i i  | i _ n | i i i |  i i  n d  S(   NR   t   labelt   to_field(   R\   R   R   R   R   R%   R   RO   R!   RF   R   t   verbose_nameR   R   R   R   R=   R   R+   R#   R   R   R(   (   RP   R*   R   R%   RL   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s    .(c         C   sN   g  } | D]$ } | |  i  i j o | | q q ~ } t t |   i |  S(   N(   R   R%   R\   R   R   (   RP   R   R@   R   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s    8N(   RS   RT   R   R&   R[   RR   R   R   R
  t   classmethodR   R   R   R   (    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s   					c         C   s  d d k  l } | i } | o g  } | i D]! } | i | j o | | q. q. ~ } t |  d j oh | d }	 t |	 |  p/ |	 i i |  j o6 |	 i i |  i i	   j o t
 d | |  f   q qt |  d j o t
 d | | f   qn g  }
 | i D]P } t | |  o: | i i |  j p | i i |  i i	   j o |
 | qq~
 } t |  d j o | d }	 nP t |  d j o& | o d St
 d | |  f   n t
 d	 | |  f   |	 S(
   sH  
    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   i    s&   fk_name '%s' is not a ForeignKey to %ss   %s has no field named '%s'Ns   %s has no ForeignKey to %ss#   %s has more than 1 ForeignKey to %s(   R   R   R   R!   R%   R   R#   R   R   t   get_parent_listt	   Exception(   t   parent_modelRG   t   fk_namet   can_failR   R-   R@   R/   t   fks_to_parentR   Rk   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   _get_foreign_key  s0    		8
0i   c         C   s   t  |  | d | } | i o
 d }
 n h	 | d 6| d 6| d 6| d 6|	 d 6| d 6| d	 6| d
 6|
 d 6} t | |  } | | _ | S(   s   
    Returns an ``InlineFormSet`` for the given kwargs.

    You must provide ``fk_name`` if ``model`` has more than one ``ForeignKey``
    to ``parent_model``.
    R  i   R*   RI   R   R   R   R   R!   R,   R   (   R  t   uniqueR   R   (   R  RG   R*   R   R  R!   R,   R   R   R   R   RI   R   RL   R   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   inlineformset_factory  s     


	t   InlineForeignKeyHiddenInputc           B   s   e  Z d    Z RS(   c         C   s   t  S(   N(   R[   (   RP   Rv   R?   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   _has_changed:  s    (   RS   RT   R  (    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR  9  s   R   c           B   s3   e  Z d  Z h e d  d 6Z d   Z d   Z RS(   sw   
    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.t   invalid_choicec         O   s   | |  _  | i d t  |  _ | i d d   |  _ |  i  d  j	 o; |  i o t |  i  |  i  | d <q~ |  i  i | d <n t | d <t | d <t	 t
 |   i | |   d  S(   NR   R  Rv   R   RB   (   t   parent_instanceRX   R[   R   R&   R  RO   R=   R  R\   R   RR   (   RP   R  t   argsRL   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyRR   F  s    	


c         C   s   | t  j o |  i o d  S|  i S|  i o t |  i |  i  } n |  i i } t |  t |  j o t |  i	 d   n |  i S(   NR  (
   R
   R   R&   R  R  RO   R=   R   R   t   error_messages(   RP   t   valuet   orig(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   S  s    

(   RS   RT   R   R   t   default_error_messagesRR   R   (    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   =  s
   	t   ModelChoiceIteratorc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   | |  _  | i |  _ d  S(   N(   R   R   (   RP   R   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyRR   c  s    	c         c   s   |  i  i d  j	 o d |  i  i f Vn |  i  i op |  i  i d  j o= g  } |  i i   D] } | |  i |  q\ ~ |  i  _ n xE |  i  i D] } | Vq Wn) x% |  i i   D] } |  i |  Vq Wd  S(   Nu    (   R   t   empty_labelR&   t   cache_choicest   choice_cacheR   t   allt   choice(   RP   R@   RA   R&  (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   __iter__g  s    =  c         C   s   t  |  i  S(   N(   R   R   (   RP   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   __len__u  s    c         C   s"   |  i  i |  |  i  i |  f S(   N(   R   t   prepare_valuet   label_from_instance(   RP   RA   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR&  x  s    (   RS   RT   RR   R'  R(  R&  (    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR!  b  s   			c        	   B   s   e  Z d  Z h 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 i  Z d
   Z d   Z d   Z RS(   s1   A ChoiceField whose choices are a model QuerySet.uG   Select a valid choice. That choice is not one of the available choices.R  u	   ---------c
      	   O   st   | o | d  j	 o d  |  _ n
 | |  _ | |  _ t i |  | | | | | |
 |  | |  _ d  |  _ |	 |  _ d  S(   N(   R&   R"  R#  R   RR   R   R$  t   to_field_name(   RP   R   R"  R#  R   RB   R  Rv   t	   help_textR+  R  RL   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyRR     s    		
		c         C   s(   t  t |   i |  } | i | _ | S(   N(   R\   R   t   __deepcopy__R   (   RP   t   memot   result(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR-    s    c         C   s   |  i  S(   N(   R   (   RP   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   _get_queryset  s    c         C   s   | |  _  |  i |  i _ d  S(   N(   R   t   choicesRB   (   RP   R   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   _set_queryset  s    	c         C   s
   t  |  S(   s   
        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   RA   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR*    s    c         C   s"   t  |  d  o |  i St |   S(   Nt   _choices(   R   R3  R!  (   RP   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   _get_choices  s    	c         C   sL   t  | d  o& |  i o | i |  i  S| i Sn t t |   i |  S(   NR   (   R   R+  t   serializable_valueR=   R\   R   R)  (   RP   R  (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR)    s
    
c         C   s{   | t  j o d  Sy- |  i p d } |  i i h | | 6  } Wn5 t |  i i i f j
 o t |  i	 d   n X| S(   NR=   R  (
   R
   R&   R+  R   RF   R5   RG   t   DoesNotExistR   R  (   RP   R  t   key(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt	   to_python  s    c         C   s   t  i |  |  S(   N(   R   t   validate(   RP   R  (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR9    s    N(   RS   RT   R   R   R   R[   R   R&   RR   R-  R0  R2  t   propertyR   R*  R4  R   t   _set_choicesR1  R)  R8  R9  (    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR   {  s    							
c           B   st   e  Z d  Z e Z e Z h e d  d 6e d  d 6e d  d 6Z e	 e
 d
 d
 d
 d
 d  Z d   Z d	   Z RS(   s9   A MultipleChoiceField whose choices are a model QuerySet.u   Enter a list of values.R   u>   Select a valid choice. %s is not one of the available choices.R  u,   "%s" is not a valid value for a primary key.t   invalid_pk_valuec   
      O   s5   t  t |   i | d  | | | | | | | |	  d  S(   N(   R\   R   RR   R&   (
   RP   R   R#  R   RB   R  Rv   R,  R  RL   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyRR     s    c   	   
   C   sz  |  i  o | o t |  i d   n |  i  o | o g  St | t t f  p t |  i d   n |  i p d } xV | D]N } y |  i i h | | 6  Wq t	 j
 o t |  i d |   q Xq W|  i i h | d | 6  } t
 g  } | D] } | t t | |   q~  } x< | D]4 } t |  | j o t |  i d |   q1q1W|  i |  | S(   NR   R   R=   R<  s   %s__inR  (   R   R   R  R#   R   R   R+  R   R  R5   R_   R   RO   t   run_validators(	   RP   R  R7  R=   R   R@   R   t   pkst   val(    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s*      6 c         C   sX   t  | d  o2 g  } | D] } | t t |   i |  q ~ St t |   i |  S(   NR'  (   R   R\   R   R)  (   RP   R  R@   Rm   (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR)    s    2N(   RS   RT   R   R   RB   R   t   hidden_widgetR   R   R[   R   R&   RR   R   R)  (    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyR     s   		N(   s	   ModelForms   BaseModelForms   model_to_dicts   fields_for_models   save_instances   ModelChoiceFields   ModelMultipleChoiceField(<   R   t   django.utils.encodingR    R   t   django.utils.datastructuresR   t   django.utils.textR   R   t   django.utils.translationR   R   R   t   django.core.exceptionsR   R   R	   t   django.core.validatorsR
   t   utilR   R   R   R   R!   R   R   RH   R   R   R   R   t   formsetsR   R   t   __all__R&   R0   R   R   R   R   R   RN   R   RU   R   R   R   R   R[   R   R   R  R  R  R   R!  R   R   (    (    (    s=   /usr/local/lib/python2.6/dist-packages/django/forms/models.pyt   <module>   sT    &$-'	!	V(%Y