
    Hwg80                         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y)    N)ValidationError)pretty_name)MultiWidgetTextarea	TextInput)cached_property)format_html	html_safe)gettext_lazy)
BoundFieldc                      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y
) r   zA Field plus datac                 t   || _         || _        || _        |j                  |      | _        |j                  |      | _        |j                  | j                        | _        | j                  j                  t        |      | _	        n| j                  j                  | _	        |j                  xs d| _        y )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       N/var/www/horilla/myenv/lib/python3.12/site-packages/django/forms/boundfield.py__init__zBoundField.__init__   s    	
	.!%!8!8!>#66t||D::#$T*DJ))DJ.B    c                     | j                   j                  r#| j                         | j                  d      z   S | j                         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__   s9    ::))>>#dnn$n&GGG~~r   c                    | j                   j                  j                  j                  d      xs | j                  }|rd|ini }| j                  |      }| j                   j                  j                  | j                  | j                         |      D cg c]7  }t        | j                   j                  || j                  j                        9 c}S c c}w )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.
        id)attrs)r   widgetr(   getr   build_widget_attrs
subwidgetsr   valueBoundWidgetr   renderer)r   id_r(   r)   s       r   r,   zBoundField.subwidgets$   s     jj%%))$/?4<<"s''. **++66

E 7 
 

))64993E3EF
 	
 
s   <Cc                      yNT r$   s    r   __bool__zBoundField.__bool__7   s    r   c                 ,    t        | j                        S N)iterr,   r$   s    r   __iter__zBoundField.__iter__;   s    DOO$$r   c                 ,    t        | j                        S r6   )lenr,   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__r,   )r   idxs     r   __getitem__zBoundField.__getitem__A   sE     #U|,Hs)$$%  s##r   c                     | j                   j                  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/   r$   s    r   rF   zBoundField.errorsK   sF    
 yy##IItyy,,dii6H6H,I
 	
r   Nc                    |xs | j                   j                  }| j                   j                  rd|_        |xs i }| j	                  ||      }| j
                  r8d|j                  vr*|j                  d|r| j                  n| j
                         |ra| j                  | j                  j                  v r?| j                  j                  | j                   j                         | j                        }n| j                         }|j                  |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(   r    r-   s        r   r"   zBoundField.as_widgetT   s	    ,4::,,::"&F''v6<<D4ld** D22diinnDII00

((*&&E
 JJLE}}+7''T^^YY''	  
 	
r   c                 :     | 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~~ik5;F;;r   c                 :     | j                   t               |fi |S )z>Return a string of HTML for representing this as a <textarea>.)r"   r   rQ   s      r   as_textareazBoundField.as_textareax   s    t~~hj%:6::r   c                 Z     | j                   | j                  j                         |fi |S )z\
        Return a string of HTML for representing this as an <input type="hidden">.
        )r"   r   rN   rQ   s      r   r#   zBoundField.as_hidden|   s)     t~~djj668%J6JJr   c                 v    | j                   j                  | j                  j                  | j                        S )zR
        Return the data for this BoundField, or None if it wasn't given.
        )r   rM   r   r)   r   r$   s    r   rL   zBoundField.data   s)    
 yy++DJJ,=,=t~~NNr   c                     | j                   }| j                  j                  r&| j                  j	                  | 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_datarL   prepare_value)r   rL   s     r   r-   zBoundField.value   sI    
 ||99::((D9Dzz''--r   c                 2   | j                   }|j                  rI|j                         }| j                  j	                  || j
                        }	 |j                  |      }n| j                  }|j                  || j                        S # t        $ r Y yw xY wr2   )r   r!   rN   r   rM   r   	to_pythonr   rY   has_changedrL   )r   r   rN   initial_values       r   _has_changedzBoundField._has_changed   s    

$$!//1M II88&&M % >
 !LLM  		:: # s   B
 
	BBc                    |xs | j                   }|B| j                  j                  | j                  j                  n| j                  j                  }|r|r|d   t	        d      vrt        d||      }| j                  j                  }|j                  j                  d      xs | j                  }|r|j                  |      }|ri |xs i d|i}| j                  j                  r^t        | j                  d      rH|xs i }d|v r%|dxx   d| j                  j                  z   z  cc<   n| j                  j                  |d<   | ||t        |      |xs d	d
}| j                  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.
        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hasattrre   boolrO   template_name_label)	r   contentsr(   rj   ri   r)   r0   rl   contexts	            r   	label_tagzBoundField.label_tag   sc    )tzz ::**6 

