
    gR                         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e      Z G d de      Z e ddddddddddfdZ!d Z"y)    )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                   n     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         |          }|j                  t        d       |j                  t        d       |S Nr   )superclean
setdefaultTOTAL_FORM_COUNTINITIAL_FORM_COUNT)selfcleaned_data	__class__s     m/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/forms/formsets.pyr    zManagementForm.clean+   s8    w} 	 0!4 2A6    )__name__
__module____qualname____doc__r   r   r   r   r   r   r    __classcell__)r&   s   @r'   r   r      sB     k2K 4M !%DM %DM r(   r   c                      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 Z5y)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xs |d u| _         |xs | j                         | _        || _        |xs i | _        |xs i | _        || _        |xs i | _        || _        d | _	        d | _
        | j                  | _        | j                  xs
 t               | _        i }	t        t        |       j                         D ]  }
|	j#                  t%        |
di                ||	j#                  |       |	| _        y )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JB	[b
&,"& $!]]?)=)?DJ../COOGC)A2FG 0%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    DJJ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    zz%  r(   c                 ,    t        | j                        S N)lenrM   rN   s    r'   __len__zBaseFormSet.__len__x   s    4::r(   c                      y)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    
 r(   c           	      
   | j                   d}n:| j                  xr, | j                   xr t        d | j                   D               }d| j                  j
                  d| j                  d|d| j                         d	S )NUnknownc              3       K   | ]  }|  y wrU   rY   .0form_errorss     r'   	<genexpr>z'BaseFormSet.__repr__.<locals>.<genexpr>   s     H<KK<s   <z: bound=z valid=z total_forms=>)r>   r5   r?   anyr&   r+   total_form_count)r$   is_valids     r'   __repr__zBaseFormSet.__repr__   s|    << H  I---IH4<<HHH  NN''MM!!#	
 	
r(   c                    | j                   rIt        | j                  | j                  | j                  | j
                        }|j                          |S t        | j                  | j                  t        | j                         t        | j                         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"   re   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&&	 
D r(   c                 d   | j                   r1t        | j                  j                  t           | j
                        S | j                         }t        || j                        | j                  z   }|| j                  cxkD  rdk\  r|}|S  || j                  cxkD  rdk\  rn |S | j                  }|S )z1Return the total number of forms in this FormSet.r   )r5   minrq   r%   r"   absolute_maxrj   maxrl   extrarn   )r$   initial_formstotal_formss      r'   re   zBaseFormSet.total_form_count   s    ==
 $$112BCTEVEV  !335MmT\\:TZZGK t||0q0+ 	 1t||0q0 #ll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   rq   r%   r#   r;   rV   )r$   rw   s     r'   rj   zBaseFormSet.initial_form_count   s?    ==''445GHH 26C-1Mr(   c           
          t        | j                               D cg c]$  } | j                  |fi | j                  |      & c}S c c}w )z+Instantiate forms at first property access.)rangere   _construct_formget_form_kwargs)r$   is     r'   rM   zBaseFormSet.forms   sT     40023
3 !D  >d&:&:1&=>3
 	
 
s   )Ac                 6    | j                   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<   copyrQ   s     r'   r}   zBaseFormSet.get_form_kwargs   s     $$&&r(   c                    | j                   | j                  |      | j                  d| j                  d}| j                  r| j
                  |d<   | j                  |d<   | j                  rd|vr	 | j                  |   |d<   || j                         k\  r|| j                  k\  rd|d<   |j                  |        | j                  di |}| j                  ||       |S # t        $ r Y iw xY w)	z;Instantiate and return the i-th form instance in a formset.F)r8   r7   r=   use_required_attributer@   r9   r:   r;   Tempty_permittedrY   )r8   
add_prefixr=   rA   r5   r9   r:   r;   
IndexErrorrj   rl   rE   rp   
add_fields)r$   r~   kwargsdefaultsrp   s        r'   r|   zBaseFormSet._construct_form   s     ||ooa(++ ',**	
 ==#yyHV $

HW<<IV3&*ll1o#
 ''))a4<<.?*.H&'tyy$8$a   s   1C! !	C-,C-c                 <    | j                   d| j                          S )z7Return a list of all the initial forms in this formset.NrM   rj   rN   s    r'   rw   zBaseFormSet.initial_forms   s     zz5D33566r(   c                 <    | j                   | j                         d S )z5Return a list of all the extra forms in this formset.Nr   rN   s    r'   extra_formszBaseFormSet.extra_forms   s     zz$113566r(   c                     i | j                  d       | j                  | j                  d      dd| j                  d} | j                  di |}| j                  |d        |S )N
