o
    þÞhZS  ã                   @   sì   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
mZ d dlmZmZmZ d dlmZ d dlmZ d d	lmZ d
ZdZdZdZdZdZdZd ZdZG dd„ deƒZG dd„ deƒZ e ddddddddddfdd„Z!dd„ Z"dS )é    )ÚValidationError)ÚBooleanFieldÚIntegerField)ÚForm)Úget_default_renderer)Ú	ErrorListÚRenderableFormMixin)ÚCheckboxInputÚHiddenInputÚNumberInput)Úcached_property)Úgettext_lazy)Úngettext_lazy)ÚBaseFormSetÚformset_factoryÚ	all_validÚTOTAL_FORMSÚINITIAL_FORMSÚMIN_NUM_FORMSÚMAX_NUM_FORMSÚORDERÚDELETEiè  c                       sL   e Zd ZdZeed�Zeed�Zeded�Zeded�Z	‡ fdd„Z
‡  ZS )ÚManagementFormz±
    Keep track of how many form instances are displayed on the page. If adding
    new forms via JavaScript, you should increment the count field of this form
    as well.
    )ÚwidgetF)Úrequiredr   c                    s&   t ƒ  ¡ }| td¡ | td¡ |S ©Nr   )ÚsuperÚcleanÚ
setdefaultÚTOTAL_FORM_COUNTÚINITIAL_FORM_COUNT)ÚselfÚcleaned_data©Ú	__class__© úU/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/forms/formsets.pyr   +   s   
zManagementForm.clean)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   r   r   r   r   r   Ú__classcell__r%   r%   r#   r&   r      s    

r   c                   @   sª  e Zd ZdZeZeZedƒe	dddƒe	dddƒdœZ
d	Zd
ZdZdZdddddeddfdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdd„ Zdd „ Zed!d"„ ƒZd#d$„ Zd%d&„ Zed'd(„ ƒZed)d*„ ƒZed+d,„ ƒZ ed-d.„ ƒZ!ed/d0„ ƒZ"ed1d2„ ƒZ#e$d3d4„ ƒZ%e$d5d6„ ƒZ&e$d7d8„ ƒZ'd9d:„ Z(ed;d<„ ƒZ)d=d>„ Z*d?d@„ Z+dAdB„ Z,dCdD„ Z-dEdF„ Z.dGdH„ Z/dIdJ„ Z0dKdL„ Z1dMdN„ Z2edOdP„ ƒZ3edQdR„ ƒZ4dSdT„ Z5dS )Ur   z;
    A collection of instances of the same Form class.
    z“ManagementForm data is missing or has been tampered with. Missing fields: %(field_names)s. You may need to file a bug report if the issue persists.z#Please submit at most %(num)d form.z$Please submit at most %(num)d forms.Únumz$Please submit at least %(num)d form.z%Please submit at least %(num)d forms.)Úmissing_management_formÚtoo_many_formsÚtoo_few_formszdjango/forms/formsets/div.htmlzdjango/forms/formsets/p.htmlz django/forms/formsets/table.htmlzdjango/forms/formsets/ul.htmlNzid_%sc	                 C   s¸   |d up|d u| _ |p|  ¡ | _|| _|pi | _|pi | _|| _|p#i | _|| _d | _	d | _
| j| _| jp7tƒ | _i }	tt| ƒjƒD ]}
|	 t|
di ƒ¡ qB|d urW|	 |¡ |	| _d S )NÚdefault_error_messages)Úis_boundÚget_default_prefixÚprefixÚauto_idÚdataÚfilesÚinitialÚform_kwargsÚerror_classÚ_errorsÚ_non_form_errorsÚrendererÚform_rendererr   ÚreversedÚtypeÚ__mro__ÚupdateÚgetattrÚerror_messages)r!   r5   r6   r4   r3   r7   r9   r8   rC   ÚmessagesÚclsr%   r%   r&   Ú__init__Q   s$   




zBaseFormSet.__init__c                 C   ó
   t | jƒS )z5Yield the forms in the order they should be rendered.)ÚiterÚforms©r!   r%   r%   r&   Ú__iter__p   ó   
