
    hX                         d dl mZmZ d dlmZ d dlmZ d dlmZ ddlm	Z	m
Z
mZ  G d de
      Z G d	 d
ee	      ZeeddddddddddddddfdZy)    )BaseGenericInlineFormSetgeneric_inlineformset_factory)ContentType)models)	ModelForm   )BasePolymorphicModelFormSetPolymorphicFormSetChildpolymorphic_child_forms_factoryc                   .     e Zd ZdZ fdZd fd	Z xZS )GenericPolymorphicFormSetChildz+
    Formset child for generic inlines
    c                     |j                  dd      | _        |j                  dd      | _        t        |   |i | y )Nct_fieldcontent_typefk_field	object_id)popr   r   super__init__)selfargskwargs	__class__s      L/home/dcms/DCMS/lib/python3.12/site-packages/polymorphic/formsets/generic.pyr   z'GenericPolymorphicFormSetChild.__init__   s9    

:~>

:{;$)&)    c                    t        | j                        }|j                  dd      }|r|t        |      z  }| j                  j                  }|j                  | j                        }t        |t        j                        r|j                  j                  t        k7  rt        d| d      |j                  | j                        }|j                  |j                  |j                  g       ||d<   t!        | D  di |S )zA
        Construct the form class for the formset child.
        extra_excludeNz	fk_name 'z$' is not a ForeignKey to ContentTypeexclude )listr   r   model_meta	get_fieldr   
isinstancer   
ForeignKeyremote_fieldr   	Exceptionr   extendnamer   get_form)r   r   r   r   r   r   optsr   s          r   r*   z'GenericPolymorphicFormSetChild.get_form   s     t||$

?D9tM**G
 zz>>$--0 8V%6%67$$**k9iz1UVWW>>$--0x}}56#yw)&))r   )r   r   )__name__
__module____qualname____doc__r   r*   __classcell__)r   s   @r   r   r      s    *
* *r   r   c                       e Zd ZdZy)#BaseGenericPolymorphicInlineFormSetzC
    Polymorphic formset variation for inline generic formsets
    N)r,   r-   r.   r/   r   r   r   r2   r2   6   s    r   r2   r   r   NFTc                     i d| d|d|d|d|d|d|d|
d	|	d
|d|d|d|d|d|d|}|i }||d}|r|j                  |       t        di |}t        |fi ||_        |S )a  
    Construct the class for a generic inline polymorphic formset.

    All arguments are identical to :func:`~django.contrib.contenttypes.forms.generic_inlineformset_factory`,
    with the exception of the ``formset_children`` argument.

    :param formset_children: A list of all child :class:`PolymorphicFormSetChild` objects
                             that tell the inline how to render the child model types.
    :type formset_children: Iterable[PolymorphicFormSetChild]
    :rtype: type
    r!   formformfield_callbackformsetr   r   extra
can_delete	can_orderfieldsr   min_nummax_numvalidate_minvalidate_maxfor_concrete_model)r   r   r   )updater   r   child_forms)r!   formset_childrenr4   r6   r   r   r:   r   r7   r9   r8   r<   r5   r>   r?   r;   r=   child_form_kwargsr   child_kwargsFormSets                        r   )generic_polymorphic_inlineformset_factoryrF   <   s   D 	0 	7	
 	H 	H 	 	j 	Y 	& 	7 	7 	7 	 	  	0!F.   L
 -.+5f5G9:J[l[GNr   )!django.contrib.contenttypes.formsr   r   "django.contrib.contenttypes.modelsr   	django.dbr   django.forms.modelsr   r	   r
   r   r   r2   rF   r   r   r   <module>rK      sw    ;  ) #*%< #*L*BD_  
/ 
+Fr   