
     h80                         d dl 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
 d dlmZmZ d dlmZ dZe G d	 d
                      Ze G d d                      ZdS )    N)ValidationError)pretty_name)MultiWidgetTextarea	TextInput)cached_property)format_html	html_safe)gettext_lazy)
BoundFieldc                   H   e Zd ZdZd Zd Zed             Zd Zd Z	d Z
d Ze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                 V   || _         || _        || _        |                    |          | _        |                    |          | _        |                    | j                  | _        | j        j	        t          |          | _	        n| j        j	        | _	        |j        pd| _        d S )N )formfieldname
add_prefix	html_nameadd_initial_prefixhtml_initial_nameauto_idhtml_initial_idlabelr   	help_text)selfr   r   r   s       V/var/www/surfInsights/venv3-11/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        r+|                                 |                     d          z   S |                                 S )z$Render this field as an HTML widget.T)only_initial)r   show_hidden_initial	as_widget	as_hiddenr   s    r   __str__zBoundField.__str__   sC    :) 	H>>##dnn$n&G&GGG~~r   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   renderer).0r+   r   s     r   
<listcomp>z)BoundField.subwidgets.<locals>.<listcomp>0   s?     
 
 
 
)6493EFF
 
 
r   )attrs)	r   r+   r/   getr   build_widget_attrs
subwidgetsr   value)r   id_r/   s   `  r   r2   zBoundField.subwidgets$   s     j%))$//?4<"*s''..
 
 
 
*+66

E 7  
 
 
 	
r   c                     dS NTr)   r$   s    r   __bool__zBoundField.__bool__7   s    tr   c                 *    t          | j                  S N)iterr2   r$   s    r   __iter__zBoundField.__iter__;   s    DO$$$r   c                 *    t          | j                  S r9   )lenr2   r$   s    r   __len__zBoundField.__len__>   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__r2   )r   idxs     r   __getitem__zBoundField.__getitem__A   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   errorsr0   r   error_classr,   r$   s    r   rI   zBoundField.errorsK   s@    
 y##Ity,,di6H,II
 
 	
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   r3   r/   r,   )r   r+   localizeis_localizedr1   r   r/   
setdefaultr   r   r   data_widget_data_valuehidden_widgetr3   renderr   r,   )r   r+   r/   r    r3   s        r   r"   zBoundField.as_widgetT   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">.
        )r"   r   r   r/   kwargss      r   as_textzBoundField.as_textr   s$     t~ikk5;;F;;;r   c                 8     | j         t                      |fi |S )z>Return a string of HTML for representing this as a <textarea>.)r"   r   rT   s      r   as_textareazBoundField.as_textareax   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">.
        )r"   r   rQ   rT   s      r   r#   z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   r$   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   r3   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 r6   )r   r!   rQ   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/   r0   r   id_for_labelrequiredhasattrrh   boolrR   template_name_label)	r   contentsr/   rm   rl   r+   r4   ro   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rl   )rv   )r   rt   r/   rm   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_classrh   rj   )rq   r|   setrI   r   addr}   r   rp   rh   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_hiddenr$   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/   r0   r   ro   )r   r+   r4   s      r   ro   zBoundField.id_for_label   s>     "lt$$4""3'''r   c                 L    | j                             | j        | j                  S r9   )r   get_initial_for_fieldr   r   r$   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<   |S )Nrequire_all_fieldsrp   Tdisabled)r   r+   dictuse_required_attributer\   rp   r   rq   r   r@   r   zipfieldswidgetsr/   r   )r   r/   r+   subfield	subwidgets        r   r1   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*r   c                 z    t          j        dd| j        j        j        j                                                  S )Nzwidget$|input$r   )resubr   r+   	__class__rE   lowerr$   s    r   widget_typezBoundField.widget_type#  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+   use_fieldsetr$   s    r   r   zBoundField.use_fieldset)  s    
 z --r   )NNFr9   )NNNN)NNN)rE   
__module____qualname____doc__r   r%   r   r2   r7   r;   r>   rG   propertyrI   r"   rV   rX   r#   rO   r3   rd   rv   rz   r   r   r   ro   r\   r1   r   r   r)   r   r   r   r      s8       / / /      
 
 _
$  % % %$ $ $$ $ $ 
 
 X

 
 
 
<< < < <; ; ; ;K K K K O O XO. . .; ; ;")H )H )H )HV
K 
K 
K 
K' ' ' ' + + X+ 
 
 X
 ( ( X( F F _F   4 
 
 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 r9   )parent_widgetrO   r,   )r   r   rO   r,   s       r   r   zBoundWidget.__init__@  s    *	 r   c                 .    |                      d          S )NT)
wrap_labelry   r$   s    r   r%   zBoundWidget.__str__E  s    xx4x(((r   Fc                 l    di | j         d|ii}| j                            | j        || j                  S )Nr+   r   )rO   r   _rendertemplate_namer,   )r   r   ru   s      r   rl   zBoundWidget.tagH  s>    D	D<DDE!))$*<gt}UUUr   c                 F    d| j         v r| j         d         S | j        j        S )Nr   )rO   r   r   r$   s    r   r   zBoundWidget.template_nameL  s(    di''9_--!//r   c                 B    | j         d                             d          S )Nr/   r'   )rO   r0   r$   s    r   ro   zBoundWidget.id_for_labelR  s    y!%%d+++r   c                     | j         d         S )Nr   )rO   r$   s    r   choice_labelzBoundWidget.choice_labelV  s    y!!r   N)F)rE   r   r   r   r   r%   rl   r   r   ro   r   r)   r   r   r*   r*   1  s         ! ! !
) ) )V V V V 0 0 X0
 , , X, " " X" " "r   r*   )r   django.core.exceptionsr   django.forms.utilsr   django.forms.widgetsr   r   r   django.utils.functionalr   django.utils.htmlr	   r
   django.utils.translationr   rn   __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
 `. `. `. `. `. `. `. `.F	 &" &" &" &" &" &" &" &" &" &"r   