''YY++  H"QvY)F"68\BH""llt$4!..s3L>EKR>%>zz""wtyy:N'Oe#'NcDII,H,H&HHN%)YY%A%AE'NCy>'
 yy		 = =wGGr   c                 ,    | j                  |||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ri   )rs   )r   rq   r(   rj   s       r   
legend_tagzBoundField.legend_tag   s     ~~h|~JJr   c                    t        |d      r|j                         }t        |xs g       }| j                  r;t        | j                  d      r%|j                  | j                  j                         | j                  j                  r;t        | j                  d      r%|j                  | j                  j                         dj                  |      S )zP
        Return a string of space-separated CSS classes for this field.
        spliterror_css_classre   rg   )rn   ry   setrF   r   addrz   r   rm   re   join)r   extra_classess     r   css_classeszBoundField.css_classes   s     ='*)//1MM/R0;;7499.?@dii778::74996J#Kdii::;xx&&r   c                 B    | 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     zz  ***r   c                     | j                   j                  }|rdt        |      v r|| j                  z  S |r| j                  S y)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   s@     ))##ts7|+T^^++>>!r   c                     | j                   j                  }|j                  j                  d      xs | 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   rl   )r   r)   r0   s      r   rl   zBoundField.id_for_label   sA     ""llt$4""3''r   c                 b    | j                   j                  | j                  | j                        S r6   )r   get_initial_for_fieldr   r   r$   s    r   rY   zBoundField.initial  s!    yy..tzz499EEr   c                    |xs | j                   j                  }t        |      }|j                  | j                        r| j                   j
                  r| j                  j                  rt        | j                   d      r| j                   j                  st        | j                   j                  t              rit        | j                   j                  |j                        D ];  \  }}|j                  | j                        xr |j
                  |j                  d<   = nd|d<   | j                   j                  rd|d<   |S )Nrequire_all_fieldsrm   Tdisabled)r   r)   dictuse_required_attributerY   rm   r   rn   r   r=   r   zipfieldswidgetsr(   r   )r   r(   r)   subfield	subwidgets        r   r+   zBoundField.build_widget_attrs	  s    ,4::,,U))$,,7

##		00
 

$89

55tzz00+>+.tzz/@/@&..+Q 'Hi!88F .$-- OOJ/ %)j!:: $E*r   c                     t        j                  dd| j                  j                  j                  j
                  j                               S )Nzwidget$|input$r   )resubr   r)   	__class__rB   lowerr$   s    r   widget_typezBoundField.widget_type#  s9    vvr4::#4#4#>#>#G#G#M#M#O
 	
r   c                 B    | 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    
 zz  ---r   )NNFr6   )NNNN)NNN)rB   
__module____qualname____doc__r   r%   r   r,   r4   r8   r;   rD   propertyrF   r"   rS   rU   r#   rL   r-   ra   rs   rw   r   r   r   rl   rY   r+   r   r   r3   r   r   r   r      s   /  
 
$%$$ 
 

<<;K O O.;")HV
K' + + 
 
 ( ( F F4 
 

 . .r   r   c                   T    e Zd ZdZd Zd Zd	dZed        Zed        Z	ed        Z
y)
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                 .    || _         || _        || _        y r6   )parent_widgetrL   r/   )r   r   rL   r/   s       r   r   zBoundWidget.__init__@  s    *	 r   c                 &    | j                  d      S )NT)
wrap_labelrv   r$   s    r   r%   zBoundWidget.__str__E  s    xx4x((r   c                     di | j                   d|ii}| j                  j                  | j                  || j                        S )Nr)   r   )rL   r   _rendertemplate_namer/   )r   r   rr   s      r   ri   zBoundWidget.tagH  sB    D		D<DE!!))$*<*<gt}}UUr   c                 h    d| j                   v r| j                   d   S | j                  j                  S )Nr   )rL   r   r   r$   s    r   r   zBoundWidget.template_nameL  s/    dii'99_--!!///r   c                 >    | j                   d   j                  d      S )Nr(   r'   )rL   r*   r$   s    r   rl   zBoundWidget.id_for_labelR  s    yy!%%d++r   c                      | j                   d   S )Nr   )rL   r$   s    r   choice_labelzBoundWidget.choice_labelV  s    yy!!r   N)F)rB   r   r   r   r   r%   ri   r   r   rl   r   r3   r   r   r.   r.   1  sS    !
)V 0 0
 , , " "r   r.   )r   django.core.exceptionsr   django.forms.utilsr   django.forms.widgetsr   r   r   django.utils.functionalr   django.utils.htmlr	   r
   django.utils.translationr   rk   __all__r   r.   r3   r   r   <module>r      sX    	 2 * A A 3 4 6
 `. `. `.F	 &" &" &"r   