
    afR                        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e          Z G d de          Z e ddddddddddfdZ!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_FORMSORDERDELETEi  c                        e Zd ZdZ ee          Z ee          Z ede          Z ede          Z	 fdZ
 x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                     t                                                      }|                    t          d           |                    t          d           |S Nr   )superclean
setdefaultTOTAL_FORM_COUNTINITIAL_FORM_COUNT)selfcleaned_data	__class__s     G/var/www/html/env/lib/python3.11/site-packages/django/forms/formsets.pyr    zManagementForm.clean+   sJ    ww}} 	 0!444 2A666    )__name__
__module____qualname____doc__r   r   r   r   r   r   r    __classcell__)r&   s   @r'   r   r      s          ,k222K L444M !L%DDDM L%DDDM        r(   r   c                   8   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Zd Zd Zd Zd Zd Zed             Zd Zd Zed             Zd Zd Zed             Zed             Zed             Z ed             Z!ed             Z"ed              Z#e$d!             Z%e$d"             Z&e$d#             Z'd$ Z(ed%             Z)d& Z*d' Z+d( Z,d) Z-d* Z.d+ Z/d, Z0d- Z1d. Z2ed/             Z3ed0             Z4d1 Z5dS )2r   z;
    A collection of instances of the same Form class.
    zManagementForm 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	                    |d up|d u| _         |p|                                 | _        || _        |pi | _        |pi | _        || _        |pi | _        || _        d | _	        d | _
        | j        | _        | j        pt                      | _        i }	t          t          |           j                  D ]&}
|	                    t%          |
di                      '||	                    |           |	| _        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$   r9   r:   r8   r7   r;   r=   r<   rG   messagesclss              r'   __init__zBaseFormSet.__init__Q   s    D(=E,=9 7 7 9 9JB	[b
&,"& $!]?)=)?)?DJJ.// 	H 	HCOOGC)A2FFGGGG%OON+++&r(   c                 *    t          | j                  S )z5Yield the forms in the order they should be rendered.)iterformsr$   s    r'   __iter__zBaseFormSet.__iter__p   s    DJr(   c                     | j         |         S )zAReturn the form at the given index, based on the rendering order.rM   r$   indexs     r'   __getitem__zBaseFormSet.__getitem__t   s    z%  r(   c                 *    t          | j                  S N)lenrM   rN   s    r'   __len__zBaseFormSet.__len__x   s    4:r(   c                     dS )zt
        Return True since all formsets have a management form which is not
        included in the length.
        T rN   s    r'   __bool__zBaseFormSet.__bool__{   s	    
 tr(   c           	          | j         d}n.| j        o&| j         ot          d | j         D                        }d| j        j        d| j        d|d|                                 d	S )NUnknownc              3      K   | ]}|V  d S rV   rZ   .0form_errorss     r'   	<genexpr>z'BaseFormSet.__repr__.<locals>.<genexpr>   s"      HHKKHHHHHHr(   <z: bound=z valid=z total_forms=>)r>   r5   r?   anyr&   r+   total_form_count)r$   is_valids     r'   __repr__zBaseFormSet.__repr__   s    < HH  I--IHH4<HHHHHH  N'''MMMHH!!####	
 	
r(   c                 d   | j         r<t          | j        | j        | j        | j                  }|                                 nlt          | j        | j        t          |                                 t          | 
                                t          | j        t          | j        i| j                  }|S )z4Return the ManagementForm instance for this FormSet.)r8   r7   r@   )r8   r7   r;   r@   )r5   r   r9   r8   r7   r@   
full_cleanr"   rf   r#   initial_form_countMIN_NUM_FORM_COUNTmin_numMAX_NUM_FORM_COUNTmax_numr$   forms     r'   management_formzBaseFormSet.management_form   s     = 	!	{	  D OO!{$d&;&;&=&=&(?(?(A(A&&	 
 
 
D r(   c                 2   | j         r*t          | j        j        t                   | j                  S |                                 }t          || j                  | j	        z   }|| j
        cxk    rdk    rn n|}n|| j
        cxk    rdk    r
