ó
ù¢TQc           @@ s‰  d  Z  d d l m Z m Z d d l 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 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 d d l m Z d d f Z  d Z! d „  Z" e# d „ Z$ d e% f d „  ƒ  YZ& e d e' f d „  ƒ  Yƒ Z( d e j) e& e( ƒ f d „  ƒ  YZ* e d e' f d „  ƒ  Yƒ Z+ d S(   u   
Form classes
i    (   t   absolute_importt   unicode_literalsN(   t   ValidationError(   t   Fieldt	   FileField(   t   flatattt	   ErrorDictt	   ErrorList(   t   Mediat   media_propertyt	   TextInputt   Textarea(   t
   SortedDict(   t   conditional_escapet   format_html(   t
   smart_textt
   force_textt   python_2_unicode_compatible(   t	   mark_safe(   t   sixu   BaseFormu   Formu   __all__c         C@ s    |  s
 d S|  j  d d ƒ j ƒ  S(   u%   Converts 'first_name' to 'First name'u    u   _u    (   t   replacet
   capitalize(   t   name(    (    s+   ../Django//lib/python/django/forms/forms.pyt   pretty_name   s    c         C@ s
  g  t  t j | ƒ ƒ D]0 \ } } t | t ƒ r | | j | ƒ f ^ q } | j d d „  ƒ | r´ x˜ |  d d d … D]4 } t | d ƒ ry t  t j | j ƒ ƒ | } qy qy WnL xI |  d d d … D]4 } t | d ƒ rÈ t  t j | j	 ƒ ƒ | } qÈ qÈ Wt
 | ƒ S(   uÏ  
    Create a list of form field instances from the passed in 'attrs', plus any
    similar fields on the base classes (in 'bases'). This is used by both the
    Form and ModelForm metclasses.

    If 'with_base_fields' is True, all fields from the bases are used.
    Otherwise, only fields in the 'declared_fields' attribute on the bases are
    used. The distinction is useful in ModelForm subclassing.
    Also integrates any additional media definitions
    t   keyc         S@ s   |  d j  S(   Ni   (   t   creation_counter(   t   x(    (    s+   ../Django//lib/python/django/forms/forms.pyt   <lambda>*   s    Niÿÿÿÿu   base_fieldsu   declared_fields(   t   listR   t	   iteritemst
   isinstanceR   t   popt   sortt   hasattrt   base_fieldst   declared_fieldsR   (   t   basest   attrst   with_base_fieldst
   field_namet   objt   fieldst   base(    (    s+   ../Django//lib/python/django/forms/forms.pyt   get_declared_fields   s    L&#t   DeclarativeFieldsMetaclassc           B@ s   e  Z d  Z d „  Z RS(   u”   
    Metaclass that converts Field attributes to a dictionary called
    'base_fields', taking into account parent class 'base_fields' as well.
    c         C@ sV   t  | | ƒ | d <t t |  ƒ j |  | | | ƒ } d | k rR t | ƒ | _ n  | S(   Nu   base_fieldsu   media(   R+   t   superR,   t   __new__R	   t   media(   t   clsR   R$   R%   t	   new_class(    (    s+   ../Django//lib/python/django/forms/forms.pyR.   ?   s    (   t   __name__t
   __module__t   __doc__R.   (    (    (    s+   ../Django//lib/python/django/forms/forms.pyR,   :   s   t   BaseFormc        	   B@ s%  e  Z d d d  d d e d e d „ Z d „  Z d „  Z d „  Z d „  Z	 e
 e	 ƒ Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e
 e ƒ Z d „  Z e
 e ƒ Z d „  Z d „  Z  d „  Z! RS(   u   id_%su   :c	   	      C@ s    | d  k	 p | d  k	 |  _ | p$ i  |  _ | p3 i  |  _ | |  _ | |  _ | pT i  |  _ | |  _ | |  _ | |  _	 d  |  _
 d  |  _ t j |  j ƒ |  _ d  S(   N(   t   Nonet   is_boundt   datat   filest   auto_idt   prefixt   initialt   error_classt   label_suffixt   empty_permittedt   _errorst   _changed_datat   copyt   deepcopyR"   R)   (	   t   selfR8   R9   R:   R;   R<   R=   R>   R?   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   __init__M   s    							c         C@ s
   |  j  ƒ  S(   N(   t   as_table(   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   __str__c   s    c         c@ s!   x |  j  D] } |  | Vq
 Wd  S(   N(   R)   (   RD   R   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   __iter__f   s    c         C@ sE   y |  j  | } Wn! t k
 r4 t d | ƒ ‚ n Xt |  | | ƒ S(   u)   Returns a BoundField with the given name.u   Key %r not found in Form(   R)   t   KeyErrort
   BoundField(   RD   R   t   field(    (    s+   ../Django//lib/python/django/forms/forms.pyt   __getitem__j   s
    c         C@ s#   |  j  d k r |  j ƒ  n  |  j  S(   u7   Returns an ErrorDict for the data provided for the formN(   R@   R6   t
   full_clean(   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   _get_errorsr   s    c         C@ s   |  j  o t |  j ƒ S(   u   
        Returns True if the form has no errors. Otherwise, False. If errors are
        being ignored, returns False.
        (   R7   t   boolt   errors(   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   is_validy   s    c         C@ s    |  j  r d |  j  | f p | 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;   (   RD   R'   (    (    s+   ../Django//lib/python/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(   RR   (   RD   R'   (    (    s+   ../Django//lib/python/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] } d |	 t | ƒ f ^ qŒ ƒ n  | j	 t
 j | ƒ ƒ q) | j ƒ  } | rê d | } n  | r| r| j	 | t | ƒ ƒ n  | j rzt t | j ƒ ƒ } |  j rb| d d k rbt d | |  j ƒ } qbn  | j | ƒ ptd } n d } |
 j rŸ| t |
 j ƒ } n d } | j	 | i t | ƒ d 6t | ƒ d 6t
 j | ƒ d	 6| d
 6| 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 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 %s) %su    class="%s"iÿÿÿÿu   :?.!u   {0}{1}u   errorsu   labelu   fieldu	   help_textu   html_class_attri    u   
(   t   non_field_errorsR)   t   itemsR=   RP   R   t	   is_hiddent   extendR   t   appendR   t	   text_typet   css_classest   labelR>   R   t	   label_tagt	   help_textt   insertt   joint   endswitht   lenR   (   RD   t
   normal_rowt	   error_rowt	   row_endert   help_text_htmlt   errors_on_separate_rowt
   top_errorst   outputt   hidden_fieldsR   RK   t   html_class_attrt   bft   errort	   bf_errorst   eRZ   R[   R]   t
   str_hiddent   last_row(    (    s+   ../Django//lib/python/django/forms/forms.pyt   _html_output   sZ    
+	3			
 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>.Rb   uW   <tr%(html_class_attr)s><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>Rc   u    <tr><td colspan="2">%s</td></tr>Rd   u
   </td></tr>Re   u&   <br /><span class="helptext">%s</span>Rf   (   Rq   t   False(   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyRF   ×   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>.Rb   uF   <li%(html_class_attr)s>%(errors)s%(label)s %(field)s%(help_text)s</li>Rc   u   <li>%s</li>Rd   u   </li>Re   u!    <span class="helptext">%s</span>Rf   (   Rq   Rr   (   RD   (    (    s+   ../Django//lib/python/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.Rb   u:   <p%(html_class_attr)s>%(label)s %(field)s%(help_text)s</p>Rc   u   %sRd   u   </p>Re   u!    <span class="helptext">%s</span>Rf   (   Rq   t   True(   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   as_pé   s    	c         C@ s   |  j  j t |  j ƒ  ƒ 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.
        (   RP   t   gett   NON_FIELD_ERRORSR=   (   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyRT   ò   s    c         C@ s8   |  j  | } |  j | ƒ } | j j |  j |  j | ƒ S(   u‘   
        Returns the raw_value for a particular field name. This is just a
        convenient wrapper around widget.value_from_datadict.
        (   R)   RR   t   widgett   value_from_datadictR8   R9   (   RD   t	   fieldnameRK   R;   (    (    s+   ../Django//lib/python/django/forms/forms.pyt
   _raw_valueú   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   R@   R7   t   cleaned_dataR?   t   has_changedt   _clean_fieldst   _clean_formt   _post_clean(   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyRM     s    		

c         C@ s+  x$|  j  j ƒ  D]\ } } | j j |  j |  j |  j | ƒ ƒ } y• t | t ƒ r‚ |  j	 j
 | | j	 ƒ } | j | | ƒ } n | j | ƒ } | |  j | <t |  d | ƒ r× t |  d | ƒ ƒ  } | |  j | <n  Wq t k
 r"} |  j | j ƒ |  j | <| |  j k r#|  j | =q#q Xq Wd  S(   Nu   clean_%s(   R)   RU   Rx   Ry   R8   R9   RR   R   R   R<   Rv   t   cleanR|   R!   t   getattrR   R=   t   messagesR@   (   RD   R   RK   t   valueR<   Rn   (    (    s+   ../Django//lib/python/django/forms/forms.pyR~     s    'c         C@ sF   y |  j  ƒ  |  _ Wn, t k
 rA } |  j | j ƒ |  j t <n Xd  S(   N(   R   R|   R   R=   Rƒ   R@   Rw   (   RD   Rn   (    (    s+   ../Django//lib/python/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(    (   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyR€   /  s    c         C@ s   |  j  S(   u'  
        Hook for doing any extra form-wide cleaning after Field.clean() 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|   (   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyR   6  s    c         C@ s   t  |  j ƒ S(   u<   
        Returns True if data differs from initial.
        (   RO   t   changed_data(   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyR}   ?  s    c         C@ sñ   |  j  d  k rê g  |  _  xÏ |  j j ƒ  D]» \ } } |  j | ƒ } | j j |  j |  j | ƒ } | j	 s… |  j
 j | | j
 ƒ } n6 |  j | ƒ } | j ƒ  } | j |  j |  j | ƒ } | j j | | ƒ r( |  j  j | ƒ q( q( Wn  |  j  S(   N(   RA   R6   R)   RU   RR   Rx   Ry   R8   R9   t   show_hidden_initialR<   Rv   RS   t   hidden_widgett   _has_changedRX   (   RD   R   RK   t   prefixed_namet
   data_valuet   initial_valuet   initial_prefixed_nameR‡   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   _get_changed_dataE  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   R)   t   valuesRx   R/   (   RD   R/   RK   (    (    s+   ../Django//lib/python/django/forms/forms.pyt
   _get_media]  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.
        (   R)   RŽ   Rx   t   needs_multipart_formRt   Rr   (   RD   RK   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   is_multipartg  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.
        (   RV   (   RD   RK   (    (    s+   ../Django//lib/python/django/forms/forms.pyRi   q  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.
        (   RV   (   RD   RK   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   visible_fieldsx  s    N("   R2   R3   R6   R   Rr   RE   RG   RH   RL   RN   t   propertyRP   RQ   RR   RS   Rq   RF   Rs   Ru   RT   R{   RM   R~   R   R€   R   R}   R   R…   R   R/   R‘   Ri   R’   (    (    (    s+   ../Django//lib/python/django/forms/forms.pyR5   G   s<   										H																			
	t   Formc           B@ s   e  Z d  Z RS(   u3   A collection of Fields, plus their associated data.(   R2   R3   R4   (    (    (    s+   ../Django//lib/python/django/forms/forms.pyR”     s   RJ   c           B@ sþ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e	 e ƒ Z
 d d e d „ Z d d „ Z d d	 „ Z d d
 „ Z d „  Z e	 e ƒ Z d „  Z d d d „ Z d d „ Z d „  Z e	 e ƒ Z d „  Z e	 e ƒ Z d „  Z e	 e ƒ Z RS(   u   A Field plus datac         C@ s   | |  _  | |  _ | |  _ | j | ƒ |  _ | j | ƒ |  _ | j |  j ƒ |  _ |  j j	 d  k rx t | ƒ |  _	 n |  j j	 |  _	 | j p“ d |  _ d  S(   Nu    (   t   formRK   R   RR   t	   html_nameRS   t   html_initial_nameR:   t   html_initial_idR[   R6   R   R]   (   RD   R•   RK   R   (    (    s+   ../Django//lib/python/django/forms/forms.pyRE   Š  s    			c         C@ s0   |  j  j r& |  j ƒ  |  j d t ƒ S|  j ƒ  S(   u%   Renders this field as an HTML widget.t   only_initial(   RK   R†   t	   as_widgett	   as_hiddenRt   (   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyRG   —  s    c         c@ s5   x. |  j  j j |  j |  j ƒ  ƒ D] } | Vq" Wd S(   uá   
        Yields rendered strings that comprise all widgets in this BoundField.

        This really is only useful for RadioSelect widgets, so that you can
        iterate over individual radio buttons in a template.
        N(   RK   Rx   t
   subwidgetsR–   R„   (   RD   t	   subwidget(    (    s+   ../Django//lib/python/django/forms/forms.pyRH     s    (c         C@ s   t  t |  j ƒ  ƒ ƒ S(   N(   Ra   R   RH   (   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   __len__§  s    c         C@ s   t  |  j ƒ  ƒ | S(   N(   R   RH   (   RD   t   idx(    (    s+   ../Django//lib/python/django/forms/forms.pyRL   ª  s    c         C@ s"   |  j  j j |  j |  j  j ƒ  ƒ S(   ul   
        Returns an ErrorList for this field. Returns an empty ErrorList
        if there are none.
        (   R•   RP   Rv   R   R=   (   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyR@   ­  s    c         C@ s¥   | s |  j  j } n  | p i  } |  j } | rn d | k rn d | j k rn | s^ | | d <qn |  j | d <n  | s€ |  j } n	 |  j } | j | |  j ƒ  d | ƒS(   uÉ   
        Renders the field by rendering the passed widget, adding any HTML
        attributes passed as attrs.  If no widget is specified, then the
        field's default widget will be used.
        u   idR%   (	   RK   Rx   R:   R%   R˜   R–   R—   t   renderR„   (   RD   Rx   R%   R™   R:   R   (    (    s+   ../Django//lib/python/django/forms/forms.pyRš   µ  s    	!	c         K@ s   |  j  t ƒ  | |  S(   u[   
        Returns a string of HTML for representing this as an <input type="text">.
        (   Rš   R
   (   RD   R%   t   kwargs(    (    s+   ../Django//lib/python/django/forms/forms.pyt   as_textÌ  s    c         K@ s   |  j  t ƒ  | |  S(   u?   Returns a string of HTML for representing this as a <textarea>.(   Rš   R   (   RD   R%   R¡   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   as_textareaÒ  s    c         K@ s   |  j  |  j j ƒ  | |  S(   u]   
        Returns a string of HTML for representing this as an <input type="hidden">.
        (   Rš   RK   R‡   (   RD   R%   R¡   (    (    s+   ../Django//lib/python/django/forms/forms.pyR›   Ö  s    c         C@ s(   |  j  j j |  j j |  j j |  j ƒ S(   uS   
        Returns the data for this BoundField, or None if it wasn't given.
        (   RK   Rx   Ry   R•   R8   R9   R–   (   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   _dataÜ  s    c         C@ s‹   |  j  j sH |  j  j j |  j |  j j ƒ } t | ƒ r{ | ƒ  } q{ n3 |  j j |  j |  j  j j |  j |  j j ƒ ƒ } |  j j	 | ƒ S(   uˆ   
        Returns the value for this BoundField, using the initial value if
        the form is not bound or the data otherwise.
        (
   R•   R7   R<   Rv   R   RK   t   callablet
   bound_dataR8   t   prepare_value(   RD   R8   (    (    s+   ../Django//lib/python/django/forms/forms.pyR„   ã  s    !	*c      	   C@ s…   | p t  |  j ƒ } |  j j } | j j d ƒ p9 |  j } | r{ | rT t | ƒ pW d } t d | j	 | ƒ | | ƒ } n  t
 | ƒ S(   u2  
        Wraps the given contents in a <label>, if the field has an ID attribute.
        contents should be 'mark_safe'd to avoid HTML escaping. If contents
        aren't given, uses the field's HTML-escaped label.

        If attrs are given, they're used as HTML attributes on the <label> tag.
        u   idu    u   <label for="{0}"{1}>{2}</label>(   R   R[   RK   Rx   R%   Rv   R:   R   R   t   id_for_labelR   (   RD   t   contentsR%   Rx   t   id_(    (    s+   ../Django//lib/python/django/forms/forms.pyR\   ò  s    c         C@ s¢   t  | d ƒ r | j ƒ  } n  t | p* g  ƒ } |  j ra t  |  j d ƒ ra | j |  j j ƒ n  |  j j r• t  |  j d ƒ r• | j |  j j	 ƒ n  d j
 | ƒ S(   uQ   
        Returns a string of space-separated CSS classes for this field.
        u   splitu   error_css_classu   required_css_classu    (   R!   t   splitt   setRP   R•   t   addt   error_css_classRK   t   requiredt   required_css_classR_   (   RD   t   extra_classes(    (    s+   ../Django//lib/python/django/forms/forms.pyRZ     s    c         C@ s   |  j  j j S(   u3   Returns True if this BoundField's widget is hidden.(   RK   Rx   RV   (   RD   (    (    s+   ../Django//lib/python/django/forms/forms.pyt
   _is_hidden  s    c         C@ sF   |  j  j } | r5 d t | ƒ k r5 t | ƒ |  j S| rB |  j Sd S(   u§   
        Calculates and returns the ID attribute for this BoundField, if the
        associated Form has specified auto_id. Returns an empty string otherwise.
        u   %su    (   R•   R:   R   R–   (   RD   R:   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   _auto_id  s    c         C@ s4   |  j  j } | j j d ƒ p$ |  j } | j | ƒ S(   uÈ   
        Wrapper around the field widget's `id_for_label` method.
        Useful, for example, for focusing on this field regardless of whether
        it has a single widget or a MutiWidget.
        u   id(   RK   Rx   R%   Rv   R:   R¨   (   RD   Rx   Rª   (    (    s+   ../Django//lib/python/django/forms/forms.pyt   _id_for_label#  s    N(   R2   R3   R4   RE   RG   RH   Rž   RL   R@   R“   RP   R6   Rr   Rš   R¢   R£   R›   R¤   R8   R„   R\   RZ   R²   RV   R³   R:   R´   R¨   (    (    (    s+   ../Django//lib/python/django/forms/forms.pyRJ   ‡  s.   			
									(,   R4   t
   __future__R    R   RB   t   django.core.exceptionsR   t   django.forms.fieldsR   R   t   django.forms.utilR   R   R   t   django.forms.widgetsR   R	   R
   R   t   django.utils.datastructuresR   t   django.utils.htmlR   R   t   django.utils.encodingR   R   R   t   django.utils.safestringR   t   django.utilsR   t   __all__Rw   R   Rt   R+   t   typeR,   t   objectR5   t   with_metaclassR”   RJ   (    (    (    s+   ../Django//lib/python/django/forms/forms.pyt   <module>   s,   "	ÿ 8"