zBaseFormSet.__iter__c                 C   s
   | j | S )zAReturn the form at the given index, based on the rendering order.©rI   ©r!   Úindexr%   r%   r&   Ú__getitem__t   rL   zBaseFormSet.__getitem__c                 C   rG   ©N)ÚlenrI   rJ   r%   r%   r&   Ú__len__x   s   
zBaseFormSet.__len__c                 C   ó   dS )zt
        Return True since all formsets have a management form which is not
        included in the length.
        Tr%   rJ   r%   r%   r&   Ú__bool__{   s   zBaseFormSet.__bool__c                 C   sN   | j d u rd}n| jo| j otdd„ | j D ƒƒ }d| jj| j||  ¡ f S )NÚUnknownc                 s   s   � | ]}|V  qd S rQ   r%   ©Ú.0Úform_errorsr%   r%   r&   Ú	<genexpr>‰   s   € z'BaseFormSet.__repr__.<locals>.<genexpr>z&<%s: bound=%s valid=%s total_forms=%s>)r:   r1   r;   Úanyr$   r)   Útotal_form_count)r!   Úis_validr%   r%   r&   Ú__repr__‚   s   
ÿýüzBaseFormSet.__repr__c                 C   s`   | j rt| j| j| j| jd�}| ¡  |S t| j| jt|  ¡ t	|  
¡ t| jt| ji| jd�}|S )z4Return the ManagementForm instance for this FormSet.)r4   r3   r<   )r4   r3   r7   r<   )r1   r   r5   r4   r3   r<   Ú
full_cleanr   r\   r    Úinitial_form_countÚMIN_NUM_FORM_COUNTÚmin_numÚMAX_NUM_FORM_COUNTÚmax_num©r!   Úformr%   r%   r&   Úmanagement_form’   s(   üõü÷zBaseFormSet.management_formc                 C   sx   | j rt| jjt | jƒS |  ¡ }t|| jƒ| j	 }|| j
  kr(dkr)|}|S  || j
  kr4dkr:n |S | j
}|S )z1Return the total number of forms in this FormSet.r   )r1   Úminrg   r"   r   Úabsolute_maxr`   Úmaxrb   Úextrard   )r!   Úinitial_formsÚtotal_formsr%   r%   r&   r\   «   s   ÿüÿzBaseFormSet.total_form_countc                 C   s*   | j r	| jjt S | jrt| jƒnd}|S )z=Return the number of forms that are required in this FormSet.r   )r1   rg   r"   r    r7   rR   )r!   rl   r%   r%   r&   r`   À   s   zBaseFormSet.initial_form_countc                    s   ‡ fdd„t ˆ  ¡ ƒD ƒS )z+Instantiate forms at first property access.c                    s$   g | ]}ˆ j |fi ˆ  |¡¤Ž‘qS r%   )Ú_construct_formÚget_form_kwargs©rX   ÚirJ   r%   r&   Ú
<listcomp>Í   s    ÿÿz%BaseFormSet.forms.<locals>.<listcomp>)Úranger\   rJ   r%   rJ   r&   rI   É   s   

þzBaseFormSet.formsc                 C   s
   | j  ¡ S )z®
        Return additional keyword arguments for each individual formset form.

        index will be None if the form being constructed is a new empty
        form.
        )r8   ÚcopyrN   r%   r%   r&   ro   Ò   s   
