
    Hwg                     .   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZ d Zd Zd e       z  Z G d d      Z G d de      Z G d de      Z G d dee      Z G d dee e      Z!d Z"d Z#y)    N)UserList)settings)ValidationError)get_default_renderer)timezone)RemovedInDjango50Warning)escapeformat_html_join)	mark_safe)gettext_lazy)get_docs_versionc                 H    | sy| j                  dd      j                         S )z%Convert 'first_name' to 'First name'. _ )replace
capitalize)names    I/var/www/horilla/myenv/lib/python3.12/site-packages/django/forms/utils.pypretty_namer      s"    <<S!,,..    c                    g }g }| j                         D ]A  \  }}t        |t              r|s|j                  |f       ,|/|j                  ||f       C t	        ddt        |            t	        ddt        |            z   S )a  
    Convert a dictionary of attributes to a single string.
    The returned string will contain a leading space followed by key="value",
    XML-style pairs. In the case of a boolean value, the key will appear
    without a value. It is assumed that the keys do not need to be
    XML-escaped. If the passed dictionary is empty, then return an empty
    string.

    The result is passed through 'mark_safe' (by way of 'format_html_join').
    r   z {}="{}"z {})items
isinstanceboolappendr
   sorted)attrskey_value_attrsboolean_attrsattrvalues        r   flatattr#      s     OM{{} 2eeT"$$dW-""D%=12 B
F?,CDGW
E6-(H  r   ag  The "default.html" templates for forms and formsets will be removed. These were proxies to the equivalent "table.html" templates, but the new "div.html" templates will be the default from Django 5.0. Transitional renderers are provided to allow you to opt-in to the new output style now. See https://docs.djangoproject.com/en/%s/releases/4.1/ for more detailsc                   "    e Zd Zd ZddZeZeZy)RenderableMixinc                     t        d      )NzBSubclasses of RenderableMixin must provide a get_context() method.)NotImplementedErrorselfs    r   get_contextzRenderableMixin.get_context;   s    !P
 	
r   Nc                     |xs | j                   }|xs | j                  }|xs | j                         }|dk(  s|dk(  r t        j                  t
        t        d       t        |j                  ||            S )Nzdjango/forms/default.htmlz"django/forms/formsets/default.html   )
stacklevel)	renderertemplate_namer*   warningswarn DEFAULT_TEMPLATE_DEPRECATION_MSGr   r   render)r)   r/   contextr.   templates        r   r3   zRenderableMixin.render@   sr    ,t}} 6D$6$6/T--/33??MM02JWX 7;<<r   NNN)__name__
__module____qualname__r*   r3   __str____html__ r   r   r%   r%   :   s    

= GHr   r%   c                   $    e Zd Zd Zd Zd Zd Zy)RenderableFormMixinc                 8    | j                  | j                        S )zRender as <p> elements.)r3   template_name_pr(   s    r   as_pzRenderableFormMixin.as_pR   s    {{4//00r   c                 8    | j                  | j                        S )z>Render as <tr> elements excluding the surrounding <table> tag.)r3   template_name_tabler(   s    r   as_tablezRenderableFormMixin.as_tableV   s    {{43344r   c                 8    | j                  | j                        S )z;Render as <li> elements excluding the surrounding <ul> tag.r3   template_name_ulr(   s    r   as_ulzRenderableFormMixin.as_ulZ   s    {{40011r   c                 8    | j                  | j                        S )zRender as <div> elements.)r3   template_name_divr(   s    r   as_divzRenderableFormMixin.as_div^   s    {{41122r   N)r7   r8   r9   rA   rD   rH   rK   r<   r   r   r>   r>   Q   s    1523r   r>   c                        e Zd ZddZd Zd Zy)RenderableErrorMixinc                 J    t        j                  | j                  |            S N)jsondumpsget_json_data)r)   escape_htmls     r   as_jsonzRenderableErrorMixin.as_jsond   s    zz$,,[9::r   c                 8    | j                  | j                        S rO   )r3   template_name_textr(   s    r   as_textzRenderableErrorMixin.as_textg   s    {{42233r   c                 8    | j                  | j                        S rO   rF   r(   s    r   rH   zRenderableErrorMixin.as_ulj   s    {{40011r   NF)r7   r8   r9   rT   rW   rH   r<   r   r   rM   rM   c   s    ;42r   rM   c                   H     e Zd ZdZdZdZdZdd fd
Zd Zdd	Z	d
 Z
 xZS )	ErrorDictz
    A collection of errors that knows how to display itself in various formats.

    The dictionary keys are the field names, and the values are the errors.
    z%django/forms/errors/dict/default.htmlz!django/forms/errors/dict/text.txtz django/forms/errors/dict/ul.htmlN)r.   c                J    t        |   |i | |xs
 t               | _        y rO   )super__init__r   r.   )r)   r.   argskwargs	__class__s       r   r^   zErrorDict.__init__y   s%    $)&) :$8$:r   c                 r    | j                         D ci c]  \  }}||j                          c}}S c c}}w rO   )r   as_data)r)   fes      r   rc   zErrorDict.as_data}   s*    +/::<841a199;888s   3c                 t    | j                         D ci c]  \  }}||j                  |       c}}S c c}}w rO   )r   rR   )r)   rS   rd   re   s       r   rR   zErrorDict.get_json_data   s.    <@JJLIDAq1??;//IIIs   4c                 (    | j                         ddS )N	errorlisterrorserror_class)r   r(   s    r   r*   zErrorDict.get_context   s    jjl&
 	
