ó
®â0_c        	   @  s  d  d l  m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d l	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z d  d l m Z d  d l m Z d  d l m Z m Z d d d f Z d Z d Z d Z  d Z! d Z" d Z# d Z$ d Z% d e f d „  ƒ  YZ& e e d e' f d „  ƒ  Yƒ ƒ Z( e( d e) e) e* e) e* e) d „ Z+ d „  Z, d  S(!   iÿÿÿÿ(   t   unicode_literals(   t   ValidationError(   t   Form(   t   BooleanFieldt   IntegerField(   t	   ErrorList(   t   HiddenInput(   t   six(   t   python_2_unicode_compatible(   t   cached_property(   t	   html_safe(   t	   mark_safe(   t   range(   t   ugettextt	   ungettextu   BaseFormSetu   formset_factoryu	   all_validu   TOTAL_FORMSu   INITIAL_FORMSu   MIN_NUM_FORMSu   MAX_NUM_FORMSu   ORDERu   DELETEi    iè  t   ManagementFormc           B  s   e  Z d  Z d „  Z RS(   uÏ   
    ``ManagementForm`` is used to keep track of how many form instances
    are displayed on the page. If adding new forms via javascript, you should
    increment the count field of this form as well.
    c         O  s   t  d t ƒ |  j t <t  d t ƒ |  j t <t  d t d t ƒ |  j t <t  d t d t ƒ |  j t <t t	 |  ƒ j
 | | Ž  d  S(   Nt   widgett   required(   R   R   t   base_fieldst   TOTAL_FORM_COUNTt   INITIAL_FORM_COUNTt   Falset   MIN_NUM_FORM_COUNTt   MAX_NUM_FORM_COUNTt   superR   t   __init__(   t   selft   argst   kwargs(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR   '   s
    (   t   __name__t
   __module__t   __doc__R   (    (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR   !   s   t   BaseFormSetc           B  s   e  Z d  Z d% d% d d% d% e d% d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z e d	 „  ƒ Z d
 „  Z d „  Z e d „  ƒ Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% d  „  Z& e d! „  ƒ Z' d" „  Z( d# „  Z) d$ „  Z* RS(&   u;   
    A collection of instances of the same Form class.
    u   id_%sc         C  sŽ   | d  k	 p | d  k	 |  _ | p* |  j ƒ  |  _ | |  _ | pB i  |  _ | pQ i  |  _ | |  _ | pi i  |  _ | |  _	 d  |  _
 d  |  _ d  S(   N(   t   Nonet   is_boundt   get_default_prefixt   prefixt   auto_idt   datat   filest   initialt   form_kwargst   error_classt   _errorst   _non_form_errors(   R   R&   R'   R%   R$   R(   R*   R)   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR   8   s    				c         C  s
   |  j  ƒ  S(   N(   t   as_table(   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   __str__E   s    c         C  s   t  |  j ƒ S(   u5   Yields the forms in the order they should be rendered(   t   itert   forms(   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   __iter__H   s    c         C  s   |  j  | S(   uA   Returns the form at the given index, based on the rendering order(   R0   (   R   t   index(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   __getitem__L   s    c         C  s   t  |  j ƒ S(   N(   t   lenR0   (   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   __len__P   s    c         C  s   t  S(   uG   All formsets have a management form which is not included in the length(   t   True(   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   __bool__S   s    c         C  s   t  |  ƒ j |  ƒ S(   N(   t   typeR7   (   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   __nonzero__W   s    c      	   C  s§   |  j  rT t |  j d |  j d |  j ƒ} | j ƒ  s£ t t d ƒ d d ƒ‚ q£ nO t d |  j d |  j d i |  j ƒ  t	 6|  j
 ƒ  t 6|  j t 6|  j t 6ƒ } | S(   u5   Returns the ManagementForm instance for this FormSet.R%   R$   u8   ManagementForm data is missing or has been tampered witht   codeu   missing_management_formR(   (   R"   R   R&   R%   R$   t   is_validR   t   _t   total_form_countR   t   initial_form_countR   t   min_numR   t   max_numR   (   R   t   form(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   management_formZ   s    	!
c         C  sŸ   |  j  r# t |  j j t |  j ƒ S|  j ƒ  } t | |  j ƒ |  j	 } | |  j
 k ob d k n rp | } n+ | |  j
 k oŠ d k n r› |  j
 } n  | S(   u2   Returns the total number of forms in this FormSet.i    (   R"   t   minRB   t   cleaned_dataR   t   absolute_maxR>   t   maxR?   t   extraR@   (   R   t   initial_formst   total_forms(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR=   m   s    		c         C  s9   |  j  r |  j j t S|  j r/ t |  j ƒ n d } | S(   u>   Returns the number of forms that are required in this FormSet.i    (   R"   RB   RD   R   R(   R4   (   R   RH   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR>   €   s    	c         C  s>   g  t  |  j ƒ  ƒ D]! } |  j | |  j | ƒ  ^ q } | S(   u=   
        Instantiate forms at first property access.
        (   R   R=   t   _construct_formt   get_form_kwargs(   R   t   iR0   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR0   ‰   s    7c         C  s   |  j  j ƒ  S(   u®   
        Return additional keyword arguments for each individual formset form.

        index will be None if the form being constructed is a new empty
        form.
        (   R)   t   copy(   R   R2   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyRK   “   s    c         K  sö   i |  j  d 6|  j | ƒ d 6|  j d 6t d 6} |  j rW |  j | d <|  j | d <n  |  j r˜ d | k r˜ y |  j | | d <Wq˜ t k
 r” q˜ Xn  | |  j	 ƒ  k rÆ | |  j
 k rÆ t | d <n  | j | ƒ |  j |   } |  j | | ƒ | S(	   uO   
        Instantiates and returns the i-th form instance in a formset.
        u   auto_idu   prefixu   error_classu   use_required_attributeu   datau   filesu   initialu   empty_permitted(   R%   t
   add_prefixR*   R   R"   R&   R'   R(   t
   IndexErrorR>   R?   R6   t   updateRA   t
   add_fields(   R   RL   R   t   defaultsRA   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyRJ   œ   s&    


	!c         C  s   |  j  |  j ƒ   S(   u7   Return a list of all the initial forms in this formset.(   R0   R>   (   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyRH   º   s    c         C  s   |  j  |  j ƒ  S(   u5   Return a list of all the extra forms in this formset.(   R0   R>   (   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   extra_forms¿   s    c         C  sP   |  j  d |  j d |  j d ƒ d t d t |  j d  ƒ  } |  j | d  ƒ | S(   NR%   R$   u
   __prefix__t   empty_permittedt   use_required_attribute(   RA   R%   RN   R6   R   RK   R!   RQ   (   R   RA   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt
   empty_formÄ   s    		c         C  sB   |  j  ƒ  s% t d |  j j ƒ ‚ n  g  |  j D] } | j ^ q/ S(   uY   
        Returns a list of form.cleaned_data dicts for every form in self.forms.
        u+   '%s' object has no attribute 'cleaned_data'(   R;   t   AttributeErrort	   __class__R   R0   RD   (   R   RA   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyRD   Ð   s    c         C  sË   |  j  ƒ  s |  j r g  St |  d ƒ sª g  |  _ xt t d |  j ƒ  ƒ D]Z } |  j | } | |  j ƒ  k r | j ƒ  r qI n  |  j	 | ƒ rI |  j j
 | ƒ qI qI Wn  g  |  j D] } |  j | ^ q´ S(   uM   
        Returns a list of forms that have been marked for deletion.
        u   _deleted_form_indexesi    (   R;   t
   can_deletet   hasattrt   _deleted_form_indexesR   R=   R0   R>   t   has_changedt   _should_delete_formt   append(   R   RL   RA   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   deleted_formsÙ   s    	c         C  s  |  j  ƒ  s |  j r0 t d |  j j ƒ ‚ n  t |  d ƒ sô g  |  _ xŠ t d |  j ƒ  ƒ D]s } |  j	 | } | |  j
 ƒ  k r– | j ƒ  r– q^ n  |  j r´ |  j | ƒ r´ q^ n  |  j j | | j t f ƒ q^ Wd „  } |  j j d | ƒ n  g  |  j D] } |  j	 | d ^ qþ S(   u’   
        Returns a list of form in the order specified by the incoming data.
        Raises an AttributeError if ordering is not allowed.
        u,   '%s' object has no attribute 'ordered_forms'u	   _orderingi    c         S  s"   |  d d  k r d Sd |  d f S(   Ni   i    (   i   i    (   R!   (   t   k(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   compare_ordering_key
  s    t   key(   R;   t	   can_orderRW   RX   R   RZ   t	   _orderingR   R=   R0   R>   R\   RY   R]   R^   RD   t   ORDERING_FIELD_NAMEt   sort(   R   RL   RA   Ra   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   ordered_formsí   s    	!	c         C  s   d S(   Nu   form(    (   t   cls(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR#     s    c         C  s#   |  j  d k r |  j ƒ  n  |  j  S(   u»   
        Returns an ErrorList of errors that aren't associated with a particular
        form -- i.e., from formset.clean(). Returns an empty ErrorList if there
        are none.
        N(   R,   R!   t
   full_clean(   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   non_form_errors  s    c         C  s#   |  j  d k r |  j ƒ  n  |  j  S(   uM   
        Returns a list of form.errors for every form in self.forms.
        N(   R+   R!   Ri   (   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   errors!  s    c         C  s'   t  |  j ƒ  ƒ t d „  |  j Dƒ ƒ S(   uO   
        Returns the number of errors across all forms in the formset.
        c         s  s   |  ] } t  | ƒ Vq d  S(   N(   R4   (   t   .0t   form_errors(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pys	   <genexpr>/  s    (   R4   Rj   t   sumRk   (   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   total_error_count*  s    c         C  s   | j  j t t ƒ S(   uJ   
        Returns whether or not the form was marked for deletion.
        (   RD   t   gett   DELETION_FIELD_NAMER   (   R   RA   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR]   1  s    c         C  s‰   |  j  s t St } |  j x[ t d |  j ƒ  ƒ D]D } |  j | } |  j rd |  j | ƒ rd q0 qd n  | | j	 ƒ  M} q0 W| oˆ |  j
 ƒ  S(   uD   
        Returns True if every form in self.forms is valid.
        i    (   R"   R   R6   Rk   R   R=   R0   RY   R]   R;   Rj   (   R   t   forms_validRL   RA   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR;   7  s    			c         C  s  g  |  _  |  j ƒ  |  _ d } |  j s+ d Sxi t d |  j ƒ  ƒ D]R } |  j | } | j ƒ  r€ | |  j ƒ  k r€ | d 7} n  |  j  j	 | j
 ƒ qA Wy× |  j rÅ |  j ƒ  t |  j ƒ |  j k sÞ |  j j t |  j k r	t t d d |  j ƒ |  j d d ƒ‚ n  |  j rc|  j ƒ  t |  j ƒ | |  j k  rct t d d |  j ƒ |  j d d ƒ‚ n  |  j ƒ  Wn( t k
 r˜} |  j | j ƒ |  _ n Xd S(	   ug   
        Cleans all of self.data and populates self._errors and
        self._non_form_errors.
        i    Ni   u    Please submit %d or fewer forms.R:   u   too_many_formsu   Please submit %d or more forms.u   too_few_forms(   R+   R*   R,   R"   R   R=   R0   R\   R>   R^   Rk   t   validate_maxR4   R_   R@   RB   RD   R   RE   R   R   t   validate_minR?   t   cleant
   error_list(   R   t   empty_forms_countRL   RA   t   e(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyRi   L  s6    			"	&c         C  s   d S(   u  
        Hook for doing any extra formset-wide cleaning after Form.clean() has
        been called on every form. Any ValidationError raised by this method
        will not be associated with a particular form; it will be accessible
        via formset.non_form_errors()
        N(    (   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyRu   r  s    c         C  s   t  d „  |  Dƒ ƒ S(   uH   
        Returns true if data in any form differs from initial.
        c         s  s   |  ] } | j  ƒ  Vq d  S(   N(   R\   (   Rl   RA   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pys	   <genexpr>  s    (   t   any(   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR\   {  s    c         C  s­   |  j  r{ | d k	 rV | |  j ƒ  k  rV t d t d ƒ d | d d t ƒ | j t <q{ t d t d ƒ d t ƒ | j t <n  |  j r© t	 d t d ƒ d t ƒ | j t
 <n  d S(   u8   A hook for adding extra fields on to each form instance.t   labelu   OrderR(   i   R   u   DeleteN(   Rc   R!   R>   R   R<   R   t   fieldsRe   RY   R   Rq   (   R   RA   R2   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyRQ     s    	/%	c         C  s   d |  j  | f S(   Nu   %s-%s(   R$   (   R   R2   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyRN   Œ  s    c         C  s+   |  j  r |  j  d j ƒ  S|  j j ƒ  Sd S(   uu   
        Returns True if the formset needs to be multipart, i.e. it
        has FileInput. Otherwise, False.
        i    N(   R0   t   is_multipartRV   (   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR|     s    	c         C  s%   |  j  r |  j  d j S|  j j Sd  S(   Ni    (   R0   t   mediaRV   (   R   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR}   ™  s    	c         C  s>   d j  d „  |  Dƒ ƒ } t d j  t j |  j ƒ | g ƒ ƒ S(   uM   Returns this formset rendered as HTML <tr>s -- excluding the <table></table>.u    c         s  s   |  ] } | j  ƒ  Vq d  S(   N(   R-   (   Rl   RA   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pys	   <genexpr>§  s    u   
(   t   joinR   R   t	   text_typeRB   (   R   R0   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR-   ¢  s    c         C  s>   d j  d „  |  Dƒ ƒ } t d j  t j |  j ƒ | g ƒ ƒ S(   u+   Returns this formset rendered as HTML <p>s.u    c         s  s   |  ] } | j  ƒ  Vq d  S(   N(   t   as_p(   Rl   RA   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pys	   <genexpr>¬  s    u   
(   R~   R   R   R   RB   (   R   R0   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR€   ª  s    c         C  s>   d j  d „  |  Dƒ ƒ } t d j  t j |  j ƒ | g ƒ ƒ S(   u,   Returns this formset rendered as HTML <li>s.u    c         s  s   |  ] } | j  ƒ  Vq d  S(   N(   t   as_ul(   Rl   RA   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pys	   <genexpr>±  s    u   
(   R~   R   R   R   RB   (   R   R0   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR   ¯  s    N(+   R   R   R   R!   R   R   R.   R1   R3   R5   R7   R9   R	   RB   R=   R>   R0   RK   RJ   t   propertyRH   RS   RV   RD   R_   Rg   t   classmethodR#   Rj   Rk   Ro   R]   R;   Ri   Ru   R\   RQ   RN   R|   R}   R-   R€   R   (    (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyR    2   sJ   									
				&	
					&						
			i   c	         C  s™   | d k r t } n  | d k r* t } n  | t }	 i	 |  d 6| d 6| d 6| d 6| d 6| d 6|	 d 6| d 6| d	 6}
 t |  j t d
 ƒ | f |
 ƒ S(   u*   Return a FormSet for the given form class.u   formu   extrau	   can_orderu
   can_deleteu   min_numu   max_numu   absolute_maxu   validate_minu   validate_maxu   FormSetN(   R!   t   DEFAULT_MIN_NUMt   DEFAULT_MAX_NUMR8   R   t   str(   RA   t   formsetRG   Rc   RY   R@   Rs   R?   Rt   RE   t   attrs(    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   formset_factoryµ  s    		

c         C  s0   t  } x# |  D] } | j ƒ  s t } q q W| S(   u3   Returns true if every formset in formsets is valid.(   R6   R;   R   (   t   formsetst   validR‡   (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt	   all_validÉ  s
    N(-   t
   __future__R    t   django.core.exceptionsR   t   django.formsR   t   django.forms.fieldsR   R   t   django.forms.utilsR   t   django.forms.widgetsR   t   django.utilsR   t   django.utils.encodingR   t   django.utils.functionalR	   t   django.utils.htmlR
   t   django.utils.safestringR   t   django.utils.six.movesR   t   django.utils.translationR   R<   R   t   __all__R   R   R   R   Re   Rq   R„   R…   R   t   objectR    R   R!   R‰   RŒ   (    (    (    s7   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/formsets.pyt   <module>   s<   ÿ ‚		