U
    R+|já  ã                   @   s  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d„ Zdd„ Zdeƒ  ZG dd„ dƒ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)ÚRemovedInDjango50Warning)ÚescapeÚformat_html_join)Ú	mark_safe)Úgettext_lazy)Úget_docs_versionc                 C   s   | sdS |   dd¡ ¡ S )z%Convert 'first_name' to 'First name'.Ú Ú_ú )ÚreplaceÚ
capitalize)Úname© r   úZc:\users\snmko\desktop\web_content\django_cbt\venv\Lib\site-packages\django/forms/utils.pyÚpretty_name   s    r   c                 C   sl   g }g }|   ¡ D ]:\}}t|tƒr4|rJ| |f¡ q|dk	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   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                   @   s&   e Zd Zdd„ Zddd„ZeZeZdS )ÚRenderableMixinc                 C   s   t dƒ‚d S )NzBSubclasses of RenderableMixin must provide a get_context() method.)ÚNotImplementedError©Úselfr   r   r   Úget_context;   s    ÿzRenderableMixin.get_contextNc                 C   sP   |p| j }|p| j}|p|  ¡ }|dks0|dkr@tjttdd� t| ||¡ƒ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'   Útemplater   r   r   r,   @   s    

ÿþ  ÿzRenderableMixin.render)NNN)Ú__name__Ú
__module__Ú__qualname__r$   r,   Ú__str__Z__html__r   r   r   r   r    :   s   
r    c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚRenderableFormMixinc                 C   s   |   | j¡S )zRender as <p> elements.)r,   Ztemplate_name_pr"   r   r   r   Úas_pR   s    zRenderableFormMixin.as_pc                 C   s   |   | j¡S )z>Render as <tr> elements excluding the surrounding <table> tag.)r,   Ztemplate_name_tabler"   r   r   r   Úas_tableV   s    zRenderableFormMixin.as_tablec                 C   s   |   | j¡S )z;Render as <li> elements excluding the surrounding <ul> tag.©r,   Útemplate_name_ulr"   r   r   r   Úas_ulZ   s    zRenderableFormMixin.as_ulc                 C   s   |   | j¡S )zRender as <div> elements.)r,   Ztemplate_name_divr"   r   r   r   Úas_div^   s    zRenderableFormMixin.as_divN)r/   r0   r1   r4   r5   r8   r9   r   r   r   r   r3   Q   s   r3   c                   @   s&   e Zd Zd	dd„Zdd„ Zdd„ ZdS )
ÚRenderableErrorMixinFc                 C   s   t  |  |¡¡S ©N)ÚjsonÚdumpsÚget_json_data©r#   Úescape_htmlr   r   r   Úas_jsond   s    zRenderableErrorMixin.as_jsonc                 C   s   |   | j¡S r;   )r,   Útemplate_name_textr"   r   r   r   Úas_textg   s    zRenderableErrorMixin.as_textc                 C   s   |   | j¡S r;   r6   r"   r   r   r   r8   j   s    zRenderableErrorMixin.as_ulN)F)r/   r0   r1   rA   rC   r8   r   r   r   r   r:   c   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||Ž |ptƒ | _d S r;   )ÚsuperÚ__init__r   r'   )r#   r'   ÚargsÚkwargs©Ú	__class__r   r   rF   y   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   rK   }   s    zErrorDict.as_dataFc                    s   ‡ fdd„|   ¡ D ƒS )Nc                    s   i | ]\}}||  ˆ ¡“qS r   )r>   rL   ©r@   r   r   rP   �   s      z+ErrorDict.get_json_data.<locals>.<dictcomp>rQ   r?   r   rR   r   r>   €   s    zErrorDict.get_json_datac                 C   s   |   ¡ ddœS )NÚ	errorlist©ÚerrorsÚerror_classrQ   r"   r   r   r   r$   ƒ   s    þzErrorDict.get_context)F)r/   r0   r1   Ú__doc__r(   rB   r7   rF   rK   r>   r$   Ú__classcell__r   r   rI   r   rD   n   s   
rD   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 krd| _nd |¡| _|p0tƒ | _d S )NrS   zerrorlist {})rE   rF   rV   Úformatr   r'   )r#   ÚinitlistrV   r'   rI   r   r   rF   “   s
    zErrorList.__init__c                 C   s   t | jƒjS r;   )r   ÚdataZ
error_listr"   r   r   r   rK   œ   s    zErrorList.as_datac                    s   t ƒ  ¡ }| j|_|S r;   )rE   ÚcopyrV   )r#   r]   rI   r   r   r]   Ÿ   s    
zErrorList.copyFc                 C   sD   g }|   ¡ D ]2}tt|ƒƒ}| |r,t|ƒn||jp6ddœ¡ q|S )Nr   )ÚmessageÚcode)rK   ÚnextÚiterr   r   r_   )r#   r@   rU   Úerrorr^   r   r   r   r>   ¤   s    þÿzErrorList.get_json_datac                 C   s   | | j dœS )NrT   )rV   r"   r   r   r   r$   °   s    þzErrorList.get_contextc                 C   s   t t| ƒƒS r;   )ÚreprÚlistr"   r   r   r   Ú__repr__¶   s    zErrorList.__repr__c                 C   s   |t | ƒkS r;   ©rd   )r#   Úitemr   r   r   Ú__contains__¹   s    zErrorList.__contains__c                 C   s   t | ƒ|kS r;   rf   )r#   Úotherr   r   r   Ú__eq__¼   s    zErrorList.__eq__c                 C   s$   | j | }t|tƒr tt|ƒƒS |S r;   )r\   r   r   r`   ra   )r#   Úirb   r   r   r   Ú__getitem__¿   s    

zErrorList.__getitem__c                    s"   t t| ƒj||Ž}|d d… d S )Né   )NN)rE   r   Ú__reduce_ex__)r#   rG   rH   ÚinforI   r   r   rn   Å   s    zErrorList.__reduce_ex__)NNN)F)r/   r0   r1   rW   r(   rB   r7   rF   rK   r]   r>   r$   re   rh   rj   rl   rn   rX   r   r   rI   r   rY   Š   s   	
rY   c              
   C   sŽ   t jrŠ| dk	rŠt | ¡rŠt ¡ }z,t |¡s@t | |¡r@tdƒ‚t | |¡W S  t	k
rˆ } zt
tdƒd| |dœd�|‚W 5 d}~X Y nX | 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)r_   Úparams)r   ÚUSE_TZr   Zis_naiveZget_current_timezoneZ_is_pytz_zoneZ _datetime_ambiguous_or_imaginaryÚ
ValueErrorZ
make_awareÚ	Exceptionr   r   )r   rq   Úexcr   r   r   Úfrom_current_timezoneÒ   s*    ÿ
þÿùø	rw   c                 C   s&   t jr"| dk	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   rs   r   Zis_awareZ
make_naive)r   r   r   r   Úto_current_timezoneì   s    
rx   )$r<   r)   Úcollectionsr   Zdjango.confr   Zdjango.core.exceptionsr   Zdjango.forms.renderersr   Zdjango.utilsr   Zdjango.utils.deprecationr   Zdjango.utils.htmlr   r	   Zdjango.utils.safestringr
   Zdjango.utils.translationr   r   Zdjango.utils.versionr   r   r   r+   r    r3   r:   ÚdictrD   rd   rY   rw   rx   r   r   r   r   Ú<module>   s0   ûÿ
H