B
    ©0H[ý)  ã               @   s°   d dl 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 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 d
ZeG dd„ dƒƒZeG dd„ dƒƒZdS )é    N)ÚflatattÚpretty_name)ÚTextareaÚ	TextInput)ÚRemovedInDjango21Warning)Úcached_property)Úconditional_escapeÚformat_htmlÚ	html_safe)Úfunc_accepts_kwargsÚfunc_supports_parameter)Ú	mark_safe)Úgettext_lazy)Ú
BoundFieldc               @   sâ   e Zd ZdZdd„ Zdd„ Zedd„ ƒZdd	„ Zd
d„ Z	dd„ Z
dd„ Zedd„ ƒZd.dd„Zd/dd„Zd0dd„Zd1dd„Zedd„ ƒZdd„ Zd2d d!„Zd3d"d#„Zed$d%„ ƒZed&d'„ ƒZed(d)„ ƒZed*d+„ ƒZd4d,d-„ZdS )5r   zA Field plus datac             C   sj   || _ || _|| _| |¡| _| |¡| _| | j¡| _| jj	d krPt
|ƒ| _	n
| jj	| _	|jpbd| _d S )NÚ )ÚformÚfieldÚnameZ
add_prefixÚ	html_nameZadd_initial_prefixÚhtml_initial_nameÚauto_idÚhtml_initial_idÚlabelr   Ú	help_text)Úselfr   r   r   © r   ú[C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\forms\boundfield.pyÚ__init__   s    
zBoundField.__init__c             C   s$   | j jr|  ¡ | jdd� S |  ¡ S )z$Render this field as an HTML widget.T)Úonly_initial)r   Zshow_hidden_initialÚ	as_widgetÚ	as_hidden)r   r   r   r   Ú__str__    s    zBoundField.__str__c                sX   ˆ j jj d¡pˆ j}|r"d|ini }ˆ  |¡}‡ fdd„ˆ j jjˆ jˆ  ¡ |d�D ƒS )a  
        Most widgets yield a single subwidget, but others like RadioSelect and
        CheckboxSelectMultiple produce one subwidget for each choice.

        This property is cached so that only one database query occurs when
        rendering ModelChoiceFields.
        Úidc                s    g | ]}t ˆ jj|ˆ jjƒ‘qS r   )ÚBoundWidgetr   Úwidgetr   Úrenderer)Ú.0r$   )r   r   r   ú
<listcomp>3   s   z)BoundField.subwidgets.<locals>.<listcomp>)Úattrs)	r   r$   r(   Úgetr   Úbuild_widget_attrsÚ
subwidgetsr   Úvalue)r   Úid_r(   r   )r   r   r+   &   s
    	

zBoundField.subwidgetsc             C   s   dS )NTr   )r   r   r   r   Ú__bool__7   s    zBoundField.__bool__c             C   s
   t | jƒS )N)Úiterr+   )r   r   r   r   Ú__iter__;   s    zBoundField.__iter__c             C   s
   t | jƒS )N)Úlenr+   )r   r   r   r   Ú__len__>   s    zBoundField.__len__c             C   s   t |ttfƒst‚| j| S )N)Ú
isinstanceÚintÚsliceÚ	TypeErrorr+   )r   Úidxr   r   r   Ú__getitem__A   s    zBoundField.__getitem__c             C   s   | j j | j| j  ¡ ¡S )zT
        Return an ErrorList (empty if there are no errors) for this field.
        )r   Úerrorsr)   r   Zerror_class)r   r   r   r   r9   H   s    zBoundField.errorsNFc             C   sÎ   |s| j j}| j jrd|_|p i }|  ||¡}| j}|rbd|krbd|jkrb|sX||d< n
| j|d< |sn| j}n| j	}i }t
|jdƒsŽt|jƒrœ| jj|d< ntjd|j tdd� |jf ||  ¡ |dœ|—ŽS )z»
        Render the field by rendering the passed widget, adding any HTML
        attributes passed as attrs. If a widget isn't specified, use the
        field's default widget.
        Tr"   r%   z]Add the `renderer` argument to the render() method of %s. It will be mandatory in Django 2.1.é   )Ú
stacklevel)r   r,   r(   )r   r$   ZlocalizeZis_localizedr*   r   r(   r   r   r   r   Úrenderr   r   r%   ÚwarningsÚwarnÚ	__class__r   r,   )r   r$   r(   r   r   r   Úkwargsr   r   r   r   O   s4    


zBoundField.as_widgetc             K   s   | j tƒ |f|ŽS )zZ
        Return a string of HTML for representing this as an <input type="text">.
        )r   r   )r   r(   r@   r   r   r   Úas_texty   s    zBoundField.as_textc             K   s   | j tƒ |f|ŽS )z>Return a string of HTML for representing this as a <textarea>.)r   r   )r   r(   r@   r   r   r   Úas_textarea   s    zBoundField.as_textareac             K   s   | j | j ¡ |f|ŽS )z\
        Return a string of HTML for representing this as an <input type="hidden">.
        )r   r   Zhidden_widget)r   r(   r@   r   r   r   r    ƒ   s    zBoundField.as_hiddenc             C   s   | j j | jj| jj| j¡S )zR
        Return the data for this BoundField, or None if it wasn't given.
        )r   r$   Zvalue_from_datadictr   ÚdataÚfilesr   )r   r   r   r   rC   ‰   s    zBoundField.datac             C   s*   | j }| jjr| j | j|¡}| j |¡S )z‡
        Return the value for this BoundField, using the initial value if
        the form is not bound or the data otherwise.
        )Úinitialr   Zis_boundr   Z