__prefix__TF)r8   r7   r   r   r@   rY   )r}   r8   r   rA   rp   r   )r$   r<   rp   s      r'   
empty_formzBaseFormSet.empty_form  sk    
""4(
||ool3#&+**
 tyy';'d#r(   c                     | j                         s"t        d| j                  j                  z        | j                  D cg c]  }|j
                   c}S c c}w )zX
        Return a list of form.cleaned_data dicts for every form in self.forms.
        z+'%s' object has no attribute 'cleaned_data')rf   AttributeErrorr&   r)   rM   r%   ro   s     r'   r%   zBaseFormSet.cleaned_data  sP    
 }} =@W@WW  /3jj9jd!!j999s   Ac                    | j                         r| j                  sg S t        | d      sug | _        t	        | j
                        D ]V  \  }}|| j                         k\  r|j                         s*| j                  |      s<| j                  j                  |       X | j                  D cg c]  }| j
                  |    c}S c c}w )z:Return a list of forms that have been marked for deletion._deleted_form_indexes)
rf   
can_deletehasattrr   	enumeraterM   rj   has_changed_should_delete_formappend)r$   r~   rp   s      r'   deleted_formszBaseFormSet.deleted_forms  s     }}dooI t45)+D&$TZZ04//11$:J:J:L++D1..55a8 1 (,'A'AB'A!

1'ABBBs   .Cc                 Z   | j                         r| j                  s"t        d| j                  j                  z        t        | d      sg | _        t        | j                        D ]u  \  }}|| j                         k\  r|j                         s*| j                  r| j                  |      rH| j                  j                  ||j                  t           f       w d }| j                  j!                  |       | j                  D cg c]  }| j                  |d       c}S c c}w )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   yd| d   fS )N   )r   r   r   rY   )ks    r'   compare_ordering_keyz7BaseFormSet.ordered_forms.<locals>.compare_ordering_keyJ  s    Q4<!1Q4y r(   )keyr   )rf   	can_orderr   r&   r)   r   r   r   rM   rj   r   r   r   r   r%   ORDERING_FIELD_NAMEsort)r$   r~   rp   r   s       r'   ordered_formszBaseFormSet.ordered_forms,  s     }}dnn >AXAXX  t[)DN$TZZ04//11$:J:J:L??t'?'?'E%%q$*;*;<O*P&QR 1!
 NN$89 +/..9.Q