r   rY   )r7   r8   r9   __doc__r/   rV   rG   r^   rc   rR   r*   __classcell__ra   s   @r   r[   r[   n   s3     <M<9'+ ;9J
r   r[   c                   p     e Zd ZdZdZdZdZd fd	Zd Z fdZ	ddZ
d	 Zd
 Zd Zd Zd Z fdZ xZS )	ErrorListzU
    A collection of errors that knows how to display itself in various formats.
    z%django/forms/errors/list/default.htmlz!django/forms/errors/list/text.txtz django/forms/errors/list/ul.htmlc                     t         |   |       |d| _        ndj                  |      | _        |xs
 t	               | _        y )Nrh   zerrorlist {})r]   r^   rk   formatr   r.   )r)   initlistrk   r.   ra   s       r   r^   zErrorList.__init__   sA    "*D-44[AD :$8$:r   c                 @    t        | j                        j                  S rO   )r   data
error_listr(   s    r   rc   zErrorList.as_data   s    tyy)444r   c                 F    t         |          }| j                  |_        |S rO   )r]   copyrk   )r)   rx   ra   s     r   rx   zErrorList.copy   s!    w|~++r   c                     g }| j                         D ]E  }t        t        |            }|j                  |rt	        |      n||j
                  xs dd       G |S )Nr   )messagecode)rc   nextiterr   r	   r{   )r)   rS   rj   errorrz   s        r   rR   zErrorList.get_json_data   sY    \\^ 	E4;'GMM2=vg7!JJ,"	 r   c                      | | j                   dS )Nri   )rk   r(   s    r   r*   zErrorList.get_context   s    ++
 	
r   c                 *    t        t        |             S rO   )reprlistr(   s    r   __repr__zErrorList.__repr__   s    DJr   c                     |t        |       v S rO   r   )r)   items     r   __contains__zErrorList.__contains__   s    tDz!!r   c                     t        |       |k(  S rO   r   )r)   others     r   __eq__zErrorList.__eq__   s    DzU""r   c                 l    | j                   |   }t        |t              rt        t	        |            S |S rO   )ru   r   r   r|   r}   )r)   ir~   s      r   __getitem__zErrorList.__getitem__   s-    		!e_-U$$r   c                 :    t        t        | 
  |i |}|d d dz   S )N   )NN)r]   r   __reduce_ex__)r)   r_   r`   infora   s       r   r   zErrorList.__reduce_ex__   s,     Xt2DCFCBQx,&&r   r6   rY   )r7   r8   r9   rl   r/   rV   rG   r^   rc   rx   rR   r*   r   r   r   r   r   rm   rn   s   @r   rp   rp      sR     <M<9;5


 "#' 'r   rp   c                 n   t         j                  rx| vt        j                  |       rat        j                         }	 t        j
                  |      s!t        j                  | |      rt        d      t        j                  | |      S | S # t        $ r }t        t        d      d| |d      |d}~ww xY w)z}
    When time zone support is enabled, convert naive datetimes
    entered in the current time zone to aware datetimes.
    NzAmbiguous or non-existent time.ur   %(datetime)s couldn’t be interpreted in time zone %(current_timezone)s; it may be ambiguous or it may not exist.ambiguous_timezone)datetimecurrent_timezone)r{   params)r   USE_TZr   is_naiveget_current_timezone_is_pytz_zone _datetime_ambiguous_or_imaginary
ValueError
make_aware	Exceptionr   r   )r"   r   excs      r   from_current_timezoner      s    
 5,1B1B51I#88:	)) ;;ECST !BCC&&u.>?? L  		!<
 *$)?OP 		s   AB 	B4B//B4c                 ~    t         j                  r,| *t        j                  |       rt        j                  |       S | S )z
    When time zone support is enabled, convert aware datetimes
    to naive datetimes in the current time zone for display.
    )r   r   r   is_aware
make_naive)r"   s    r   to_current_timezoner      s3    
 5,1B1B51I""5))Lr   )$rP   r0   collectionsr   django.confr   django.core.exceptionsr   django.forms.renderersr   django.utilsr   django.utils.deprecationr   django.utils.htmlr	   r
   django.utils.safestringr   django.utils.translationr   r   django.utils.versionr   r   r#   r2   r%   r>   rM   dictr[   r   rp   r   r   r<   r   r   <module>r      s          2 7 ! = 6 - 6 1/4J
  ! .3/ 3$2? 2
* 
8B'$ 4 B'P4r   