n n| j
        }|S )z1Return the total number of forms in this FormSet.r   )r5   minrr   r%   r"   absolute_maxrk   maxrm   extraro   )r$   initial_formstotal_formss      r'   rf   zBaseFormSet.total_form_count   s    = 	+
 $12BCTEV   !3355MmT\::TZGK t|0000q00000+t|0000q00000"lr(   c                 |    | 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   )r5   rr   r%   r#   r;   rW   )r$   rx   s     r'   rk   zBaseFormSet.initial_form_count   sB    = 	E'45GHH 26DC---1Mr(   c                 ^      fdt                                                     D             S )z+Instantiate forms at first property access.c           	      R    g | ]#} j         |fi                     |          $S rZ   )_construct_formget_form_kwargsr`   ir$   s     r'   
<listcomp>z%BaseFormSet.forms.<locals>.<listcomp>   sL     
 
 
 !D >>d&:&:1&=&=>>
 
 
r(   )rangerf   rN   s   `r'   rM   zBaseFormSet.forms   sB    
 
 
 
4002233
 
 
 	
r(   c                 4    | 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.
        )r<   copyrR   s     r'   r~   zBaseFormSet.get_form_kwargs   s     $$&&&r(   c                    | j         |                     |          | j        d| j        d}| j        r| j        |d<   | j        |d<   | j        r&d|vr"	 | j        |         |d<   n# t          $ r Y nw xY w|| 	                                k    r|| j
        k    rd|d<   |                    |            | j        di |}|                     ||           |S )	z;Instantiate and return the i-th form instance in a formset.F)r8   r7   r=   use_required_attributer@   r9   r:   r;   Tempty_permittedrZ   )r8   
add_prefixr=   rA   r5   r9   r:   r;   
IndexErrorrk   rm   rE   rq   
add_fields)r$   r   kwargsdefaultsrq   s        r'   r}   zBaseFormSet._construct_form   s    |ooa((+ ',*	
 	
 = 	+#yHV $
HW< 	IV33&*l1o##    ''))))a4<.?.?*.H&'ty$$8$$a   s   A# #
A0/A0c                 D    | j         d|                                          S )z7Return a list of all the initial forms in this formset.NrM   rk   rN   s    r'   rx   zBaseFormSet.initial_forms   s#     z5D3355566r(   c                 D    | j         |                                 d         S )z5Return a list of all the extra forms in this formset.Nr   rN   s    r'   extra_formszBaseFormSet.extra_forms   s#     z$11335566r(   c                     i |                      d           | j        |                     d          dd| j        d} | j        di |}|                     |d            |S )N
__prefix__TF)r8   r7   r   r   r@   rZ   )r~   r8   r   rA   rq   r   )r$   r<   rq   s      r'   
empty_formzBaseFormSet.empty_form  s    
""4((
|ool33#&+*
 
 
 ty'';''d###r(   c                     |                                  st          d| j        j        z            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                     g | ]	}|j         
S rZ   )r%   r`   rq   s     r'   r   z,BaseFormSet.cleaned_data.<locals>.<listcomp>  s    999d!999r(   )rg   AttributeErrorr&   r)   rM   rN   s    r'   r%   zBaseFormSet.cleaned_data  sK    
 }} 	 =@WW   :9dj9999r(   c                 ~                                      r j        sg S t           d          s}g  _        t	           j                  D ]a\  }}|                                 k    r|                                s2                     |          r j        	                    |           b fd j        D             S )z:Return a list of forms that have been marked for deletion._deleted_form_indexesc                 *    g | ]}j         |         S rZ   rQ   r   s     r'   r   z-BaseFormSet.deleted_forms.<locals>.<listcomp>*  s    BBB!
