
    g2                         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y)    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y)!r   zA Field plus datac                    || _         || _        || _        |j                  |      | _        |j                  |      | _        |j                  | j                        | _        | j                  j                  t        |      | _	        n| j                  j                  | _	        |j                  xs d| _        |j                  | _        y )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       o/var/www/python.vincentserveurtest.ovh/public_html/venv/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                  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   r   )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__1   s    r    c                 ,    t        | j                        S N)iterr'   r.   s    r   __iter__zBoundField.__iter__5   s    DOO$$r    c                 ,    t        | j                        S r1   )lenr'   r.   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__;   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   rA   zBoundField.errorsE   sF    
 yy##IItyy,,dii6H6H,I
 	
r    c                 r    | j                   j                  xs  | j                  j                  j                  S r1   )r   template_namer   r   field_template_namer.   s    r   rD   zBoundField.template_nameN   s'    zz''Q499+=+=+Q+QQr    c                 
    d| iS )Nr   r-   r.   s    r   get_contextzBoundField.get_contextR   s    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#   only_initialr(   s        r   	as_widgetzBoundField.as_widgetU   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">.
        )rQ   r   r   r#   kwargss      r   as_textzBoundField.as_texts   s     t~~ik5;F;;r    c                 :     | j                   t               |fi |S )z>Return a string of HTML for representing this as a <textarea>.)rQ   r   rS   s      r   as_textareazBoundField.as_textareay   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">.
        )rQ   r   rN   rS   s      r   	as_hiddenz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r,   )r   show_hidden_initialrN   r   rM   r   	to_pythonr   r\   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hasattrri   boolrO   template_name_label)	r   contentsr#   rn   rm   r$   r*   rp   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rm   )rw   )r   ru   r#   rn   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_classri   rk   )rr   r}   setrA   r   addr~   r   rq   ri   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   rp   )r   r$   r*   s      r   rp   zBoundField.id_for_label   sA     ""llt$4""3''r    c                 b    | j                   j                  | j                  | j                        S r1   )r   get_initial_for_fieldr   r   r.   s    r   r\   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<   |j                   s| j"                  rd|d<   |j%                  d      sg|j                  j%                  d      sL| j                   j&                  r6| j(                  s*| j*                  r| j                   s| j*                   d|d<   |S )	Nrequire_all_fieldsrq   Tdisabledtruezaria-invalidzaria-describedby	_helptext)r   r$   dictuse_required_attributer\   rq   r   rr   r   r8   r   zipfieldswidgetsr#   r   r   rA   r%   r   use_fieldsetr   )r   r#   r$   subfield	subwidgets        r   r&   zBoundField.build_widget_attrs
  sm   ,4::,,U))$,,7

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

$89

55tzz00+>+.tzz/@/@&..+Q'Hi!88F .$-- OOJ/ ,R %)j!:: $E*DKK$*E.!
 		,-LL$$%78

$$%%NN+/<<.	(BE$%r    c                     t        j                  dd| j                  j                  j                  j
                  j                               S )Nzwidget$|input$r   )resubr   r$   	__class__r=   lowerr.   s    r   widget_typezBoundField.widget_type2  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$   r   r.   s    r   r   zBoundField.use_fieldset8  s    
 zz  ---r    )NNFr1   )NNNN)NNN) r=   
__module____qualname____doc__r   r	   r'   r/   r3   r6   r?   propertyrA   rD   rG   rQ   rU   rW   rY   rL   r(   re   rw   r{   r   r   r   rp   r\   r&   r   r   r-   r    r   r   r      s(   & 
 
$%$$ 
 
 R R
<<;K O O.;")HV
K' + + 
 
 ( ( F F&P 
 

 . .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 r1   )parent_widgetrL   r   )r   r   rL   r   s       r   r   zBoundWidget.__init__O  s    *	 r    c                 &    | j                  d      S )NT)
wrap_labelrz   r.   s    r   __str__zBoundWidget.__str__T  s    xx4x((r    c                     di | j                   d|ii}| j                  j                  | j                  || j                        S )Nr$   r   )rL   r   _renderrD   r   )r   r   rv   s      r   rm   zBoundWidget.tagW  sB    D		D<DE!!))$*<*<gt}}UUr    c                 h    d| j                   v r| j                   d   S | j                  j                  S )NrD   )rL   r   rD   r.   s    r   rD   zBoundWidget.template_name[  s/    dii'99_--!!///r    c                 >    | j                   d   j                  d      S )Nr#   r"   )rL   r%   r.   s    r   rp   zBoundWidget.id_for_labela  s    yy!%%d++r    c                      | j                   d   S )Nr   )rL   r.   s    r   choice_labelzBoundWidget.choice_labele  s    yy!!r    N)F)r=   r   r   r   r   r   rm   r   rD   rp   r   r-   r    r   r)   r)   @  sS    !
)V 0 0
 , , " "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   ro   __all__r   r)   r-   r    r   <module>r      sK    	 2 @ A A 3 4 6
p.% p.f	 &" &" &"r    