1Q4 .999s   D(c                      y)Nrp   rY   rI   s    r'   r6   zBaseFormSet.get_default_prefixT  s    r(   c                     | j                   S rU   )deletion_widgetr   s    r'   get_deletion_widgetzBaseFormSet.get_deletion_widgetX      """r(   c                     | j                   S rU   )ordering_widgetr   s    r'   get_ordering_widgetzBaseFormSet.get_ordering_widget\  r   r(   c                 R    | j                   | 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?   ri   rN   s    r'   non_form_errorszBaseFormSet.non_form_errors`  s&       (OO$$$r(   c                 R    | j                   | j                          | j                   S )z:Return a list of form.errors for every form in self.forms.)r>   ri   rN   s    r'   errorszBaseFormSet.errorsj  s"     <<OO||r(   c                 n    t        | j                               t        d | j                  D              z   S )z<Return the number of errors across all forms in the formset.c              3   2   K   | ]  }t        |        y wrU   )rV   r^   s     r'   ra   z0BaseFormSet.total_error_count.<locals>.<genexpr>s  s      1
0;Cs   )rV   r   sumr   rN   s    r'   total_error_countzBaseFormSet.total_error_countq  s5    4'')*S 1
041
 .
 
 	
r(   c                 B    |j                   j                  t        d      S )z7Return whether or not the form was marked for deletion.F)r%   getDELETION_FIELD_NAMEro   s     r'   r   zBaseFormSet._should_delete_formw  s      $$%8%@@r(   c                    | j                   sy| j                   t        | j                  D cg c]/  }| j                  r| j                  |      s|j                         1 c}      }|xr | j                          S c c}w )z1Return True if every form in self.forms is valid.F)r5   r   allrM   r   r   rf   r   )r$   rp   forms_valids      r'   rf   zBaseFormSet.is_valid{  sx    }}  !JJ&DD,D,DT,J &
 94#7#7#999s   4A=c                 (    g  _          j                  d j                         _        d} j                  sy j
                  j                         sdt         j                  d   ddj                   fd j
                  j                  D              id	      } j                  j                  |       t         j                        D ]r  \  }}|j                         s| j                         k\  r|d
z  }|j                  } j                   r j#                  |      rX j                   j                  |       t 	  j$                  r3 j'                         t)         j*                        z
   j,                  kD  s* j
                  j.                  t0            j2                  kD  r)t         j                  d   d j,                  iz  d       j4                  r_ j'                         t)         j*                        z
  |z
   j6                  k  r)t         j                  d   d j6                  iz  d       j9                          y# t        $ r7} j                  |j:                  d j                         _        Y d}~y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   T   K   | ]  }j                   j                  |       ! y wrU   )rq   r   )r_   
field_namer$   s     r'   ra   z)BaseFormSet.full_clean.<locals>.<genexpr>  s*      -*EJ ,,77
C*Es   %()paramscoder   r1   r/   )r   r2   )r>   r=   r@   r?   r5   rq   rf   r   rG   joinr   r   r   rM   r   rj   r   r   validate_maxre   rV   r   rn   r%   r"   rt   validate_minrl   r    
error_list)r$   empty_forms_counterrorr~   rp   r`   es   `      r'   ri   zBaseFormSet.full_clean  s_   
  $ 0 0!DMM !1 !
 }}##,,.###$=>!499 -*.*>*>*E*E- $ /	E !!((/ ,GAt##%!t/F/F/H*H!Q&! ++K4#;#;D#ALL, -	!!))+c$2D2D.EET%%22 !!" &''(89UDLL<QQ) 
 !!))+d(()*#$ ,,
 &''8E4<<;PP( 
 JJL 	$($4$4% %5 %D!!	s   DI 	J-JJc                      y)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()
        NrY   rN   s    r'   r    zBaseFormSet.clean  s     	r(   c                 &    t        d | D              S )z5Return True if data in any form differs from initial.c              3   <   K   | ]  }|j                           y wrU   )r   )r_   rp   s     r'   ra   z*BaseFormSet.has_changed.<locals>.<genexpr>  s     7$$4##%$s   )rd   rN   s    r'   r   zBaseFormSet.has_changed  s    7$777r(   c                    | j                         }| j                  rx|@||k  r;t        t        d      |dz   d| j	                               |j
                  t        <   n6t        t        d      d| j	                               |j
                  t        <   | j                  rL| j                  s|=||k  r7t        t        d      d| j                               |j
                  t        <   yyyy)z8A hook for adding extra fields on to each form instance.NOrderr   F)labelr;   r   r   )r   r   r   Delete)rj   r   r   _r   fieldsr   r   can_delete_extrar   r   r   )r$   rp   rR   rj   s       r'   r   zBaseFormSet.add_fields  s    !446>> U-?%?3?G*!AI"335	4/0 4@G*"3354/0
 ??!!e&7EDV<V/;k//10DKK+, =W&7 r(   c                 $    | j                   d|S )N-)r7   rQ   s     r'   r   zBaseFormSet.add_prefix  s    ++u--r(   c                     | j                   r| j                   d   j                         S | j                  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  s5    
 ::::a=--//??//11r(   c                 x    | 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 rU   )r@   formset_template_namerN   s    r'   template_namezBaseFormSet.template_name  s    }}222r(   c                 
    d| iS )NformsetrY   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   rS   rW   rZ   rg   r   rq   re   rj   rM   r}   r|   propertyrw   r   r   r%   r   r   classmethodr6   r   r   r   r   r   r   rf   ri   r    r   r   r   r   r   r   r   rY   r(   r'   r   r   4   s	    $O!O#$X$
 (12

 '23
" 94O<6 '> !
   0* 
 
': 7 7 7 7   : : C C  %: %:N   # # # #%  
A:"BH86.2 ) ) 3 3!r(   r   r   FNTc                     |t         }|t        }|		|t        z   }	||	kD  rt        d      | ||||
|||	|||d}t        | j                  dz   |f|      S )z*Return a FormSet for the given form class.z5'absolute_max' must be greater or equal to 'max_num'.)rp   rv   r   r   r   rl   rn   rt   r   r   r@   FormSet)DEFAULT_MIN_NUMDEFAULT_MAX_NUM
ValueErrorrC   r)   )rp   r   rv   r   r   rn   r   rl   r   rt   r   r@   attrss                r'   r   r     s     !! 0PQQ ,$$$E 	)G:u==r(   c                 Z    t        | D cg c]  }|j                          c}      S c c}w )z8Validate every formset and return True if all are valid.)r   rf   )formsetsr   s     r'   r   r   @  s*     (;(w  "(;<<;s   ()#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#   rk   rm   r   r   r   r   r   r   r   r   rY   r(   r'   <module>r      s    2 : # 7 = H H 3 6 2
9 ! $ $ $     T 0_!% _!H 
'>T=r(   