zBaseFormSet.get_form_kwargsc                 K   s²   | j |  |¡| jd| jdœ}| jr| j|d< | j|d< | jr5d|vr5z	| j| |d< W n	 ty4   Y nw ||  	¡ krD|| j
krDd|d< | |¡ | jd	i |¤Ž}|  ||¡ |S )
z;Instantiate and return the i-th form instance in a formset.F)r4   r3   r9   Úuse_required_attributer<   r5   r6   r7   TÚempty_permittedNr%   )r4   Ú
add_prefixr9   r=   r1   r5   r6   r7   Ú
IndexErrorr`   rb   rA   rf   Ú
add_fields)r!   rq   ÚkwargsÚdefaultsrf   r%   r%   r&   rn   Û   s*   ø


ÿ
zBaseFormSet._construct_formc                 C   s   | j d|  ¡ … S )z7Return a list of all the initial forms in this formset.N©rI   r`   rJ   r%   r%   r&   rl   ø   ó   zBaseFormSet.initial_formsc                 C   s   | j |  ¡ d… S )z5Return a list of all the extra forms in this formset.Nr|   rJ   r%   r%   r&   Úextra_formsý   r}   zBaseFormSet.extra_formsc                 C   sH   i |   d ¡¥| j|  d¡dd| jdœ¥}| jdi |¤Ž}|  |d ¡ |S )NÚ
__prefix__TF)r4   r3   rv   ru   r<   r%   )ro   r4   rw   r=   rf   ry   )r!   r8   rf   r%   r%   r&   Ú
empty_form  s   ÿúzBaseFormSet.empty_formc                 C   s(   |   ¡ std| jj ƒ‚dd„ | jD ƒS )zX
        Return a list of form.cleaned_data dicts for every form in self.forms.
        z+'%s' object has no attribute 'cleaned_data'c                 S   s   g | ]}|j ‘qS r%   )r"   ©rX   rf   r%   r%   r&   rr     s    z,BaseFormSet.cleaned_data.<locals>.<listcomp>)r]   ÚAttributeErrorr$   r'   rI   rJ   r%   r%   r&   r"     s
   
ÿzBaseFormSet.cleaned_datac                    sv   ˆ   ¡ rˆ js	g S tˆ dƒs1g ˆ _tˆ jƒD ]\}}|ˆ  ¡ kr%| ¡ s%qˆ  |¡r0ˆ j 	|¡ q‡ fdd„ˆ jD ƒS )z:Return a list of forms that have been marked for deletion.Ú_deleted_form_indexesc                    s   g | ]}ˆ j | ‘qS r%   rM   rp   rJ   r%   r&   rr   *  s    z-BaseFormSet.deleted_forms.<locals>.<listcomp>)
r]   Ú
can_deleteÚhasattrrƒ   Ú	enumeraterI   r`   Úhas_changedÚ_should_delete_formÚappend)r!   rq   rf   r%   rJ   r&   Údeleted_forms  s   

€zBaseFormSet.deleted_formsc                    sª   ˆ   ¡ rˆ jstdˆ jj ƒ‚tˆ dƒsKg ˆ _tˆ jƒD ]#\}}|ˆ  	¡ kr+| 
¡ s+qˆ jr4ˆ  |¡r4qˆ j ||jt f¡ qdd„ }ˆ jj|d� ‡ fdd„ˆ jD ƒS )z�
        Return a list of form in the order specified by the incoming data.
        Raise an AttributeError if ordering is not allowed.
        z,'%s' object has no attribute 'ordered_forms'Ú	_orderingc                 S   s   | d d u rdS d| d fS )Né   )rŒ   r   r   r%   )Úkr%   r%   r&   Úcompare_ordering_keyJ  s   z7BaseFormSet.ordered_forms.<locals>.compare_ordering_key)Úkeyc                    s   g | ]	}ˆ j |d   ‘qS )r   rM   rp   rJ   r%   r&   rr   R  s    z-BaseFormSet.ordered_forms.<locals>.<listcomp>)r]   Ú	can_orderr‚   r$   r'   r…   r‹   r†   rI   r`   r‡   r„   rˆ   r‰   r"   ÚORDERING_FIELD_NAMEÚsort)r!   rq   rf   rŽ   r%   rJ   r&   Úordered_forms,  s   
