
    h(                         d dl Z d dlZd dlmZmZ d dlmZ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 dZe G d	 d
             Ze G d d             Zy)    N)flatattpretty_name)Textarea	TextInput)cached_property)conditional_escapeformat_html	html_safe)	mark_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dZddZed        Zed        Zed        Zed        Zd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       Z/var/www/html/ranktracker/api/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                  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6t~~tzz|[`6a
 

))64993E3EF
 	
 
s   <Cc                      y)NT r%   s    r   __bool__zBoundField.__bool__5   s    r   c                 ,    t        | j                        S N)iterr-   r%   s    r   __iter__zBoundField.__iter__9   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__?   sE     #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   errorsr+   r   error_classr%   s    r   rF   zBoundField.errorsI   s2    
 yy##DIItyy/D/D/FGGr   Nc                    |xs | j                   j                  }| j                   j                  rd|_        |xs i }| j	                  ||      }| j
                  r8d|j                  vr*|j                  d|r| j                  n| j
                         |j                  |r| j                  n| j                  | 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)   r0   )r   r*   localizeis_localizedr,   r   r)   
setdefaultr   renderr   r   r.   r   r0   )r   r*   r)   r!   s       r   r#   zBoundField.as_widgetP   s     ,4::,,::"&F''v6<<D4T<4#7#7T\\Z}}+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_textd   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   rN   s      r   as_textareazBoundField.as_textareaj   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   hidden_widgetrN   s      r   r$   zBoundField.as_hiddenn   s)     t~~djj668%J6JJr   c                     | j                   j                  j                  | j                  j                  | j                  j
                  | j                        S )zR
        Return the data for this BoundField, or None if it wasn't given.
        )r   r*   value_from_datadictr   datafilesr   r%   s    r   rW   zBoundField.datat   s:    
 zz  44TYY^^TYY__VZVdVdeer   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_datarW   prepare_valuer   rW   s     r   r.   zBoundField.value{   sI    
 ||99::((D9Dzz''--r   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<   |rt        |      nd	}t        d
||      }t!        |      S t        |      }t!        |      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   z<label{}>{}</label>)r   r   label_suffixr   _r	   r*   r)   r+   r   id_for_labelrequiredhasattrrb   r   r   r   )r   contentsr)   re   r*   r1   rg   s          r   	label_tagzBoundField.label_tag   s]    )tzz7;zz7N7N7ZDJJ33!%!7!7 
 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&+GENE"#8%JH "" *(3H""r   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_classrb   rd   )ri   rm   setrF   r   addrn   r   rh   rb   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   ru   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   rg   )r   r*   r1   s      r   rg   zBoundField.id_for_label   sA     ""llt$4""3''r   c                    | j                   j                  | j                  | j                        }t	        |t
        j
                  t
        j                  f      r2| j                  j                  j                  s|j                  d      }|S )Nr   )microsecond)
r   get_initial_for_fieldr   r   r=   datetimetimer*   supports_microsecondsreplacer^   s     r   rZ   zBoundField.initial   sc    yy..tzz499E th//?@JJ%%;;<<A<.Dr   c                    |xs | j                   j                  }t        |      }|j                  | j                        r1| j                   j
                  r| j                  j                  rd|d<   | j                   j                  rd|d<   |S )NTrh   disabled)r   r*   dictuse_required_attributerZ   rh   r   r   )r   r)   r*   s      r   r,   zBoundField.build_widget_attrs   sr    ,4::,,U((64::;N;NSWS\S\SsSs $E*:: $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   s5    vv'TZZ->->-H-H-Q-Q-W-W-YZZr   )NNFr6   )NNN)rB   
__module____qualname____doc__r   r&   r   r-   r4   r8   r;   rD   propertyrF   r#   rP   rR   r$   rW   r.   rk   rs   ru   r   rg   rZ   r,   r   r3   r   r   r   r      s    /  
 
 %$$ H H
(<;K f f.##J' + + 
 
 ( (   [ [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_widgetrW   r0   )r   r   rW   r0   s       r   r   zBoundWidget.__init__   s    *	 r   c                 &    | j                  d      S )NT)
wrap_label)tagr%   s    r   r&   zBoundWidget.__str__   s    xx4x((r   c                     di | j                   d|ii}| j                  j                  | j                  || j                        S )Nr*   r   )rW   r   _rendertemplate_namer0   )r   r   contexts      r   r   zBoundWidget.tag  sB    D		D<DE!!))$*<*<gt}}UUr   c                 h    d| j                   v r| j                   d   S | j                  j                  S )Nr   )rW   r   r   r%   s    r   r   zBoundWidget.template_name  s/    dii'99_--!!///r   c                 F    d| j                   d   d| j                   d   S )Nr1   r   rf   indexrW   r%   s    r   rg   zBoundWidget.id_for_label  s    !YYv.		'0BCCr   c                      | j                   d   S )Nr   r   r%   s    r   choice_labelzBoundWidget.choice_label  s    yy!!r   N)F)rB   r   r   r   r   r&   r   r   r   rg   r   r3   r   r   r/   r/      sU    !
)V 0 0
 D D " "r   r/   )r|   r   django.forms.utilsr   r   django.forms.widgetsr   r   django.utils.functionalr   django.utils.htmlr   r	   r
   django.utils.safestringr   django.utils.translationr   rf   __all__r   r/   r3   r   r   <module>r      s^     	 3 4 3 H H - 6
 Z[ Z[ Z[z %" %" %"r   