o
    ^"<fl                     @   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
mZmZmZ d dlmZ dd	 Zd
d ZeG dd deZeG dd deeZdd Zdd ZdS )    N)UserList)settings)ValidationError)timezone)escapeformat_htmlformat_html_join	html_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/kck/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                   @   sD   e Zd ZdZdd ZdddZdddZd	d
 Zdd Zdd Z	d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.
    c                 C   s   dd |   D S )Nc                 S   s   i | ]	\}}||  qS r   )as_data.0fer   r   r   
<dictcomp>4   s    z%ErrorDict.as_data.<locals>.<dictcomp>r   selfr   r   r   r    3   s   zErrorDict.as_dataFc                    s    fdd|   D S )Nc                    s   i | ]
\}}||  qS r   )get_json_datar!   escape_htmlr   r   r%   7   s    z+ErrorDict.get_json_data.<locals>.<dictcomp>r&   r(   r+   r   r*   r   r)   6   s   zErrorDict.get_json_datac                 C      t | |S Njsondumpsr)   r,   r   r   r   as_json9      zErrorDict.as_jsonc                 C   s   | sdS t dtdd|  S )Nr   z<ul class="errorlist">{}</ul>z<li>{}{}</li>)r   r   r   r'   r   r   r   as_ul<   s   zErrorDict.as_ulc                 C   sH   g }|   D ]\}}|d|  |ddd |D  qd|S )N* %s
c                 s       | ]}d | V  qdS )z  * %sNr   r"   r$   r   r   r   	<genexpr>H       z$ErrorDict.as_text.<locals>.<genexpr>)r   r   join)r(   outputfielderrorsr   r   r   as_textD   s
   
zErrorDict.as_textc                 C      |   S r.   r4   r'   r   r   r   __str__K      zErrorDict.__str__NF)
__name__
__module____qualname____doc__r    r)   r2   r4   r?   rB   r   r   r   r   r   ,   s    

r   c                       s   e Zd ZdZd fdd	Zdd Z fddZdd
dZdddZdd Z	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.
    Nc                    s.   t  | |d u rd| _d S d|| _d S )N	errorlistzerrorlist {})super__init__error_classformat)r(   initlistrM   	__class__r   r   rL   T   s   
zErrorList.__init__c                 C   s   t | jjS r.   )r   data
error_listr'   r   r   r   r    \      zErrorList.as_datac                    s   t   }| j|_|S r.   )rK   copyrM   )r(   rU   rP   r   r   rU   _   s   
zErrorList.copyFc                 C   sD   g }|   D ]}tt|}||rt|n||jpdd q|S )Nr   )messagecode)r    nextiterr   r   rW   )r(   r+   r>   errorrV   r   r   r   r)   d   s   
zErrorList.get_json_datac                 C   r-   r.   r/   r,   r   r   r   r2   n   r3   zErrorList.as_jsonc                 C   s*   | j sdS td| jtdddd | D S )Nr   z<ul class="{}">{}</ul>z<li>{}</li>c                 s   s    | ]}|fV  qd S r.   r   r8   r   r   r   r9   x   s    z"ErrorList.as_ul.<locals>.<genexpr>)rR   r   rM   r   r'   r   r   r   r4   q   s   zErrorList.as_ulc                 C   s   d dd | D S )Nr6   c                 s   r7   )r5   Nr   r8   r   r   r   r9   |   r:   z$ErrorList.as_text.<locals>.<genexpr>)r;   r'   r   r   r   r?   {   s   zErrorList.as_textc                 C   r@   r.   rA   r'   r   r   r   rB   ~   rC   zErrorList.__str__c                 C   s   t t| S r.   )reprlistr'   r   r   r   __repr__   rT   zErrorList.__repr__c                 C   s   |t | v S r.   r\   )r(   itemr   r   r   __contains__   rT   zErrorList.__contains__c                 C   s   t | |kS r.   r^   )r(   otherr   r   r   __eq__   rT   zErrorList.__eq__c                 C   s$   | j | }t|trtt|S |S r.   )rR   r   r   rX   rY   )r(   irZ   r   r   r   __getitem__   s   

zErrorList.__getitem__c                    s&   t t| j|i |}|d d d S )N   NN)rK   r   __reduce_ex__)r(   argskwargsinforP   r   r   rg      s   zErrorList.__reduce_ex__rf   rD   )rE   rF   rG   rH   rL   r    rU   r)   r2   r4   r?   rB   r]   r`   rb   rd   rg   __classcell__r   r   rP   r   rI   O   s    



rI   c              
   C   s   t jr@| dur@t| r@t }zt|s 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)rW   params)r   USE_TZr   is_naiveget_current_timezone_is_pytz_zone _datetime_ambiguous_or_imaginary
ValueError
make_aware	Exceptionr   r   )r   rn   excr   r   r   from_current_timezone   s(   
ry   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   rp   r   is_aware
make_naive)r   r   r   r   to_current_timezone   s   
r|   )r0   collectionsr   django.confr   django.core.exceptionsr   django.utilsr   django.utils.htmlr   r   r   r	   django.utils.translationr
   r   r   r   dictr   r\   rI   ry   r|   r   r   r   r   <module>   s    "L