ÿ
zBaseFormSet.ordered_formsc                 C   rT   )Nrf   r%   ©rE   r%   r%   r&   r2   T  s   zBaseFormSet.get_default_prefixc                 C   ó   | j S rQ   )Údeletion_widgetr”   r%   r%   r&   Úget_deletion_widgetX  ó   zBaseFormSet.get_deletion_widgetc                 C   r•   rQ   )Úordering_widgetr”   r%   r%   r&   Úget_ordering_widget\  r˜   zBaseFormSet.get_ordering_widgetc                 C   ó   | j du r	|  ¡  | j S )z¹
        Return an ErrorList of errors that aren't associated with a particular
        form -- i.e., from formset.clean(). Return an empty ErrorList if there
        are none.
        N)r;   r_   rJ   r%   r%   r&   Únon_form_errors`  s   
zBaseFormSet.non_form_errorsc                 C   r›   )z:Return a list of form.errors for every form in self.forms.N)r:   r_   rJ   r%   r%   r&   Úerrorsj  s   
zBaseFormSet.errorsc                 C   s    t |  ¡ ƒtdd„ | jD ƒƒ S )z<Return the number of errors across all forms in the formset.c                 s   s   � | ]}t |ƒV  qd S rQ   )rR   rW   r%   r%   r&   rZ   s  s   € 
ÿz0BaseFormSet.total_error_count.<locals>.<genexpr>)rR   rœ   Úsumr�   rJ   r%   r%   r&   Útotal_error_countq  s   
ÿzBaseFormSet.total_error_countc                 C   s   |j  td¡S )z7Return whether or not the form was marked for deletion.F)r"   ÚgetÚDELETION_FIELD_NAMEre   r%   r%   r&   rˆ   w  s   zBaseFormSet._should_delete_formc                    s6   ˆ j sdS ˆ j t‡ fdd„ˆ jD ƒƒ}|oˆ  ¡  S )z1Return True if every form in self.forms is valid.Fc                    s$   g | ]}ˆ j rˆ  |¡s| ¡ ‘qS r%   )r„   rˆ   r]   r�   rJ   r%   r&   rr   „  s    ýýÿz(BaseFormSet.is_valid.<locals>.<listcomp>)r1   r�   ÚallrI   rœ   )r!   Úforms_validr%   rJ   r&   r]   {  s   
þÿzBaseFormSet.is_validc              
      s–  g ˆ _ ˆ jdˆ jd�ˆ _d}ˆ jsdS ˆ j ¡ s6tˆ jd dd 	‡ fdd	„ˆ jj
D ƒ¡idd
�}ˆ j |¡ tˆ jƒD ]$\}}| ¡ sM|ˆ  ¡ krM|d7 }|j
}ˆ jrYˆ  |¡rYq;ˆ j  |¡ q;zLˆ jrpˆ  ¡ tˆ jƒ ˆ jksyˆ jjt ˆ jkr‡tˆ jd dˆ ji dd�‚ˆ jr¦ˆ  ¡ tˆ jƒ | ˆ jk r¦tˆ jd dˆ ji dd�‚ˆ  ¡  W dS  tyÊ } zˆ j|jdˆ jd�ˆ _W Y d}~dS d}~ww )ze
        Clean all of self.data and populate self._errors and
        self._non_form_errors.
        Únonform)r9   r<   r   Nr-   Úfield_namesz, c                 3   s   � | ]	}ˆ j  |¡V  qd S rQ   )rg   rw   )rX   Ú
field_namerJ   r%   r&   rZ   ž  s
   € 
ÿ
ÿz)BaseFormSet.full_clean.<locals>.<genexpr>)ÚparamsÚcoderŒ   r.   r,   )r¨   r/   )r:   r9   r<   r;   r1   rg   r]   r   rC   Újoinr�   r‰   r†   rI   r‡   r`   r„   rˆ   Úvalidate_maxr\   rR   rŠ   rd   r"   r   ri   Úvalidate_minrb   r   Ú
error_list)r!   Úempty_forms_countÚerrorrq   rf   rY   Úer%   rJ   r&   r_   Œ  sv   ÿ
þÿø
ÿÿþþÿÿþýþý€ÿzBaseFormSet.full_cleanc                 C   rT   )a  
        Hook for doing any extra formset-wide cleaning after Form.clean() has
        been called on every form. Any ValidationError raised by this method
        will not be associated with a particular form; it will be accessible
        via formset.non_form_errors()
        Nr%   rJ   r%   r%   r&   r   Ð  s   zBaseFormSet.cleanc                 C   ó   t dd„ | D ƒƒS )z5Return True if data in any form differs from initial.c                 s   s   � | ]}|  ¡ V  qd S rQ   )r‡   r�   r%   r%   r&   rZ   Û  s   € z*BaseFormSet.has_changed.<locals>.<genexpr>)r[   rJ   r%   r%   r&   r‡   Ù  s   zBaseFormSet.has_changedc                 C   s¦   |   ¡ }| jr/|dur!||k r!ttdƒ|d d|  ¡ d�|jt< nttdƒd|  ¡ d�|jt< | jrM| js=|durO||k rQt	tdƒd|  
