
    h                         d Z ddlZddlmZ ddlmZmZmZ dZ G d d      Z	 G d d	e	ej                        Z G d
 de	ej                        Z G d de	ej                        Zy)z
The ``extra_views.formsets`` provides a simple way to handle formsets.
The ``extra_views.advanced`` provides a method to combine that with a create/update form.

This package provides classes that support both options for polymorphic formsets.
    N)ImproperlyConfigured)BasePolymorphicInlineFormSetBasePolymorphicModelFormSetpolymorphic_child_forms_factory)PolymorphicFormSetViewPolymorphicInlineFormSetViewPolymorphicInlineFormSetc                   >     e Zd ZdZeZddiZdZd Zd Z	 fdZ
 xZS )PolymorphicFormSetMixinza
    Internal Mixin, that provides polymorphic integration with the ``extra_views`` package.
    extrar   Nc                 H    | j                   st        d      | j                   S )z7
        :rtype: list[PolymorphicFormSetChild]
        z>Define 'formset_children' as list of `PolymorphicFormSetChild`)formset_childrenr   selfs    O/home/dcms/DCMS/lib/python3.12/site-packages/polymorphic/contrib/extra_views.pyget_formset_childrenz,PolymorphicFormSetMixin.get_formset_children&   s+     $$&P  $$$    c                     i S )N r   s    r   get_formset_child_kwargsz0PolymorphicFormSetMixin.get_formset_child_kwargs0   s    	r   c                 ~    t         |          }t        | j                         fi | j	                         |_        |S )zK
        Returns the formset class from the inline formset factory
        )superget_formsetr   r   r   child_forms)r   FormSet	__class__s     r   r   z#PolymorphicFormSetMixin.get_formset3   sC     '%'=%%'
+/+H+H+J
 r   )__name__
__module____qualname____doc__r   formset_classfactory_kwargsr   r   r   r   __classcell__)r   s   @r   r   r      s6     0M q\N % r   r   c                       e Zd ZdZeZy)r   a  
    A view that displays a single polymorphic formset.

    .. code-block:: python

        from polymorphic.formsets import PolymorphicFormSetChild


        class ItemsView(PolymorphicFormSetView):
            model = Item
            formset_children = [
                PolymorphicFormSetChild(ItemSubclass1),
                PolymorphicFormSetChild(ItemSubclass2),
            ]

    N)r   r   r   r    r   r!   r   r   r   r   r   B   s    " 0Mr   r   c                       e Zd ZdZeZy)r   a$  
    A view that displays a single polymorphic formset - with one parent object.
    This is a variation of the :mod:`extra_views` package classes for django-polymorphic.

    .. code-block:: python

        from polymorphic.formsets import PolymorphicFormSetChild


        class OrderItemsView(PolymorphicInlineFormSetView):
            model = Order
            inline_model = Item
            formset_children = [
                PolymorphicFormSetChild(ItemSubclass1),
                PolymorphicFormSetChild(ItemSubclass2),
            ]
    Nr   r   r   r    r   r!   r   r   r   r   r   W   s    $ 1Mr   r   c                       e Zd ZdZeZy)r	   a  
    An inline to add to the ``inlines`` of
    the :class:`~extra_views.advanced.CreateWithInlinesView`
    and :class:`~extra_views.advanced.UpdateWithInlinesView` class.

    .. code-block:: python

        from polymorphic.formsets import PolymorphicFormSetChild


        class ItemsInline(PolymorphicInlineFormSet):
            model = Item
            formset_children = [
                PolymorphicFormSetChild(ItemSubclass1),
                PolymorphicFormSetChild(ItemSubclass2),
            ]


        class OrderCreateView(CreateWithInlinesView):
            model = Order
            inlines = [ItemsInline]

            def get_success_url(self):
                return self.object.get_absolute_url()

    Nr&   r   r   r   r	   r	   m   s    6 1Mr   r	   )r    extra_viewsdjango.core.exceptionsr   polymorphic.formsetsr   r   r   __all__r   ModelFormSetViewr   InlineFormSetViewr   InlineFormSetFactoryr	   r   r   r   <module>r/      sm     7 ' 'T04k6R6R 0*1#:K<Y<Y 1,168X8X 1r   