o
    `Zh                     @   s   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mZ d dlmZ d d	lmZ d
d Zdd ZG dd dZG dd deZG dd deZG dd deZG dd deeZG dd deeeZdd Zdd ZdS )    N)UserList)settings)ValidationError)get_default_renderer)timezone)escapeformat_html_join)	mark_safe)gettext_lazyc                 C   s   | sdS |  dd S )z%Convert 'first_name' to 'First name'. _ )replace
capitalize)name r   I/var/www/html/lang_env/lib/python3.10/site-packages/django/forms/utils.pypretty_name   s   r   c                 C   sl   g }g }|   D ]\}}t|tr|r||f q|dur%|||f qtddt|tddt| 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').
    Nr   z {}="{}"z {})items
isinstanceboolappendr   sorted)attrsZkey_value_attrsboolean_attrsattrvaluer   r   r   flatatt   s   

r   c                   @   s&   e Zd Zdd ZdddZeZeZdS )RenderableMixinc                 C      t d)NzBSubclasses of RenderableMixin must provide a get_context() method.NotImplementedErrorselfr   r   r   get_context.      zRenderableMixin.get_contextNc                 C   s0   |p| j }|p	| j}|p|  }t|||S N)renderertemplate_namer$   r	   render)r#   r(   contextr'   templater   r   r   r)   3   s   

zRenderableMixin.renderNNN)__name__
__module____qualname__r$   r)   __str____html__r   r   r   r   r   -   s
    
r   c                   @   s0   e Zd Zdd Zdd Zdd Zdd ZeZd	S )
RenderableFieldMixinc                 C   s   |   S r&   )r)   r"   r   r   r   as_field_group>   s   z#RenderableFieldMixin.as_field_groupc                 C   r   )NzFSubclasses of RenderableFieldMixin must provide an as_hidden() method.r    r"   r   r   r   	as_hiddenA   r%   zRenderableFieldMixin.as_hiddenc                 C   r   )NzFSubclasses of RenderableFieldMixin must provide an as_widget() method.r    r"   r   r   r   	as_widgetF   r%   zRenderableFieldMixin.as_widgetc                 C   s$   | j jr|  | jdd S |  S )z$Render this field as an HTML widget.T)Zonly_initial)fieldZshow_hidden_initialr5   r4   r"   r   r   r   r0   K   s   zRenderableFieldMixin.__str__N)r-   r.   r/   r3   r4   r5   r0   r1   r   r   r   r   r2   =   s    r2   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
RenderableFormMixinc                 C      |  | jS )zRender as <p> elements.)r)   Ztemplate_name_pr"   r   r   r   as_pU      zRenderableFormMixin.as_pc                 C   r8   )z>Render as <tr> elements excluding the surrounding <table> tag.)r)   Ztemplate_name_tabler"   r   r   r   as_tableY   r:   zRenderableFormMixin.as_tablec                 C   r8   )z;Render as <li> elements excluding the surrounding <ul> tag.r)   template_name_ulr"   r   r   r   as_ul]   r:   zRenderableFormMixin.as_ulc                 C   r8   )zRender as <div> elements.)r)   Ztemplate_name_divr"   r   r   r   as_diva   r:   zRenderableFormMixin.as_divN)r-   r.   r/   r9   r;   r>   r?   r   r   r   r   r7   T   s
    r7   c                   @   s&   e Zd Zd	ddZdd Zdd ZdS )
RenderableErrorMixinFc                 C   s   t | |S r&   )jsondumpsget_json_datar#   escape_htmlr   r   r   as_jsong   s   zRenderableErrorMixin.as_jsonc                 C   r8   r&   )r)   template_name_textr"   r   r   r   as_textj      zRenderableErrorMixin.as_textc                 C   r8   r&   r<   r"   r   r   r   r>   m   rI   zRenderableErrorMixin.as_ulNF)r-   r.   r/   rF   rH   r>   r   r   r   r   r@   f   s    
r@   c                       sL   e Zd ZdZdZdZdZdd fdd
Zd	d
 ZdddZ	dd Z
  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                   s"   t  j|i | |pt | _d S r&   )super__init__r   r'   )r#   r'   argskwargs	__class__r   r   rM   |   s   zErrorDict.__init__c                 C   s   dd |   D S )Nc                 S   s   i | ]	\}}||  qS r   )as_data.0fer   r   r   
<dictcomp>   s    z%ErrorDict.as_data.<locals>.<dictcomp>r   r"   r   r   r   rR      s   zErrorDict.as_dataFc                    s    fdd|   D S )Nc                    s   i | ]
\}}||  qS r   )rC   rS   rE   r   r   rW      s    z+ErrorDict.get_json_data.<locals>.<dictcomp>rX   rD   r   rY   r   rC      s   zErrorDict.get_json_datac                 C   s   |   ddS )N	errorlisterrorserror_classrX   r"   r   r   r   r$      s   zErrorDict.get_contextrJ   )r-   r.   r/   __doc__r(   rG   r=   rM   rR   rC   r$   __classcell__r   r   rP   r   rK   q   s    
rK   c                       s   e Zd ZdZdZdZdZd fdd	Zdd	 Z fd
dZ	dddZ
dd Zdd Zdd Zdd Zdd Z fddZ  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.htmlNc                    s8   t  | |d u rd| _nd|| _|pt | _d S )NrZ   zerrorlist {})rL   rM   r]   formatr   r'   )r#   initlistr]   r'   rP   r   r   rM      s
   zErrorList.__init__c                 C   s   t | jjS r&   )r   dataZ
error_listr"   r   r   r   rR      rI   zErrorList.as_datac                    s   t   }| j|_|S r&   )rL   copyr]   )r#   rd   rP   r   r   rd      s   
zErrorList.copyFc                 C   sD   g }|   D ]}tt|}||rt|n||jpdd q|S )Nr   )messagecode)rR   nextiterr   r   rf   )r#   rE   r\   errorre   r   r   r   rC      s   zErrorList.get_json_datac                 C   s   | | j dS )Nr[   )r]   r"   r   r   r   r$      s   zErrorList.get_contextc                 C   s   t t| S r&   )reprlistr"   r   r   r   __repr__   rI   zErrorList.__repr__c                 C   s   |t | v S r&   rk   )r#   itemr   r   r   __contains__   rI   zErrorList.__contains__c                 C   s   t | |kS r&   rm   )r#   otherr   r   r   __eq__   rI   zErrorList.__eq__c                 C   s$   | j | }t|trtt|S |S r&   )rc   r   r   rg   rh   )r#   iri   r   r   r   __getitem__   s   

zErrorList.__getitem__c                    s&   t t| j|i |}|d d d S )N   )NN)rL   r   __reduce_ex__)r#   rN   rO   inforP   r   r   ru      s   zErrorList.__reduce_ex__r,   rJ   )r-   r.   r/   r^   r(   rG   r=   rM   rR   rd   rC   r$   rl   ro   rq   rs   ru   r_   r   r   rP   r   r`      s    	
r`   c              
   C   sz   t jr;| dur;t| r;t }zt| |rtdt| |W S  ty: } zt	t
dd| |dd|d}~ww | S )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.Zambiguous_timezone)datetimecurrent_timezone)rf   params)r   USE_TZr   Zis_naiveZget_current_timezoneZ _datetime_ambiguous_or_imaginary
ValueErrorZ
make_aware	Exceptionr   r   )r   rx   excr   r   r   from_current_timezone   s&   
r~   c                 C   s&   t jr| durt| rt| S | S )z
    When time zone support is enabled, convert aware datetimes
    to naive datetimes in the current time zone for display.
    N)r   rz   r   Zis_awareZ
make_naive)r   r   r   r   to_current_timezone   s   
r   )rA   collectionsr   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.forms.renderersr   Zdjango.utilsr   Zdjango.utils.htmlr   r   Zdjango.utils.safestringr	   Zdjango.utils.translationr
   r   r   r   r   r2   r7   r@   dictrK   rk   r`   r~   r   r   r   r   r   <module>   s&    H