
    af2                         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
e          Ze G d d                      ZdS )    N)ValidationError)RenderableFieldMixinpretty_name)MultiWidgetTextarea	TextInput)cached_property)format_html	html_safe)gettext_lazy)
BoundFieldc                   ^   e Zd ZdZd Zed             Zd Zd Zd Z	d Z
ed             Zed	             Zd
 ZddZddZddZddZed             Zd Zd Zd dZd!dZddZed             Zed             Zed             Zed             ZddZed             Zed             ZdS )"r   zA Field plus datac                 n   || _         || _        || _        |                    |          | _        |                    |          | _        |                    | j                  | _        | j        j	        t          |          | _	        n| j        j	        | _	        |j        pd| _        |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   s       I/var/www/html/env/lib/python3.11/site-packages/django/forms/boundfield.py__init__zBoundField.__init__   s    	
	..!%!8!8!>!>#66t|DD:#$T**DJJ)DJ.B    c                      j         j        j                            d          p j        }|rd|ini }                     |          } fd j         j                             j                                         |          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                 Z    g | ]'}t          j        j        |j        j                  (S  )BoundWidgetr   widgetr   r   ).0r&   r   s     r   
<listcomp>z)BoundField.subwidgets.<locals>.<listcomp>*   s?     
 
 
 
)6493EFF
 
 
r    )attrs)	r   r&   r)   getr   build_widget_attrs
subwidgetsr   value)r   id_r)   s   `  r   r,   zBoundField.subwidgets   s     j%))$//?4<"*s''..
 
 
 
*+66

E 7  
 
 
 	
r    c                     dS NTr$   r   s    r   __bool__zBoundField.__bool__1   s    tr    c                 *    t          | j                  S N)iterr,   r1   s    r   __iter__zBoundField.__iter__5   s    DO$$$r    c                 *    t          | j                  S r4   )lenr,   r1   s    r   __len__zBoundField.__len__8   s    4?###r    c                     t          |t          t          f          s$t          dt	          |          j        z            | j        |         S )Nz6BoundField indices must be integers or slices, not %s.)
isinstanceintslice	TypeErrortype__name__r,   )r   idxs     r   __getitem__zBoundField.__getitem__;   sO     #U|,, 	Hs))$%   s##r    c                     | j         j                            | j        | j                             | j         j                            S )zT
        Return an ErrorList (empty if there are no errors) for this field.
        )r   )r   errorsr*   r   error_classr   r1   s    r   rD   zBoundField.errorsE   s@    
 y##Ity,,di6H,II
 
 	
r    c                 <    | j         j        p| j        j        j        S r4   )r   template_namer   r   field_template_namer1   s    r   rG   zBoundField.template_nameN   s    z'Q49+=+QQr    c                 
    d| iS )Nr   r$   r1   s    r   get_contextzBoundField.get_contextR   s    r    NFc                    |p| j         j        }| j         j        rd|_        |pi }|                     ||          }| j        r-d|j        vr$|                    d|r| j        n| j                   |rK| j	        | j
        j        v r8| j
                            | j                                         | j	                  }n|                                 }|                    |r| j	        n| j        ||| j
        j                  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-   s        r   	as_widgetzBoundField.as_widgetU   s    ,4:,: 	'"&F''v66< 	D44lLd**    	!D2dinDDI00
((**& EE
 JJLLE}}+7K''T^Y'	  
 
 	
r    c                 8     | j         t                      |fi |S )zZ
        Return a string of HTML for representing this as an <input type="text">.
        )rT   r   r   r)   kwargss      r   as_textzBoundField.as_texts   s$     t~ikk5;;F;;;r    c                 8     | j         t                      |fi |S )z>Return a string of HTML for representing this as a <textarea>.)rT   r   rV   s      r   as_textareazBoundField.as_textareay   s"    t~hjj%::6:::r    c                 N     | j         | j                                        |fi |S )z\
        Return a string of HTML for representing this as an <input type="hidden">.
        )rT   r   rQ   rV   s      r   	as_hiddenzBoundField.as_hidden}   s.     t~dj6688%JJ6JJJr    c                 V    | j                             | j        j        | j                  S )zR
        Return the data for this BoundField, or None if it wasn't given.
        )r   rP   r   r&   r   r1   s    r   rO   zBoundField.data   s#    
 y++DJ,=t~NNNr    c                     | 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_datarO   prepare_value)r   rO   s     r   r-   zBoundField.value   sG    
 |9 	::((D99Dz''---r    c                    | j         }|j        r\|                                }| j                            || j                  }	 |                    |          }n# t          $ r Y dS w xY w| j        }|	                    || j
                  S r0   )r   show_hidden_initialrQ   r   rP   r   	to_pythonr   r_   has_changedrO   )r   r   rQ   initial_values       r   _has_changedzBoundField._has_changed   s    
$ 	)!//11M I88& M % > >"   tt !LM  	:::s   A 
A('A(c                 |   |p| j         }|$| j        j        | j        j        n| j        j        }|r*|r(|d         t	          d          vrt          d||          }| j        j        }|j                            d          p| j	        }|rw|
                    |          }|r
i |pi d|i}| j        j        rJt          | j        d          r5|pi }d|v r|dxx         d	| j        j        z   z  cc<   n| j        j        |d<   | ||t          |          |pd
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.
        Nz:?.!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hasattrrl   boolrR   template_name_label)	r   contentsr)   rq   rp   r&   r.   rs   contexts	            r   	label_tagzBoundField.label_tag   s    )tz :*6 
''Y+   	CH 	C"QvYY)F)F"68\BBH"lt$$4 		B!..s33L ?>EKR>%>>z" Bwty:N'O'O Be##'NNNcDI,H&HHNNNN%)Y%AE'NCyy>'
 
 y	 =wGGGr    c                 4    |                      |||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rp   )rz   )r   rx   r)   rq   s       r   
legend_tagzBoundField.legend_tag   s     ~~h|~JJJr    c                    t          |d          r|                                }t          |pg           }| j        r4t          | j        d          r|                    | j        j                   | j        j        r4t          | j        d          r|                    | j        j	                   d
                    |          S )zP
        Return a string of space-separated CSS classes for this field.
        spliterror_css_classrl   rn   )ru   r   setrD   r   addr   r   rt   rl   join)r   extra_classess     r   css_classeszBoundField.css_classes   s     ='** 	2)//11MM/R00; 	9749.?@@ 	9di7888: 	<7496J#K#K 	<di:;;;xx&&&r    c                 $    | j         j        j        S )z2Return True if this BoundField's widget is hidden.)r   r&   	is_hiddenr1   s    r   r   zBoundField.is_hidden   s     z **r    c                 j    | j         j        }|rdt          |          v r
|| j        z  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   s     r   r   zBoundField.auto_id   sH     )# 	"ts7||++T^++ 	">!rr    c                     | 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   rs   )r   r&   r.   s      r   rs   zBoundField.id_for_label   s>     "lt$$4""3'''r    c                 L    | j                             | j        | j                  S r4   )r   get_initial_for_fieldr   r   r1   s    r   r_   zBoundField.initial  s    y..tz49EEEr    c                    |p| j         j        }t          |          }|                    | j                  r| j         j        r| j        j        rt          | j         d          rz| j         j        snt          | j         j        t                    rOt          | j         j        |j                  D ].\  }}|                    | j                  o|j        |j        d<   /nd|d<   | j         j        rd|d<   |j        s| j        rd|d<   |                    d          sA|j                            d          s'| j         j        r| j        s| j        r| j         d|d<   |S )	Nrequire_all_fieldsrt   Tdisabledtruezaria-invalidzaria-describedby	_helptext)r   r&   dictuse_required_attributer_   rt   r   ru   r   r;   r   zipfieldswidgetsr)   r   r   rD   r*   r   use_fieldsetr   )r   r)   r&   subfield	subwidgets        r   r+   zBoundField.build_widget_attrs
  s   ,4:,U))$,77	)
#	) 	0	) 
$899)
5) tz0+>>)
 ,/tz/@&.+Q+Q  'Hi!88FF .$- OJ// %)j!: 	% $E* 	+DK 	+$*E.!
 		,--	CL$$%788	C 
$	C %		C
 	C ,0<(B(B(BE$%r    c                 z    t          j        dd| j        j        j        j                                                  S )Nzwidget$|input$r   )resubr   r&   	__class__r@   lowerr1   s    r   widget_typezBoundField.widget_type1  s4    vr4:#4#>#G#M#M#O#O
 
 	
r    c                 $    | j         j        j        S )zV
        Return the value of this BoundField widget's use_fieldset attribute.
        )r   r&   r   r1   s    r   r   zBoundField.use_fieldset7  s    
 z --r    )NNFr4   )NNNN)NNN) r@   
__module____qualname____doc__r   r	   r,   r2   r6   r9   rB   propertyrD   rG   rJ   rT   rX   rZ   r\   rO   r-   rh   rz   r~   r   r   r   rs   r_   r+   r   r   r$   r    r   r   r      sW       & & & 
 
 _
$  % % %$ $ $$ $ $ 
 
 X
 R R XR  
 
 
 
<< < < <; ; ; ;K K K K O O XO. . .; ; ;")H )H )H )HV
K 
K 
K 
K' ' ' ' + + X+ 
 
 X
 ( ( X( F F _F% % % %N 
 
 X

 . . X. . .r    r   c                   h    e Zd ZdZd Zd Zd
dZed             Zed             Z	e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                 0    || _         || _        || _        d S r4   )parent_widgetrO   r   )r   r   rO   r   s       r   r   zBoundWidget.__init__N  s    *	 r    c                 .    |                      d          S )NT)
wrap_labelr}   r1   s    r   __str__zBoundWidget.__str__S  s    xx4x(((r    Fc                 l    di | j         d|ii}| j                            | j        || j                  S )Nr&   r   )rO   r   _renderrG   r   )r   r   ry   s      r   rp   zBoundWidget.tagV  s>    D	D<DDE!))$*<gt}UUUr    c                 F    d| j         v r| j         d         S | j        j        S )NrG   )rO   r   rG   r1   s    r   rG   zBoundWidget.template_nameZ  s(    di''9_--!//r    c                 B    | j         d                             d          S )Nr)   r"   )rO   r*   r1   s    r   rs   zBoundWidget.id_for_label`  s    y!%%d+++r    c                     | j         d         S )Nr   )rO   r1   s    r   choice_labelzBoundWidget.choice_labeld  s    y!!r    N)F)r@   r   r   r   r   r   rp   r   rG   rs   r   r$   r    r   r%   r%   ?  s         ! ! !
) ) )V V V V 0 0 X0
 , , X, " " X" " "r    r%   )r   django.core.exceptionsr   django.forms.utilsr   r   django.forms.widgetsr   r   r   django.utils.functionalr	   django.utils.htmlr
   r   django.utils.translationr   rr   __all__r   r%   r$   r    r   <module>r      s	   				 2 2 2 2 2 2 @ @ @ @ @ @ @ @ A A A A A A A A A A 3 3 3 3 3 3 4 4 4 4 4 4 4 4 6 6 6 6 6 6
o. o. o. o. o.% o. o. o.d	 &" &" &" &" &" &" &" &" &" &"r    