ó
®ā0_c           @  s  d  Z  d d l m Z d d l Z d d l m Z d d l m Z m Z d d l	 m
 Z
 d d l m Z m Z d d l m Z m Z m Z d d	 l m Z m Z d d
 l m Z d d l m Z 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 f Z& d e f d     YZ' e e d e( f d     Y  Z) d e j* e' e)  f d     YZ+ d S(   u   
Form classes
i’’’’(   t   unicode_literalsN(   t   OrderedDict(   t   NON_FIELD_ERRORSt   ValidationError(   t
   BoundField(   t   Fieldt	   FileField(   t	   ErrorDictt	   ErrorListt   pretty_name(   t   Mediat   MediaDefiningClass(   t   six(   t
   force_textt   python_2_unicode_compatible(   t   cached_property(   t   conditional_escapet	   html_safe(   t	   mark_safe(   t   ugettexti   (   t   get_default_rendereru   BaseFormu   Formt   DeclarativeFieldsMetaclassc           B  s   e  Z d  Z d   Z RS(   uF   
    Metaclass that collects Fields declared on the base classes.
    c         C  sB  g  } xR t  | j    D]> \ } } t | t  r | j | | f  | j |  q q W| j d d    t |  | d <t t	 |   j
 |  | | |  } t   } x t | j  D]p }	 t |	 d  rą | j |	 j  n  xE |	 j j   D]4 \ }
 } | d  k rš |
 | k rš | j |
  qš qš Wqø W| | _ | | _ | S(   Nt   keyc         S  s   |  d j  S(   Ni   (   t   creation_counter(   t   x(    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   <lambda>(   t    u   declared_fields(   t   listt   itemst
   isinstanceR   t   appendt   popt   sortR   t   superR   t   __new__t   reversedt   __mro__t   hasattrt   updatet   declared_fieldst   __dict__t   Nonet   base_fields(   t   mcst   namet   basest   attrst   current_fieldsR   t   valuet	   new_classR'   t   baset   attr(    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR"   !   s$    !			(   t   __name__t
   __module__t   __doc__R"   (    (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR      s   t   BaseFormc           B  s[  e  Z d Z d Z d Z e Z d d d  d d e d e	 d d d d  Z
 d   Z d   Z d   Z 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 d d  Z d   Z d   Z d   Z d   Z d   Z  d   Z! e" d    Z# e d    Z$ d   Z% d   Z& d   Z' d   Z( RS(   u   id_%sc         C  s[  | d  k	 p | d  k	 |  _ | p$ i  |  _ | p3 i  |  _ | |  _ | d  k	 rZ | |  _ n  | pc i  |  _ | |  _ | d  k	 r | n	 t d  |  _	 | |  _
 d  |  _ t j |  j  |  _ i  |  _ |  j |	 d  k rŽ |  j n |	  |
 d  k	 rż |
 |  _ n  | d  k rN|  j d  k r$t   } qN|  j } t |  j t  rN|   } qNn  | |  _ d  S(   Nu   :(   R)   t   is_boundt   datat   filest   auto_idt   prefixt   initialt   error_classt   _t   label_suffixt   empty_permittedt   _errorst   copyt   deepcopyR*   t   fieldst   _bound_fields_cachet   order_fieldst   field_ordert   use_required_attributet   default_rendererR   R   t   typet   renderer(   t   selfR9   R:   R;   R<   R=   R>   R@   RA   RH   RI   RL   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   __init__K   s.    		!			"	c         C  su   | d k r d St   } x< | D]4 } y |  j j |  | | <Wq  t k
 rS q  Xq  W| j |  j  | |  _ d S(   uł  
        Rearranges the fields according to field_order.

        field_order is a list of field names specifying the order. Fields not
        included in the list are appended in the default order for backward
        compatibility with subclasses not overriding field_order. If field_order
        is None, all fields are kept in the order defined in the class.
        Unknown fields in field_order are ignored to allow disabling fields in
        form subclasses without redefining ordering.
        N(   R)   R   RE   R   t   KeyErrorR&   (   RM   RH   RE   R   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyRG   r   s    	c         C  s
   |  j    S(   N(   t   as_table(   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   __str__   s    c         C  sj   |  j  d  k r d } n |  j o. t |  j   } d i |  j j d 6|  j d 6| d 6d j |  j  d 6S(   Nu   Unknownu?   <%(cls)s bound=%(bound)s, valid=%(valid)s, fields=(%(fields)s)>u   clsu   boundu   validu   ;u   fields(   RB   R)   R8   t   boolt	   __class__R4   t   joinRE   (   RM   t   is_valid(    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   __repr__   s    	
c         c  s!   x |  j  D] } |  | Vq
 Wd  S(   N(   RE   (   RM   R,   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   __iter__   s    c         C  s   y |  j  | } WnL t k
 r_ t d | |  j j d j t d   |  j  D   f   n X| |  j k r | j |  |  |  j | <n  |  j | S(   u)   Returns a BoundField with the given name.u,   Key '%s' not found in '%s'. Choices are: %s.u   , c         s  s   |  ] } | Vq d  S(   N(    (   t   .0t   f(    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pys	   <genexpr>¤   s    (   RE   RO   RS   R4   RT   t   sortedRF   t   get_bound_field(   RM   R,   t   field(    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   __getitem__   s    	-c         C  s#   |  j  d k r |  j   n  |  j  S(   u7   Returns an ErrorDict for the data provided for the formN(   RB   R)   t
   full_clean(   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   errors«   s    c         C  s   |  j  o |  j S(   u   
        Returns True if the form has no errors. Otherwise, False. If errors are
        being ignored, returns False.
        (   R8   R_   (   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyRU   ²   s    c         C  s   |  j  r d |  j  | f S| S(   u   
        Returns the field name with a prefix appended, if this Form has a
        prefix set.

        Subclasses may wish to override.
        u   %s-%s(   R<   (   RM   t
   field_name(    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt
   add_prefix¹   s    c         C  s   d |  j  |  S(   uL   
        Add a 'initial' prefix for checking dynamic initial values
        u
   initial-%s(   Ra   (   RM   R`   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   add_initial_prefixĀ   s    c         C  sĀ  |  j    } g  g  } } xĮ|  j j   D]°\ }	 }
 d } |  |	 } |  j g  | j D] } t |  ^ qU  } | j rŁ | rĄ | j g  | D]* } t d  i |	 d 6t	 |  d 6^ q  n  | j
 t j |   q) | j   } | rų d | } n  | r| r| j
 | t	 |   n  | j rTt t	 | j   } | j |  pNd } n d } |
 j ry| t	 |
 j  } n d } | j
 | i t	 |  d 6t	 |  d 6t j |  d 6| d	 6| d
 6| d 6| j d 6 q) W| r | j d | t	 |   n  | rÆd j |  } | r| d } | j |  s| i d d 6d d 6d d 6d d	 6| d
 6d d 6d d 6} | j
 |  n  | t |   | | | d <qÆ| j
 |  n  t d j |   S(   uI   Helper function for outputting HTML. Used by as_table(), as_ul(), as_p().u    u!   (Hidden field %(name)s) %(error)su   nameu   erroru    class="%s"u   errorsu   labelu   fieldu	   help_textu   html_class_attru   css_classesu
   field_namei    i’’’’u   
(   t   non_field_errorsRE   R   R>   R_   R   t	   is_hiddent   extendR?   R   R   R   t	   text_typet   css_classest   labelt	   label_tagt	   help_textt	   html_namet   insertRT   t   endswitht   lenR   (   RM   t
   normal_rowt	   error_rowt	   row_endert   help_text_htmlt   errors_on_separate_rowt
   top_errorst   outputt   hidden_fieldsR,   R\   t   html_class_attrt   bft   errort	   bf_errorst   eRg   Rh   Rj   t
   str_hiddent   last_row(    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   _html_outputČ   sf    
+	8		
 c         C  s(   |  j  d d d d d d d d d	 t  S(
   uJ   Returns this form rendered as HTML <tr>s -- excluding the <table></table>.Ro   uW   <tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>Rp   u    <tr><td colspan="2">%s</td></tr>Rq   u
   </td></tr>Rr   u&   <br /><span class="helptext">%s</span>Rs   (   R~   t   False(   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyRP     s    	c         C  s(   |  j  d d d d d d d d d	 t  S(
   uD   Returns this form rendered as HTML <li>s -- excluding the <ul></ul>.Ro   uF   <li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>Rp   u   <li>%s</li>Rq   u   </li>Rr   u!    <span class="helptext">%s</span>Rs   (   R~   R   (   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   as_ul  s    	c         C  s(   |  j  d d d d d d d d d	 t  S(
   u(   Returns this form rendered as HTML <p>s.Ro   u:   <p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>Rp   u   %sRq   u   </p>Rr   u!    <span class="helptext">%s</span>Rs   (   R~   t   True(   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   as_p(  s    	c         C  s   |  j  j t |  j d d   S(   u¹   
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        R>   u   nonfield(   R_   t   getR   R>   (   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyRc   1  s    c         C  sB  t  | t  s t |  } n  t | d  rT | d k	 rH t d   qj | j } n i | j | pf t 6} xŃ | j   D]Ć \ } } | |  j	 k r
| t k rĢ | |  j
 k rĢ t d |  j j | f   n  | t k rō |  j d d  |  j | <q
|  j   |  j | <n  |  j | j |  | |  j k rw |  j | =qw qw Wd S(   u^  
        Update the content of `self._errors`.

        The `field` argument is the name of the field to which the errors
        should be added. If its value is None the errors will be treated as
        NON_FIELD_ERRORS.

        The `error` argument can be a single error, a list of errors, or a
        dictionary that maps field names to lists of errors. What we define as
        an "error" can be either a simple string or an instance of
        ValidationError with its message attribute set and what we define as
        list or dictionary can be an actual `list` or `dict` or an instance
        of ValidationError with its `error_list` or `error_dict` attribute set.

        If `error` is a dictionary, the `field` argument *must* be None and
        errors will be added to the fields that correspond to the keys of the
        dictionary.
        u
   error_dictub   The argument `field` must be `None` when the `error` argument contains errors for multiple fields.u   '%s' has no field named '%s'.R>   u   nonfieldN(   R   R   R%   R)   t	   TypeErrort
   error_dictt
   error_listR   R   R_   RE   t
   ValueErrorRS   R4   R>   RB   Re   t   cleaned_data(   RM   R\   Ry   R   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt	   add_error9  s&    c         C  s`   | d  k r | |  j k S| |  j k r\ x1 |  j j   | D] } | j | k r< t Sq< Wn  t S(   N(   R)   R_   t   as_datat   codeR   R   (   RM   R\   R   Ry   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt	   has_errori  s    c         C  s^   t    |  _ |  j s d Si  |  _ |  j r< |  j   r< d S|  j   |  j   |  j   d S(   uc   
        Cleans all of self.data and populates self._errors and
        self.cleaned_data.
        N(	   R   RB   R8   R   RA   t   has_changedt   _clean_fieldst   _clean_formt   _post_clean(   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR^   r  s    		

c         C  s  x|  j  j   D]\ } } | j r: |  j | |  } n' | j j |  j |  j |  j |   } y t	 | t
  r |  j | |  } | j | |  } n | j |  } | |  j | <t |  d |  rļ t |  d |    } | |  j | <n  Wq t k
 r} |  j | |  q Xq Wd  S(   Nu   clean_%s(   RE   R   t   disabledt   get_initial_for_fieldt   widgett   value_from_datadictR9   R:   Ra   R   R   t   cleanR   R%   t   getattrR   R   (   RM   R,   R\   R0   R=   R{   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR     s    	'c         C  sR   y |  j    } Wn# t k
 r5 } |  j d  |  n X| d  k	 rN | |  _ n  d  S(   N(   R   R   R   R)   R   (   RM   R   R{   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR     s    c         C  s   d S(   u   
        An internal hook for performing additional cleaning after form cleaning
        is complete. Used for model validation in model forms.
        N(    (   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR   £  s    c         C  s   |  j  S(   u+  
        Hook for doing any extra form-wide cleaning after Field.clean() has been
        called on every field. Any ValidationError raised by this method will
        not be associated with a particular field; it will have a special-case
        association with the field named '__all__'.
        (   R   (   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR   Ŗ  s    c         C  s   t  |  j  S(   u<   
        Returns True if data differs from initial.
        (   RR   t   changed_data(   RM   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR   ³  s    c   	      C  sł   g  } xģ |  j  j   D]Ū \ } } |  j |  } | j j |  j |  j |  } | j sh |  | j } ng |  j	 |  } | j
   } y( | j | j |  j |  j |   } Wn! t k
 rĪ | j |  q n X| j | |  r | j |  q q W| S(   N(   RE   R   Ra   R   R   R9   R:   t   show_hidden_initialR=   Rb   t   hidden_widgett	   to_pythonR   R   R   (	   RM   R9   R,   R\   t   prefixed_namet
   data_valuet   initial_valuet   initial_prefixed_nameR   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR   ¹  s"    	c         C  s7   t    } x' |  j j   D] } | | j j } q W| S(   u`   
        Provide a description of all media required to render the widgets on this form
        (   R
   RE   t   valuesR   t   media(   RM   R    R\   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR    Ń  s    	c         C  s.   x' |  j  j   D] } | j j r t Sq Wt S(   uz   
        Returns True if the form needs to be multipart-encoded, i.e. it has
        FileInput. Otherwise, False.
        (   RE   R   R   t   needs_multipart_formR   R   (   RM   R\   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   is_multipartŪ  s    c         C  s    g  |  D] } | j  r | ^ q S(   u   
        Returns a list of all the BoundField objects that are hidden fields.
        Useful for manual form layout in templates.
        (   Rd   (   RM   R\   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyRv   å  s    c         C  s    g  |  D] } | j  s | ^ q S(   u   
        Returns a list of BoundField objects that aren't hidden fields.
        The opposite of the hidden_fields() method.
        (   Rd   (   RM   R\   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   visible_fieldsģ  s    c         C  s4   |  j  j | | j   } t |  r0 |   } n  | S(   u   
        Return initial data for field on form. Use initial data from the form
        or the field, in that order. Evaluate callable values.
        (   R=   R   t   callable(   RM   R\   R`   R0   (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR   ó  s    N()   R4   R5   R)   RJ   RH   R<   R   RI   R   R   RN   RG   RQ   RV   RW   R]   t   propertyR_   RU   Ra   Rb   R~   RP   R   R   Rc   R   R   R^   R   R   R   R   R   R   R   R    R¢   Rv   R£   R   (    (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR7   ?   sF   	%										N								0									
	
		t   Formc           B  s   e  Z d  Z RS(   u3   A collection of Fields, plus their associated data.(   R4   R5   R6   (    (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyR¦   ž  s   (,   R6   t
   __future__R    RC   t   collectionsR   t   django.core.exceptionsR   R   t   django.forms.boundfieldR   t   django.forms.fieldsR   R   t   django.forms.utilsR   R   R	   t   django.forms.widgetsR
   R   t   django.utilsR   t   django.utils.encodingR   R   t   django.utils.functionalR   t   django.utils.htmlR   R   t   django.utils.safestringR   t   django.utils.translationR   R?   t	   renderersR   t   __all__R   t   objectR7   t   with_metaclassR¦   (    (    (    s4   /tmp/pip-unpacked-wheel-BAJOf3/django/forms/forms.pyt   <module>   s,   "’ ¾