a
    xdt                     @   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   J/var/www/html/Ranjet/env/lib/python3.9/site-packages/django/forms/utils.pypretty_name   s    r   c                 C   sl   g }g }|   D ]:\}}t|tr4|rJ||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                   @   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       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   r%   z+ErrorDict.get_json_data.<locals>.<dictcomp>r&   r(   r+   r   r*   r   r)   6   s    zErrorDict.get_json_datac                 C   s   t | |S Njsondumpsr)   r,   r   r   r   as_json9   s    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 ]0\}}|d|  |ddd |D  qd|S )N* %s
c                 s   s   | ]}d | V  qdS )z  * %sNr   r!   r#   r   r   r   	<genexpr>H   r%   z$ErrorDict.as_text.<locals>.<genexpr>)r   r   join)r(   outputfielderrorsr   r   r   as_textD   s
    zErrorDict.as_textc                 C   s   |   S r-   r2   r'   r   r   r   __str__K   s    zErrorDict.__str__N)F)F)
__name__
__module____qualname____doc__r   r)   r1   r2   r;   r=   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| _nd|| _d S )NZ	errorlistzerrorlist {})super__init__error_classformat)r(   initlistrE   	__class__r   r   rD   T   s    zErrorList.__init__c                 C   s   t | jjS r-   )r   dataZ
error_listr'   r   r   r   r   \   s    zErrorList.as_datac                    s   t   }| j|_|S r-   )rC   copyrE   )r(   rK   rH   r   r   rK   _   s    
zErrorList.copyFc                 C   sD   g }|   D ]2}tt|}||r,t|n||jp6dd q|S )Nr   )messagecode)r   nextiterr   r   rM   )r(   r+   r:   errorrL   r   r   r   r)   d   s    
zErrorList.get_json_datac                 C   s   t | |S r-   r.   r,   r   r   r   r1   n   s    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   r5   r   r   r   r6   x   r%   z"ErrorList.as_ul.<locals>.<genexpr>)rJ   r   rE   r   r'   r   r   r   r2   q   s    zErrorList.as_ulc                 C   s   d dd | D S )Nr4   c                 s   s   | ]}d | V  qdS )r3   Nr   r5   r   r   r   r6   |   r%   z$ErrorList.as_text.<locals>.<genexpr>)r7   r'   r   r   r   r;   {   s    zErrorList.as_textc                 C   s   |   S r-   r<   r'   r   r   r   r=   ~   s    zErrorList.__str__c                 C   s   t t| S r-   )reprlistr'   r   r   r   __repr__   s    zErrorList.__repr__c                 C   s   |t | v S r-   rR   )r(   itemr   r   r   __contains__   s    zErrorList.__contains__c                 C   s   t | |kS r-   rT   )r(   otherr   r   r   __eq__   s    zErrorList.__eq__c                 C   s$   | j | }t|tr tt|S |S r-   )rJ   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)rC   r   __reduce_ex__)r(   argskwargsinforH   r   r   r\      s    zErrorList.__reduce_ex__)NN)F)F)r>   r?   r@   rA   rD   r   rK   r)   r1   r2   r;   r=   rS   rV   rX   rZ   r\   __classcell__r   r   rH   r   rB   O   s   



rB   c              
   C   sr   t jrn| durnt| rnt }zt| |W S  tyl } z&ttdd| |dd|W Y d}~n
d}~0 0 | S )z}
    When time zone support is enabled, convert naive datetimes
    entered in the current time zone to aware datetimes.
    Nur   %(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)rM   params)	r   USE_TZr   Zis_naiveZget_current_timezoneZ
make_aware	Exceptionr   r   )r   rb   excr   r   r   from_current_timezone   s    rg   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   rd   r   Zis_awareZ
make_naive)r   r   r   r   to_current_timezone   s    
rh   )r/   collectionsr   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.utilsr   Zdjango.utils.htmlr   r   r   r	   Zdjango.utils.translationr
   r   r   r   dictr   rR   rB   rg   rh   r   r   r   r   <module>   s   "L