¡ d�|jt< dS dS dS dS )z8A hook for adding extra fields on to each form instance.NÚOrderrŒ   F)Úlabelr7   r   r   )r²   r   r   ÚDelete)r`   r�   r   Ú_rš   Úfieldsr‘   r„   Úcan_delete_extrar   r—   r¡   )r!   rf   rO   r`   r%   r%   r&   ry   Ý  s2   üýÿýýzBaseFormSet.add_fieldsc                 C   s   d| j |f S )Nz%s-%s)r3   rN   r%   r%   r&   rw   ø  s   zBaseFormSet.add_prefixc                 C   s   | j r
| j d  ¡ S | j ¡ S )zv
        Return True if the formset needs to be multipart, i.e. it
        has FileInput, or False otherwise.
        r   )rI   Úis_multipartr€   rJ   r%   r%   r&   r·   û  s   
zBaseFormSet.is_multipartc                 C   s   | j r	| j d jS | jjS r   )rI   Úmediar€   rJ   r%   r%   r&   r¸     s   zBaseFormSet.mediac                 C   s   | j jS rQ   )r<   Úformset_template_namerJ   r%   r%   r&   Útemplate_name  s   zBaseFormSet.template_namec                 C   s   d| iS )NÚformsetr%   rJ   r%   r%   r&   Úget_context  s   zBaseFormSet.get_context)6r'   r(   r)   r*   r	   r–   r   r™   r´   r   r0   Útemplate_name_divÚtemplate_name_pÚtemplate_name_tableÚtemplate_name_ulr   rF   rK   rP   rS   rU   r^   r   rg   r\   r`   rI   ro   rn   Úpropertyrl   r~   r€   r"   rŠ   r“   Úclassmethodr2   r—   rš   rœ   r�   rŸ   rˆ   r]   r_   r   r‡   ry   rw   r·   r¸   rº   r¼   r%   r%   r%   r&   r   4   sž    ÿýýö
÷
	
	






'




D	


r   rŒ   FNTc                 C   s„   |du rt }|du rt}|	du r|t }	||	krtdƒ‚| ||||
|||	|||dœ}| j}| d¡r7|d }n|d }t||f|ƒS )z*Return a FormSet for the given form class.Nz5'absolute_max' must be greater or equal to 'max_num'.)rf   rk   r�   r„   r¶   rb   rd   ri   r«   rª   r<   r   ÚSetÚFormSet)ÚDEFAULT_MIN_NUMÚDEFAULT_MAX_NUMÚ
ValueErrorr'   Úendswithr?   )rf   r»   rk   r�   r„   rd   rª   rb   r«   ri   r¶   r<   ÚattrsÚ	form_nameÚformset_namer%   r%   r&   r     s2   õ

r   c                 C   r°   )z8Validate every formset and return True if all are valid.c                 S   s   g | ]}|  ¡ ‘qS r%   )r]   )rX   r»   r%   r%   r&   rr   H  s    zall_valid.<locals>.<listcomp>)r¢   )Úformsetsr%   r%   r&   r   E  r}   r   )#Údjango.core.exceptionsr   Údjango.forms.fieldsr   r   Údjango.forms.formsr   Údjango.forms.renderersr   Údjango.forms.utilsr   r   Údjango.forms.widgetsr	   r
   r   Údjango.utils.functionalr   Údjango.utils.translationr   r´   r   Ú__all__r   r    ra   rc   r‘   r¡   rÅ   rÆ   r   r   r   r   r%   r%   r%   r&   Ú<module>   sH       g
ô/