
 X#                 @   s   d  d l  m Z d  d l 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 d  d l m Z m Z m Z d  d l m Z d  d	 l m Z d Z e   Z e e Gd d
   d
 e    Z d S)    )unicode_literalsN)flatattpretty_name)Textarea	TextInput)six)
force_textpython_2_unicode_compatible
smart_text)conditional_escapeformat_html	html_safe)	mark_safe)ugettext_lazy
BoundFieldc               @   s?  e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z e	 d d    Z
 d d d d d  Z d d d  Z d d d  Z d d d  Z e	 d d    Z d d   Z d d d d d  Z d d d  Z e	 d  d!    Z e	 d" d#    Z e	 d$ d%    Z e	 d& d'    Z d d( d)  Z d S)*r   zA Field plus datac             C   s   | |  _  | |  _ | |  _ | j |  |  _ | j |  |  _ | j |  j  |  _ |  j j	 d  k rx t
 |  |  _	 n |  j j	 |  _	 | j p d |  _ t |  _ d  S)N )formfieldnameZ
add_prefix	html_nameZadd_initial_prefixhtml_initial_nameauto_idhtml_initial_idlabelr   	help_textUNSET_initial_value)selfr   r   r    r   E/home/ubuntu/projects/ifolica/build/django/django/forms/boundfield.py__init__   s    			zBoundField.__init__c             C   s0   |  j  j r& |  j   |  j d d  S|  j   S)z%Renders this field as an HTML widget.only_initialT)r   Zshow_hidden_initial	as_widget	as_hidden)r   r   r   r   __str__'   s    zBoundField.__str__c             c   s   |  j  j j j d  p |  j } | r4 i | d 6n i  } |  j |  } x1 |  j  j j |  j |  j   |  D] } | Vqn Wd S)z
        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.
        idN)	r   widgetattrsgetr   build_widget_attrsZ
subwidgetsr   value)r   id_r'   Z	subwidgetr   r   r   __iter__-   s
    !+zBoundField.__iter__c             C   s   t  t |  j     S)N)lenlistr,   )r   r   r   r   __len__:   s    zBoundField.__len__c             C   s6   t  | t j t f  s" t  n  t |  j    | S)N)
isinstancer   integer_typesslice	TypeErrorr.   r,   )r   idxr   r   r   __getitem__=   s    	zBoundField.__getitem__c             C   s"   |  j  j j |  j |  j  j    S)zl
        Returns an ErrorList for this field. Returns an empty ErrorList
        if there are none.
        )r   errorsr(   r   Zerror_class)r   r   r   r   r6   D   s    zBoundField.errorsNFc             C   s   | s |  j  j } n  |  j  j r- d | _ n  | p6 i  } |  j | |  } |  j } | r d | k r d | j k r | s | | d <q |  j | d <n  | s |  j } n	 |  j	 } t
 | j | |  j   d |  S)z
        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.
        Tr%   r'   )r   r&   ZlocalizeZis_localizedr)   r   r'   r   r   r   r   renderr*   )r   r&   r'   r!   r   r   r   r   r   r"   L   s    	!	zBoundField.as_widgetc             K   s   |  j  t   | |  S)z[
        Returns a string of HTML for representing this as an <input type="text">.
        )r"   r   )r   r'   kwargsr   r   r   as_textg   s    zBoundField.as_textc             K   s   |  j  t   | |  S)z?Returns a string of HTML for representing this as a <textarea>.)r"   r   )r   r'   r8   r   r   r   as_textaream   s    zBoundField.as_textareac             K   s   |  j  |  j j   | |  S)z]
        Returns a string of HTML for representing this as an <input type="hidden">.
        )r"   r   Zhidden_widget)r   r'   r8   r   r   r   r#   q   s    zBoundField.as_hiddenc             C   s(   |  j  j j |  j j |  j j |  j  S)zS
        Returns the data for this BoundField, or None if it wasn't given.
        )r   r&   Zvalue_from_datadictr   datafilesr   )r   r   r   r   r;   w   s    zBoundField.datac             C   s[   |  j  j s |  j } n3 |  j j |  j |  j  j j |  j |  j j   } |  j j |  S)z
        Returns the value for this BoundField, using the initial value if
        the form is not bound or the data otherwise.
        )	r   Zis_boundinitialr   Z
bound_datar;   r(   r   Zprepare_value)r   r;   r   r   r   r*   ~   s
    	*zBoundField.valuec             C   s  | p |  j  } | d k rH |  j j d k	 r9 |  j j n	 |  j j } n  | r | r | d t d  k r t d | |  } n  |  j j } | j j d  p |  j	 } | rq| j
 |  } | r t | p i  i | d 6 } n  |  j j rDt |  j d  rD| pi  } d | k r1| d d	 |  j j 7<qD|  j j | d <n  | rVt |  n d
 } t d | |  } n t |  } t |  S)as  
        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.

        label_suffix allows overriding the form's label_suffix.
        N   z:?.!z{}{}r%   forrequired_css_classclass r   z<label{}>{}</label>)r   r   label_suffixr   _r   r&   r'   r(   r   id_for_labeldictrequiredhasattrr@   r   r   r   )r   contentsr'   rD   r&   r+   rF   r   r   r   	label_tag   s*    
"zBoundField.label_tagc             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)zQ
        Returns a string of space-separated CSS classes for this field.
        spliterror_css_classr@   rB   )rI   rL   setr6   r   addrM   r   rH   r@   join)r   Zextra_classesr   r   r   css_classes   s    zBoundField.css_classesc             C   s   |  j  j j S)z3Returns True if this BoundField's widget is hidden.)r   r&   	is_hidden)r   r   r   r   rR      s    zBoundField.is_hiddenc             C   sF   |  j  j } | r5 d t |  k r5 t |  |  j S| rB |  j Sd S)z
        Calculates and returns the ID attribute for this BoundField, if the
        associated Form has specified auto_id. Returns an empty string otherwise.
        z%sr   )r   r   r
   r   )r   r   r   r   r   r      s    zBoundField.auto_idc             C   s4   |  j  j } | j j d  p$ |  j } | j |  S)z
        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 MultiWidget.
        r%   )r   r&   r'   r(   r   rF   )r   r&   r+   r   r   r   rF      s    zBoundField.id_for_labelc             C   s   |  j  j j |  j |  j j  } t |  r |  j t k	 rH |  j } q |   } t | t	 j	 t	 j
 f  r |  j j j r | j d d  } n  | |  _ n  | S)Nmicrosecondr   )r   r=   r(   r   r   callabler   r   r0   datetimetimer&   Zsupports_microsecondsreplace)r   r;   r   r   r   r=      s    !	zBoundField.initialc             C   su   | s |  j  j } n  t |  } | j |  j  rX |  j  j rX |  j j rX d | d <n  |  j  j rq d | d <n  | S)NTrH   disabled)r   r&   rG   Zuse_required_attributer=   rH   r   rX   )r   r'   r&   r   r   r   r)      s    *zBoundField.build_widget_attrs)__name__
__module____qualname____doc__r    r$   r,   r/   r5   propertyr6   r"   r9   r:   r#   r;   r*   rK   rQ   rR   r   rF   r=   r)   r   r   r   r   r      s(   %)z
BoundField)
__future__r   rU   Zdjango.forms.utilsr   r   Zdjango.forms.widgetsr   r   Zdjango.utilsr   Zdjango.utils.encodingr   r	   r
   Zdjango.utils.htmlr   r   r   Zdjango.utils.safestringr   Zdjango.utils.translationr   rE   __all__objectr   r   r   r   r   r   <module>   s   	