o
    þÞh×3  ã                   @   sŠ   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 d dlmZmZ d dlmZ dZG d	d
„ d
eƒZeG dd„ dƒƒZdS )é    N)ÚValidationError)ÚRenderableFieldMixinÚpretty_name)ÚMultiWidgetÚTextareaÚ	TextInput)Úcached_property)Úformat_htmlÚ	html_safe)Úgettext_lazy)Ú
BoundFieldc                   @   s$  e Zd Z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edd„ ƒZdd„ Z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#„ Zd<d$d%„Zd=d&d'„Zd;d(d)„Zed*d+„ ƒZed,d-„ ƒZed.d/„ ƒZed0d1„ ƒZd;d2d3„Zed4d5„ ƒZed6d7„ ƒZed8d9„ ƒZ dS )>r   zA Field plus datac                 C   sr   || _ || _|| _| |¡| _| |¡| _| | j¡| _| jj	d u r(t
|ƒ| _	n| jj	| _	|jp1d| _|j| _d S )NÚ )ÚformÚfieldÚnameÚ
add_prefixÚ	html_nameÚadd_initial_prefixÚhtml_initial_nameÚauto_idÚhtml_initial_idÚlabelr   Ú	help_textÚrenderer)Úselfr   r   r   © r   úW/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/forms/boundfield.pyÚ__init__   s   
zBoundField.__init__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   r   )Ú.0r    ©r   r   r   Ú
<listcomp>*   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__1   s   zBoundField.__bool__c                 C   ó
   t | jƒS ©N)Úiterr'   r"   r   r   r   Ú__iter__5   ó   
zBoundField.__iter__c                 C   r,   r-   )Úlenr'   r"   r   r   r   Ú__len__8   r0   zBoundField.__len__c                 C   s*   t |ttfƒstdt|ƒj ƒ‚| j| S )Nz6BoundField indices must be integers or slices, not %s.)Ú
isinstanceÚintÚsliceÚ	TypeErrorÚtypeÚ__name__r'   )r   Úidxr   r   r   Ú__getitem__;   s   ÿÿ
zBoundField.__getitem__c                 C   s    | j j | j| j j| j jd�¡S )zT
        Return an ErrorList (empty if there are no errors) for this field.
        )r   )r   Úerrorsr%   r   Úerror_classr   r"   r   r   r   r;   E   s   ÿzBoundField.errorsc                 C   s   | j jp| jjjS r-   )r   Útemplate_namer   r   Úfield_template_namer"   r   r   r   r=   N   ó   zBoundField.template_namec                 C   s   d| iS )Nr   r   r"   r   r   r   Úget_contextR   s   zBoundField.get_contextNFc                 C   sª   |p| j j}| j jrd|_|pi }|  ||¡}| jr+d|jvr+| d|r'| jn| j¡ |r@| j	| j
jv r@| j
 | j  ¡ | j	¡}n|  ¡ }|j|rK| j	n| j||| j
j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   r(   r$   r   )r   r    ÚlocalizeÚis_localizedr&   r   r$   Ú
setdefaultr   r   r   ÚdataÚ_widget_data_valueÚhidden_widgetr(   Úrenderr   r   )r   r    r$   Úonly_initialr(   r   r   r   Ú	as_widgetU   s*   ÿþüzBoundField.as_widgetc                 K   ó   | j tƒ |fi |¤ŽS )zZ
        Return a string of HTML for representing this as an <input type="text">.
        )rI   r   ©r   r$   Úkwargsr   r   r   Úas_texts   s   zBoundField.as_textc                 K   rJ   )z>Return a string of HTML for representing this as a <textarea>.)rI   r   rK   r   r   r   Úas_textareay   s   zBoundField.as_textareac                 K   s   | j | j ¡ |fi |¤ŽS )z\
        Return a string of HTML for representing this as an <input type="hidden">.
        )rI   r   rF   rK   r   r   r   Ú	as_hidden}   s   zBoundField.as_hiddenc                 C   s   | j  | jj| j¡S )zR
        Return the data for this BoundField, or None if it wasn't given.
        )r   rE   r   r    r   r"   r   r   r   rD   ƒ   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   Úis_boundr   Ú
bound_datarD   Úprepare_value)r   rD   r   r   r   r(   Š   s   zBoundField.valuec                 C   s\   | j }|jr$| ¡ }| j || j¡}z| |¡}W n ty#   Y dS w | j}| 	|| j
¡S r*   )r   Úshow_hidden_initialrF   r   rE   r   Ú	to_pythonr   rP   Úhas_changedrD   )r   r   rF   Úinitial_valuer   r   r   Ú_has_changed”   s   þþzBoundField._has_changedc           	      C   s  |p| j }|du r| jjdur| jjn| jj}|r)|r)|d tdƒvr)td||ƒ}| jj}|j d¡p5| j	}|rn| 
|¡}|rIi |pCi ¥d|i¥}| jjrnt| jdƒrn|pVi }d|v rh|d  d	| jj 7  < n| jj|d< | ||t|ƒ|pwd
dœ}| j | jj|¡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   )r   r   r$   Úuse_tagÚtag)r   r   Úlabel_suffixr   Ú_r	   r    r$   r%   r   Úid_for_labelÚrequiredÚhasattrr[   ÚboolrG   Útemplate_name_label)	r   Úcontentsr$   r`   r_   r    r)   rb   Úcontextr   r   r   Ú	label_tag¥   s4   

ÿý
ûzBoundField.label_tagc                 C   s   | j |||dd�S )af  
        Wrap the given contents in a <legend>, 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 <legend> tag.

        label_suffix overrides the form's label_suffix.
        Úlegend©r_   )ri   )r   rg   r$   r`   r   r   r   Ú
