o
    <g                     @   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   E/var/www/html/venv/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)attrs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)only_initial)fieldshow_hidden_initialr6   r5   r#   r   r   r   r1   K   s   zRenderableFieldMixin.__str__N)r.   r/   r0   r4   r5   r6   r1   r2   r   r   r   r   r3   =   s    r3   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*   template_name_pr#   r   r   r   as_pU      zRenderableFormMixin.as_pc                 C   r;   )z>Render as <tr> elements excluding the surrounding <table> tag.)r*   template_name_tabler#   r   r   r   as_tableY   r>   zRenderableFormMixin.as_tablec                 C   r;   )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   r;   )zRender as <div> elements.)r*   template_name_divr#   r   r   r   as_diva   r>   zRenderableFormMixin.as_divN)r.   r/   r0   r=   r@   rC   rE   r   r   r   r   r:   T   s
    r:   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   r;   r'   )r*   template_name_textr#   r   r   r   as_textj      zRenderableErrorMixin.as_textc                 C   r;   r'   rA   r#   r   r   r   rC   m   rO   zRenderableErrorMixin.as_ulNF)r.   r/   r0   rL   rN   rC   r   r   r   r   rF   f   s    
rF   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   rS   |   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   rX      s   zErrorDict.as_dataFc                    s    fdd|   D S )Nc                    s   i | ]
\}}||  qS r   )rI   rY   rK   r   r   r]      s    z+ErrorDict.get_json_data.<locals>.<dictcomp>r^   rJ   r   r_   r   rI      s   zErrorDict.get_json_datac                 C   s   |   ddS )N	errorlisterrorserror_classr^   r#   r   r   r   r%      s   zErrorDict.get_contextrP   )r.   r/   r0   __doc__r)   rM   rB   rS   rX   rI   r%   __classcell__r   r   rV   r   rQ   q   s    
rQ   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 )Nr`   zerrorlist {})rR   rS   rc   formatr   r(   )r$   initlistrc   r(   rV   r   r   rS      s
   zErrorList.__init__c                 C   s   t | jjS r'   )r   data
error_listr#   r   r   r   rX      rO   zErrorList.as_datac                    s   t   }| j|_|S r'   )rR   copyrc   )r$   rk   rV   r   r   rk      s   
zErrorList.copyFc                 C   sD   g }|   D ]}tt|}||rt|n||jpdd q|S )Nr   )messagecode)rX   nextiterr   r   rm   )r$   rK   rb   errorrl   r   r   r   rI      s   zErrorList.get_json_datac                 C   s   | | j dS )Nra   )rc   r#   r   r   r   r%      s   zErrorList.get_contextc                 C   s   t t| S r'   )reprlistr#   r   r   r   __repr__   rO   zErrorList.__repr__c                 C   s   |t | v S r'   rr   )r$   itemr   r   r   __contains__   rO   zErrorList.__contains__c                 C   s   t | |kS r'   rt   )r$   otherr   r   r   __eq__   rO   zErrorList.__eq__c                 C   s$   | j | }t|trtt|S |S r'   )ri   r   r   rn   ro   )r$   irp   r   r   r   __getitem__   s   

zErrorList.__getitem__c                    s&   t t| j|i |}|d d d S )N   )NN)rR   r   __reduce_ex__)r$   rT   rU   inforV   r   r   r|      s   zErrorList.__reduce_ex__r-   rP   )r.   r/   r0   rd   r)   rM   rB   rS   rX   rk   rI   r%   rs   rv   rx   rz   r|   re   r   r   rV   r   rf      s    	
rf   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.ambiguous_timezone)datetimecurrent_timezone)rm   params)r   USE_TZr   is_naiveget_current_timezone _datetime_ambiguous_or_imaginary
ValueError
make_aware	Exceptionr   r   )r   r   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   r   r   is_aware
make_naive)r   r   r   r   to_current_timezone   s   
r   )rG   collectionsr   django.confr   django.core.exceptionsr   django.forms.renderersr   django.utilsr   django.utils.htmlr   r   django.utils.safestringr	   django.utils.translationr
   r   r   r   r   r3   r:   rF   dictrQ   rr   rf   r   r   r   r   r   r   <module>   s&    H