a
    Lcòf¯R  ã                   @   sì   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
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)ÚForm)ÚBooleanFieldÚIntegerField)Ú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_FORMSZORDERÚDELETEiè  c                       sP   e Zd 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.
    zdjango/forms/div.html)ÚwidgetF)Úrequiredr   c                    s&   t ƒ  ¡ }| td¡ | td¡ |S ©Nr   )ÚsuperÚcleanÚ
setdefaultÚTOTAL_FORM_COUNTÚINITIAL_FORM_COUNT)ÚselfÚcleaned_data©Ú	__class__© úR/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/django/forms/formsets.pyr   -   s    
zManagementForm.clean)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Útemplate_namer   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 | _|p6i | _|| _|pFi | _|| _d | _	d | _
i }	tt| ƒjƒD ]}
|	 t|
di ƒ¡ qn|d ur˜|	 |¡ |	| _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ÚreversedÚtypeÚ__mro__ÚupdateÚgetattrÚerror_messages)r    r5   r6   r4   r3   r7   r9   r8   rA   ÚmessagesÚclsr$   r$   r%   Ú__init__S   s     



zBaseFormSet.__init__c                 C   s
   t | jƒS )z5Yield the forms in the order they should be rendered.)ÚiterÚforms©r    r$   r$   r%   Ú__iter__p   s    zBaseFormSet.__iter__c                 C   s
   | j | S )zAReturn the form at the given index, based on the rendering order.©rF   ©r    Úindexr$   r$   r%   Ú__getitem__t   s    zBaseFormSet.__getitem__c                 C   s
   t | jƒS ©N)ÚlenrF   rG   r$   r$   r%   Ú__len__x   s    zBaseFormSet.__len__c                 C   s   dS )zt
        Return True since all formsets have a management form which is not
        included in the length.
        Tr$   rG   r$   r$   r%   Ú__bool__{   s    zBaseFormSet.__bool__c                 C   sN   | j d u rd}n$| jo2| j o2tdd„ | j D ƒƒ }d| jj| j||  ¡ f S )NÚUnknownc                 s   s   | ]
}|V  qd S rM   r$   ©Ú.0Úform_errorsr$   r$   r%   Ú	<genexpr>‰   ó    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�}| ¡  n2t| j| jt|  ¡ t	|  
¡ t| jt| ji| jd�}|S )z4Return the ManagementForm instance for this FormSet.)r4   r3   Úrenderer)r4   r3   r7   r[   )r1   r   r5   r4   r3   r[   Ú
full_cleanr   rX   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rJdkrTn n|}n || j
  krjdkrtn n| j
}|S )z1Return the total number of forms in this FormSet.r   )r1   Úminrd   r!   r   Úabsolute_maxr]   Úmaxr_   Úextrara   )r    Úinitial_formsZtotal_formsr$   r$   r%   rX   «   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   rd   r!   r   r7   rN   )r    ri   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©rS   ÚirG   r$   r%   Ú
<listcomp>Í   s   ÿz%BaseFormSet.forms.<locals>.<listcomp>)ÚrangerX   rG   r$   rG   r%   rF   É   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   ÚcopyrJ   r$   r$   r%   rk   Ò   s    zBaseFormSet.get_form_kwargsc                 K   s²   | j |  |¡| jd| jdœ}| jr6| j|d< | j|d< | jrjd|vrjz| j| |d< W n tyh   Y n0 ||  	¡ krˆ|| j
krˆd|d< | |¡ | jf 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_permitted)r4   Ú
add_prefixr9   r[   r1   r5   r6   r7   Ú
IndexErrorr]   r_   r?   rc   Ú
add_fields)r    rm   ÚkwargsÚdefaultsrc   r$   r$   r%   rj   Û   s(    ø



zBaseFormSet._construct_formc                 C   s   | j d|  ¡ … S )z7Return a list of all the initial forms in this formset.N©rF   r]   rG   r$   r$   r%   ri   ø   s    zBaseFormSet.initial_formsc                 C   s   | j |  ¡ d… S )z5Return a list of all the extra forms in this formset.Nrx   rG   r$   r$   r%   Úextra_formsý   s    zBaseFormSet.extra_formsc                 C   sH   i |   d ¡¥| j|  d¡dd| jdœ¥}| jf i |¤Ž}|  |d ¡ |S )NZ
__prefix__TF)r4   r3   rr   rq   r[   )rk   r4   rs   r[   rc   ru   )r    r8   rc   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!   ©rS   rc   r$   r$   r%   rn     rV   z,BaseFormSet.cleaned_data.<locals>.<listcomp>)rY   ÚAttributeErrorr#   r&   rF   rG   r$   r$   r%   r!     s
    