bound_datarC   Zprepare_value)r   rC   r   r   r   r,   �   s    zBoundField.valuec             C   s
  |p| j }|dkr.| jjdk	r&| jjn| jj}|rR|rR|d tdƒkrRtd||ƒ}| jj}|j d¡pj| j	}|rú| 
|¡}|r’t|p†i fd|iŽ}| jjrÜt| jdƒrÜ|p¬i }d|krÐ|d  d	| jj 7  < n| jj|d< |rèt|ƒnd
}td||ƒ}nt|ƒ}t|ƒS )ad  
        Wrap 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, use the field's HTML-escaped label.

        If attrs are given, use them as HTML attributes on the <label> tag.

        label_suffix overrides 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ÚhasattrrH   r   r   r   )r   Úcontentsr(   rK   r$   r-   rM   r   r   r   Ú	label_tagš   s*    


zBoundField.label_tagc             C   sj   t |dƒr| ¡ }t|pg ƒ}| jr>t | jdƒr>| | jj¡ | jjr`t | jdƒr`| | jj	¡ d 
|¡S )zP
        Return a string of space-separated CSS classes for this field.
        ÚsplitÚerror_css_classrH   rJ   )rP   rS   Úsetr9   r   ÚaddrT   r   rO   rH   Újoin)r   Zextra_classesr   r   r   Úcss_classes¿   s    
zBoundField.css_classesc             C   s
   | j jjS )z2Return True if this BoundField's widget is hidden.)r   r$   Ú	is_hidden)r   r   r   r   rY   Ì   s    zBoundField.is_hiddenc             C   s0   | j j}|r"dt|ƒkr"|| j S |r,| jS dS )z¤
        Calculate and return the ID attribute for this BoundField, if the
        associated Form has specified auto_id. Return an empty string otherwise.
        z%sr   )r   r   Ústrr   )r   r   r   r   r   r   Ñ   s    
zBoundField.auto_idc             C   s$   | j j}|j d¡p| 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   rM   )r   r$   r-   r   r   r   rM   Þ   s    zBoundField.id_for_labelc             C   s>   | j  | j| j¡}t|tjtjfƒr:| jjjs:|j	dd�}|S )Nr   )Úmicrosecond)
r   Zget_initial_for_fieldr   r   r3   ÚdatetimeÚtimer$   Zsupports_microsecondsÚreplace)r   rC   r   r   r   rE   é   s
    
zBoundField.initialc             C   sL   |s| j j}t|ƒ}| | j¡r8| j jr8| jjr8d|d< | j jrHd|d< |S )NTrO   Údisabled)r   r$   rN   Zuse_required_attributerE   rO   r   r_   )r   r(   r$   r   r   r   r*   ó   s    zBoundField.build_widget_attrs)NNF)N)N)N)NNN)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r!   r   r+   r.   r0   r2   r8   Úpropertyr9   r   rA   rB   r    rC   r,   rR   rX   rY   r   rM   rE   r*   r   r   r   r   r      s,   
*




%

r   c               @   sN   e Zd ZdZdd„ Zdd„ Zddd„Zed	d
„ ƒZedd„ ƒZ	edd„ ƒZ
dS )r#   ap  
    A container class used for iterating over widgets. This is useful for
    widgets that have choices. For example, the following can be used in a
    template:

    {% for radio in myform.beatles %}
      <label for="{{ radio.id_for_label }}">
        {{ radio.choice_label }}
        <span class="radio">{{ radio.tag }}</span>
      </label>
    {% endfor %}
    c             C   s   || _ || _|| _d S )N)Úparent_widgetrC   r%   )r   re   rC   r%   r   r   r   r     s    zBoundWidget.__init__c             C   s   | j dd�S )NT)Ú
wrap_label)Útag)r   r   r   r   r!     s    zBoundWidget.__str__Fc             C   s    | j |dœ}| j | j|| j¡S )N)r$   rf   )rC   re   Z_renderÚtemplate_namer%   )r   rf   Úcontextr   r   r   rg     s    zBoundWidget.tagc             C   s   d| j kr| j d S | jjS )Nrh   )rC   re   rh   )r   r   r   r   rh     s    

zBoundWidget.template_namec             C   s   d| j d | j d f S )Nzid_%s_%sr   Úindex)rC   )r   r   r   r   rM     s    zBoundWidget.id_for_labelc             C   s
   | j d S )Nr   )rC   )r   r   r   r   Úchoice_label"  s    zBoundWidget.choice_labelN)F)r`   ra   rb   rc   r   r!   rg   rd   rh   rM   rk   r   r   r   r   r#   þ   s   
r#   )r\   r=   Zdjango.forms.utilsr   r   Zdjango.forms.widgetsr   r   Zdjango.utils.deprecationr   Zdjango.utils.functionalr   Zdjango.utils.htmlr   r	   r
   Zdjango.utils.inspectr   r   Zdjango.utils.safestringr   Zdjango.utils.translationr   rL   Ú__all__r   r#   r   r   r   r   Ú<module>   s    o