1BBBr(   )
rg   
can_deletehasattrr   	enumeraterM   rk   has_changed_should_delete_formappend)r$   r   rq   s   `  r'   deleted_formszBaseFormSet.deleted_forms  s     }} 	do 	I t455 	9)+D&$TZ00 9 94//1111$:J:J:L:L1++D11 9.55a888BBBBt'ABBBBr(   c                 "                                      r j        st          d j        j        z            t           d          sg  _        t           j                  D ]{\  }}| 	                                k    r|
                                s2 j        r                     |          rO j                            ||j        t                   f           |d } j                            |            f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                 *    | d         dS d| d         fS )N   )r   r   r   rZ   )ks    r'   compare_ordering_keyz7BaseFormSet.ordered_forms.<locals>.compare_ordering_keyJ  s    Q4<!61Q4y r(   )keyc                 6    g | ]}j         |d                   S )r   rQ   r   s     r'   r   z-BaseFormSet.ordered_forms.<locals>.<listcomp>R  s$    999Q
1Q4 999r(   )rg   	can_orderr   r&   r)   r   r   r   rM   rk   r   r   r   r   r%   ORDERING_FIELD_NAMEsort)r$   r   rq   r   s   `   r'   ordered_formszBaseFormSet.ordered_forms,  s4    }} 	dn 	 >AXX   t[)) 	:DN$TZ00 S S4//1111$:J:J:L:L1? t'?'?'E'E %%q$*;<O*P&QRRRR! ! !
 N$8999 :999$.9999r(   c                     dS )Nrq   rZ   rI   s    r'   r6   zBaseFormSet.get_default_prefixT  s    vr(   c                     | j         S rV   )deletion_widgetr   s    r'   get_deletion_widgetzBaseFormSet.get_deletion_widgetX      ""r(   c                     | j         S rV   )ordering_widgetr   s    r'   get_ordering_widgetzBaseFormSet.get_ordering_widget\  r   r(   c                 F    | j         |                                  | 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.
        )r?   rj   rN   s    r'   non_form_errorszBaseFormSet.non_form_errors`  s&      (OO$$r(   c                 F    | j         |                                  | j         S )z:Return a list of form.errors for every form in self.forms.)r>   rj   rN   s    r'   errorszBaseFormSet.errorsj  s$     <OO|r(   c                     t          |                                           t          d | j        D                       z   S )z<Return the number of errors across all forms in the formset.c              3   4   K   | ]}t          |          V  d S rV   )rW   r_   s     r'   rb   z0BaseFormSet.total_error_count.<locals>.<genexpr>s  s;       1
 1
!,C1
 1
 1
 1
 1
 1
r(   )rW   r   sumr   rN   s    r'   total_error_countzBaseFormSet.total_error_countq  sM    4''))**S 1
 1
041
 1
 1
 .
 .
 
 	
r(   c                 B    |j                             t          d          S )z7Return whether or not the form was marked for deletion.F)r%   getDELETION_FIELD_NAMErp   s     r'   r   zBaseFormSet._should_delete_formw  s     $$%8%@@@r(   c                       j         sdS  j         t           fd j        D                       }|o                                  S )z1Return True if every form in self.forms is valid.Fc                 p    g | ]2}j         r                    |          |                                3S rZ   )r   r   rg   )r`   rq   r$   s     r'   r   z(BaseFormSet.is_valid.<locals>.<listcomp>  sQ        -1,D,DT,J,J  r(   )r5   r   allrM   r   )r$   forms_valids   ` r'   rg   zBaseFormSet.is_valid{  sn    } 	5     J  
 
 94#7#7#9#999r(   c                     g  _                              d j                   _        d} j        sdS  j                                        sbt           j        d         dd	                     fd j        j
        D                       id	          } j                            |           t           j                  D ]t\  }}|                                s|                                 k    r|d
z  }|j
        } j        r                     |          rZ j                             |           u	  j        r2                                 t)           j                  z
   j        k    s  j        j        t0                    j        k    r&t           j        d         d j        iz  d           j        r[                                 t)           j                  z
  |z
   j        k     r&t           j        d         d j        iz  d                                            dS # t          $ r2}                     |j        d j                   _        Y d}~dS d}~ww xY w)ze
        Clean all of self.data and populate self._errors and
        self._non_form_errors.
        nonform)r=   r@   r   Nr0   field_namesz, c              3   L   K   | ]}j                             |          V  d S rV   )rr   r   )r`   