ÿzBaseFormSet.cleaned_datac                    sv   ˆ   ¡ rˆ jsg S tˆ dƒsbg ˆ _tˆ jƒD ]4\}}|ˆ  ¡ krJ| ¡ sJq,ˆ  |¡r,ˆ 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$   rI   rl   rG   r$   r%   rn   *  rV   z-BaseFormSet.deleted_forms.<locals>.<listcomp>)
rY   Ú
can_deleteÚhasattrr}   Ú	enumeraterF   r]   Úhas_changedÚ_should_delete_formÚappend)r    rm   rc   r$   rG   r%   Údeleted_forms  s    

zBaseFormSet.deleted_formsc                    sª   ˆ   ¡ rˆ jstdˆ jj ƒ‚tˆ dƒs–g ˆ _tˆ jƒD ]F\}}|ˆ  	¡ krV| 
¡ sVq8ˆ jrhˆ  |¡rhq8ˆ j ||jt f¡ q8d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   rI   rl   rG   r$   r%   rn   R  rV   z-BaseFormSet.ordered_forms.<locals>.<listcomp>)rY   Ú	can_orderr|   r#   r&   r   r…   r€   rF   r]   r�   r~   r‚   rƒ   r!   ÚORDERING_FIELD_NAMEÚsort)r    rm   rc   rˆ   r$   rG   r%   Úordered_forms,  s    
ÿ
zBaseFormSet.ordered_formsc                 C   s   dS )Nrc   r$   ©rC   r$   r$   r%   r2   T  s    zBaseFormSet.get_default_prefixc                 C   s   | j S rM   )Údeletion_widgetrŽ   r$   r$   r%   Úget_deletion_widgetX  s    zBaseFormSet.get_deletion_widgetc                 C   s   | j S rM   )Úordering_widgetrŽ   r$   r$   r%   Úget_ordering_widget\  s    zBaseFormSet.get_ordering_widgetc                 C   s   | 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\   rG   r$   r$   r%   Únon_form_errors`  s    
zBaseFormSet.non_form_errorsc                 C   s   | j du r|  ¡  | j S )z:Return a list of form.errors for every form in self.forms.N)r:   r\   rG   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 rM   )rN   rR   r$   r$   r%   rU   s  s   z0BaseFormSet.total_error_count.<locals>.<genexpr>)rN   r“   Úsumr”   rG   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_NAMErb   r$   r$   r%   r‚   w  s    zBaseFormSet._should_delete_formc                    s6   ˆ j s
dS ˆ j t‡ fdd„ˆ jD ƒƒ}|o4ˆ  ¡  S )z1Return True if every form in self.forms is valid.Fc                    s$   g | ]}ˆ j rˆ  |¡s| ¡ ‘qS r$   )r~   r‚   rY   r{   rG   r$   r%   rn   „  s   þz(BaseFormSet.is_valid.<locals>.<listcomp>)r1   r”   ÚallrF   r“   )r    Zforms_validr$   rG   r%   rY   {  s    
þÿzBaseFormSet.is_validc              
      sž  g ˆ _ ˆ jdˆ jd�ˆ _d}ˆ js&dS ˆ j ¡ sltˆ jd dd 	‡ fdd	„ˆ jj
D ƒ¡idd
�}ˆ j |¡ tˆ jƒD ]H\}}| ¡ sš|ˆ  ¡ krš|d7 }|j
}ˆ jr²ˆ  |¡r²qvˆ j  |¡ qvzœˆ jràˆ  ¡ tˆ jƒ ˆ jksôˆ jjt ˆ jk�rtˆ jd dˆ ji dd�‚ˆ j�rRˆ  ¡ tˆ jƒ | ˆ jk �rRtˆ jd dˆ ji dd�‚ˆ  ¡  W n< t�y˜ } z"ˆ j|jdˆ jd�ˆ _W Y d}~n
d}~0 0 dS )ze
        Clean all of self.data and populate self._errors and
        self._non_form_errors.
        Znonform)r9   r[   r   Nr-   Úfield_namesz, c                 3   s   | ]}ˆ j  |¡V  qd S rM   )rd   rs   )rS   Ú
field_namerG   r$   r%   rU   ž  s   ÿz)BaseFormSet.full_clean.<locals>.<genexpr>)ÚparamsÚcoder†   r.   r,   )r�   r/   )r:   r9   r[   r;   r1   rd   rY   r   rA   Újoinr”   rƒ   r€   rF   r�   r]   r~   r‚   Úvalidate_maxrX   rN   r„   ra   r!   r   rf   Úvalidate_minr_   r   Z
error_list)r    Zempty_forms_countÚerrorrm   rc   rT   Úer$   rG   r%   r\   Œ  sx    ÿ
þÿø
ÿþÿþýþÿÿþýþþýzBaseFormSet.full_cleanc                 C   s   dS )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$   rG   r$   r$   r%   r   Ð  s    zBaseFormSet.cleanc                 C   s   t dd„ | D ƒƒS )z5Return True if data in any form differs from initial.c                 s   s   | ]}|  ¡ V  qd S rM   )r�   r{   r$   r$   r%   rU   Û  rV   z*BaseFormSet.has_changed.<locals>.<genexpr>)rW   rG   r$   r$   r%   r�   Ù  s    zBaseFormSet.has_changedc                 C   sš   |   ¡ }| jr^|durB||k rBttdƒ|d d|  ¡ d�|jt< nttdƒd|  ¡ d�|jt< | jr–| jsz|dur–||k r–t	tdƒd|  
¡ d�|jt< dS )z8A hook for adding extra fields on to each form instance.NZOrderr†   F)Úlabelr7   r   r   )r£   r   r   ÚDelete)r]   rŠ   r   Ú_r’   Úfieldsr‹   r~   Úcan_delete_extrar   r�   r˜   )r    rc   rK   r]   r$   r$   r%   ru   Ý  s4    üýÿÿÿýzBaseFormSet.add_fieldsc                 C   s   d| j |f S )Nz%s-%s)r3   rJ   r$   r$   r%   rs   ø  s    zBaseFormSet.add_prefixc                 C   s"   | j r| j d  ¡ S | j ¡ S dS )zv
        Return True if the formset needs to be multipart, i.e. it
        has FileInput, or False otherwise.
        r   N)rF   Úis_multipartrz   rG   r$   r$   r%   r¨   û  s    zBaseFormSet.is_multipartc                 C   s   | j r| j d jS | jjS d S r   )rF   Úmediarz   rG   r$   r$   r%   r©     s    zBaseFormSet.mediac                 C   s   | j jS rM   )r[   Zformset_template_namerG   r$   r$   r%   r*     s    zBaseFormSet.template_namec                 C   s   d| iS )NÚformsetr$   rG   r$   r$   r%   Úget_context  s    zBaseFormSet.get_context)6r&   r'   r(   r)   r	   r�   r   r‘   r¥   r   r0   Ztemplate_name_divZtemplate_name_pZtemplate_name_tableZtemplate_name_ulr   rD   rH   rL   rO   rP   rZ   r   rd   rX   r]   rF   rk   rj   Úpropertyri   ry   rz   r!   r„   r�   Úclassmethodr2   r�   r’   r“   r”   r–   r‚   rY   r\   r   r�   ru   rs   r¨   r©   r*   r«   r$   r$   r$   r%   r   6   sœ   ÿýýö÷

	
	






'




D	


r   r†   FNTc                 C   sn   |du rt }|du rt}|	du r(|t }	||	kr8tdƒ‚| ||||
|||	|||pTtƒ dœ}t| jd |f|ƒS )z*Return a FormSet for the given form class.Nz5'absolute_max' must be greater or equal to 'max_num'.)rc   rh   rŠ   r~   r§   r_   ra   rf   r    rŸ   r[   ZFormSet)ÚDEFAULT_MIN_NUMÚDEFAULT_MAX_NUMÚ
ValueErrorr   r=   r&   )rc   rª   rh   rŠ   r~   ra   rŸ   r_   r    rf   r§   r[   Úattrsr$   r$   r%   r     s*    õr   c                 C   s   t dd„ | D ƒƒS )z8Validate every formset and return True if all are valid.c                 S   s   g | ]}|  ¡ ‘qS r$   )rY   )rS   rª   r$   r$   r%   rn   C  rV   zall_valid.<locals>.<listcomp>)r™   )Zformsetsr$   r$   r%   r   @  s    r   )#Zdjango.core.exceptionsr   Zdjango.formsr   Zdjango.forms.fieldsr   r   Zdjango.forms.renderersr   Zdjango.forms.utilsr   r   Zdjango.forms.widgetsr	   r
   r   Zdjango.utils.functionalr   Zdjango.utils.translationr   r¥   r   Ú__all__r   r   r^   r`   r‹   r˜   r®   r¯   r   r   r   r   r$   r$   r$   r%   Ú<module>   sF      eô
*