legend_tagÐ   s   
zBoundField.legend_tagc                 C   sj   t |dƒr	| ¡ }t|pg ƒ}| jrt | jdƒr| | jj¡ | jjr0t | jdƒr0| | jj	¡ d 
|¡S )zP
        Return a string of space-separated CSS classes for this field.
        ÚsplitÚerror_css_classr[   r]   )rd   rm   Úsetr;   r   Úaddrn   r   rc   r[   Újoin)r   Úextra_classesr   r   r   Úcss_classesÜ   s   

zBoundField.css_classesc                 C   ó
   | j jjS )z2Return True if this BoundField's widget is hidden.)r   r    Ú	is_hiddenr"   r   r   r   ru   é   s   
zBoundField.is_hiddenc                 C   s0   | j j}|rdt|ƒv 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   rb   )r   r    r)   r   r   r   rb   û   s   
zBoundField.id_for_labelc                 C   s   | j  | j| j¡S r-   )r   Úget_initial_for_fieldr   r   r"   r   r   r   rP     r?   zBoundField.initialc                 C   sØ   |p| j j}t|ƒ}| | j¡rG| j jrG| jjrGt| j dƒrC| j jsCt	| j jt
ƒrCt| j j|jƒD ]\}}| | j¡o=|j|jd< q1nd|d< | j jrOd|d< |jsY| jrYd|d< | d¡sj| jsj| j }rj||d< |S )NÚrequire_all_fieldsrc   TÚdisabledÚtruezaria-invalidúaria-describedby)r   r    ÚdictÚuse_required_attributerP   rc   r   rd   rx   r3   r   ÚzipÚfieldsÚwidgetsr$   ry   ru   r;   r%   Úuse_fieldsetÚaria_describedby)r   r$   r    ÚsubfieldÚ	subwidgetr‚   r   r   r   r&   
  s8   
ÿþý
ÿþý
þÿ
zBoundField.build_widget_attrsc                 C   s^   | j jj d¡r
d S g }| jr*| js*| jr| | j› d�¡ | jr*| | j› d�¡ d 	|¡S )Nr{   Ú	_helptextÚ_errorr]   )
r   r    r$   r%   r   ru   r   Úappendr;   rq   )r   r‚   r   r   r   r‚   +  s   
zBoundField.aria_describedbyc                 C   s   t  dd| jjjj ¡ ¡S )Nzwidget$|input$r   )ÚreÚsubr   r    Ú	__class__r8   Úlowerr"   r   r   r   Úwidget_type8  s   ÿzBoundField.widget_typec                 C   rt   )zV
        Return the value of this BoundField widget's use_fieldset attribute.
        )r   r    r�   r"   r   r   r   r�   >  s   
zBoundField.use_fieldset)NNFr-   )NNNN)NNN)!r8   Ú
__module__Ú__qualname__Ú__doc__r   r   r'   r+   r/   r2   r:   Úpropertyr;   r=   r@   rI   rM   rN   rO   rD   r(   rX   ri   rl   rs   ru   r   rb   rP   r&   r‚   rŒ   r�   r   r   r   r   r      sP    











+






!

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 r-   )Úparent_widgetrD   r   )r   r‘   rD   r   r   r   r   r   U  s   
zBoundWidget.__init__c                 C   s   | j dd�S )NT)Ú
wrap_labelrk   r"   r   r   r   Ú__str__Z  s   zBoundWidget.__str__Fc                 C   s*   di | j ¥d|i¥i}| j | j|| j¡S )Nr    r’   )rD   r‘   Ú_renderr=   r   )r   r’   rh   r   r   r   r_   ]  s   zBoundWidget.tagc                 C   s   d| j v r
| j d S | jjS )Nr=   )rD   r‘   r=   r"   r   r   r   r=   a  s   

zBoundWidget.template_namec                 C   s   | j d  d¡S )Nr$   r   )rD   r%   r"   r   r   r   rb   g  s   zBoundWidget.id_for_labelc                 C   s
   | j d S )Nr   )rD   r"   r   r   r   Úchoice_labelk  s   
zBoundWidget.choice_labelN)F)r8   r�   rŽ   r�   r   r“   r_   r�   r=   rb   r•   r   r   r   r   r   F  s    


r   )rˆ   Údjango.core.exceptionsr   Údjango.forms.utilsr   r   Údjango.forms.widgetsr   r   r   Údjango.utils.functionalr   Údjango.utils.htmlr	   r
   Údjango.utils.translationr   ra   Ú__all__r   r   r   r   r   r   Ú<module>   s      ;