field_namer$   s     r'   rb   z)BaseFormSet.full_clean.<locals>.<genexpr>  sH       - -& ,77
CC- - - - - -r(   )paramscoder   r1   r/   )r   r2   )r>   r=   r@   r?   r5   rr   rg   r   rG   joinr   r   r   rM   r   rk   r   r   validate_maxrf   rW   r   ro   r%   r"   ru   validate_minrm   r    
error_list)r$   empty_forms_counterrorr   rq   ra   es   `      r'   rj   zBaseFormSet.full_clean  s   
  $ 0 0!DM !1 !
 !
 } 	F#,,.. 	0##$=>!499 - - - -*.*>*E- - - $ $ /	 	 	E !((/// ,, 		- 		-GAt##%% '!t/F/F/H/H*H*H!Q&! +K 4#;#;D#A#A L,,,,	!	))++c$2D.E.EETT%2 !" " &'(89UDL<QQ)   
 !
))++d())*#$ , 
 &'8E4<;PP(   
 JJLLLLL 	 	 	$($4$4% %5 % %D!!!!!!!	s   :C5H1 1
I-;'I((I-c                     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()
        NrZ   rN   s    r'   r    zBaseFormSet.clean  s	     	r(   c                 4    t          d | D                       S )z5Return True if data in any form differs from initial.c              3   >   K   | ]}|                                 V  d S rV   )r   r   s     r'   rb   z*BaseFormSet.has_changed.<locals>.<genexpr>  s.      77$4##%%777777r(   )re   rN   s    r'   r   zBaseFormSet.has_changed  s    77$777777r(   c                    |                                  }| j        r|I||k     rCt          t          d          |dz   d|                                           |j        t          <   n>t          t          d          d|                                           |j        t          <   | j        rO| j        s|H||k     rDt          t          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)labelr;   r   r   )r   r   r   Delete)rk   r   r   _r   fieldsr   r   can_delete_extrar   r   r   )r$   rq   rS   rk   s       r'   r   zBaseFormSet.add_fields  s%   !4466> 	 U-?%?%?3?G**!AI"3355	4 4 4/00 4@G**"33554 4 4/0
 ? 	!	&+&7EDV<V<V/;kk//110 0 0DK+,,,	 	&7&7<V<Vr(   c                     | j         d|S )N-)r7   rR   s     r'   r   zBaseFormSet.add_prefix  s    +++uu--r(   c                     | 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   )rM   is_multipartr   rN   s    r'   r   zBaseFormSet.is_multipart  s:    
 : 	2:a=--///?//111r(   c                 L    | j         r| j         d         j        S | j        j        S r   )rM   mediar   rN   s    r'   r   zBaseFormSet.media  s(     : 	):a=&&?((r(   c                     | j         j        S rV   )r@   formset_template_namerN   s    r'   template_namezBaseFormSet.template_name  s    }22r(   c                 
    d| iS )NformsetrZ   rN   s    r'   get_contextzBaseFormSet.get_context  s    4  r(   )6r)   r*   r+   r,   r
   r   r   r   r   r   r4   template_name_divtemplate_name_ptemplate_name_tabletemplate_name_ulr   rJ   rO   rT   rX   r[   rh   r   rr   rf   rk   rM   r~   r}   propertyrx   r   r   r%   r   r   classmethodr6   r   r   r   r   r   r   rg   rj   r    r   r   r   r   r   r   r   rZ   r(   r'   r   r   4   sx         $O!O#$1X$
 $
 (-12
 

 '23
 
 " 94O<6 ' ' ' '>     ! ! !    
 
 
    _0  *   
 
 _
' ' '  : 7 7 X7 7 7 X7   X : : X: C C XC  %: %: X%:N   [ # # [# # # [#% % %   X
 
 
A A A: : :"B B BH  8 8 8  6. . .2 2 2 ) ) X) 3 3 X3! ! ! ! !r(   r   r   FNTc                     |t           }|t          }|	
|t          z   }	||	k    rt          d          | ||||
|||	|||d}t          | j        dz   |f|          S )z*Return a FormSet for the given form class.Nz5'absolute_max' must be greater or equal to 'max_num'.)rq   rw   r   r   r   rm   ro   ru   r   r   r@   FormSet)DEFAULT_MIN_NUMDEFAULT_MAX_NUM
ValueErrorrC   r)   )rq   r   rw   r   r   ro   r   rm   r   ru   r   r@   attrss                r'   r   r     s     !! 0PQQQ ,$$$ E 	)G:u===r(   c                 4    t          d | D                       S )z8Validate every formset and return True if all are valid.c                 6    g | ]}|                                 S rZ   )rg   )r`   r   s     r'   r   zall_valid.<locals>.<listcomp>C  s$    ;;;w  "";;;r(   )r   )formsetss    r'   r   r   @  s!     ;;(;;;<<<r(   )#django.core.exceptionsr   django.formsr   django.forms.fieldsr   r   django.forms.renderersr   django.forms.utilsr   r	   django.forms.widgetsr
   r   r   django.utils.functionalr   django.utils.translationr   r   r   __all__r"   r#   rl   rn   r   r   r   r   r   r   r   r   rZ   r(   r'   <module>r     s   2 2 2 2 2 2       : : : : : : : : 7 7 7 7 7 7 = = = = = = = = H H H H H H H H H H 3 3 3 3 3 3 6 6 6 6 6 6 2 2 2 2 2 2
9 ! $ $ $         T   0_! _! _! _! _!% _! _! _!H 
'> '> '> '>T= = = = =r(   