a
    Dg0                     @   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
 d dlmZ d dlmZ d dlmZ d d	lmZ efd
dZG dd dZdS )    )ImproperlyConfigured)	mark_safe)WagtailAdminDraftStateFormMixinWagtailAdminModelForm)	Component)StreamValue)safe_snake_case)DraftStateMixin)RichText)text_from_htmlc           	      K   s   |}| |d< d|vr$d|vr$g |d< | j d }t|dr@|jfnd}td||}d|i}t|}|g}t| tr||dt ||t||S )z
    Construct a ModelForm subclass using the given model and base form class. Any additional
    keyword arguments are used to populate the form's Meta class.
    modelfieldsexcludeZFormMeta r   )	__name__hasattrr   type
issubclassr	   insertr   tuple)	r   
form_classkwargsZmeta_class_attrs
class_namebasesr   Zform_class_attrs	metaclassr   r   X/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/admin/panels/base.pyget_form_for_model   s    

r   c                   @   s   e Zd ZdZi Zd!ddZdd Zdd	 Zd
d Zdd Z	dd Z
d"ddZdd Zdd Zdd Zdd Zedd Zdd ZG dd  d eZdS )#Panela  
    Defines part (or all) of the edit form interface for pages and other models
    within the Wagtail admin. Each model has an associated top-level panel definition
    (also known as an edit handler), consisting of a nested structure of ``Panel`` objects.
    This provides methods for obtaining a :class:`~django.forms.ModelForm` subclass,
    with the field list and other parameters collated from all panels in the structure.
    It then handles rendering that form as HTML.

    The following parameters can be used to customize how the panel is displayed.
    For more details, see :ref:`customizing_panels`.

    :param heading: The heading text to display for the panel.
    :param classname: A CSS class name to add to the panel's HTML element.
    :param help_text: Help text to display within the panel.
    :param base_form_class: The base form class to use for the panel. Defaults to the model's ``base_form_class``, before falling back to :class:`~wagtail.admin.forms.WagtailAdminModelForm`. This is only relevant for the top-level panel.
    :param icon: The name of the icon to display next to the panel heading.
    :param attrs: A dictionary of HTML attributes to add to the panel's HTML element.
     Nc                 C   sH   || _ || _|| _|| _|| _d | _| j | _|d urD| j	| d S N)
heading	classname	help_textbase_form_classiconr   
BASE_ATTRScopyattrsupdate)selfr!   r"   r#   r$   r%   r(   r   r   r   __init__I   s    	zPanel.__init__c                 C   s   | j f i |  S )z
        Create a clone of this panel definition. By default, constructs a new instance, passing the
        keyword arguments returned by ``clone_kwargs``.
        )	__class__clone_kwargsr*   r   r   r   clone]   s    zPanel.clonec                 C   s   | j | j| j| j| j| jdS )zw
        Return a dictionary of keyword arguments that can be used to create a clone of this panel definition.
        r%   r(   r!   r"   r#   r$   r0   r.   r   r   r   r-   d   s    zPanel.clone_kwargsc                 C   s   i S )a0  
        Return a dictionary of attributes such as 'fields', 'formsets' and 'widgets'
        which should be incorporated into the form class definition to generate a form
        that this panel can use.
        This will only be called after binding to a model (i.e. self.model is available).
        r   r.   r   r   r   get_form_optionsq   s    zPanel.get_form_optionsc                 C   s6   |   }t| jdt}| jp|}t| jfd|i|S )z
        Construct a form class that has all the fields and formsets named in
        the children of this edit handler.
        r$   r   )r1   getattrr   r   r$   r   )r*   Zform_optionsZmodel_form_classr$   r   r   r   get_form_classz   s    
zPanel.get_form_classc                 C   s   |   }||_|  |S )zx
        Create a clone of this panel definition with a ``model`` attribute pointing to the linked model class.
        )r/   r   on_model_bound)r*   r   newr   r   r   bind_to_model   s    zPanel.bind_to_modelpanelc                 C   sP   | j du rtdt| j t| jtjs<tdt| j | j| ||||dS )z
        Return a ``BoundPanel`` instance that can be rendered onto the template as a component. By default, this creates an instance
        of the panel class's inner ``BoundPanel`` class, which must inherit from ``Panel.BoundPanel``.
        Nz=%s.bind_to_model(model) must be called before get_bound_panelz4%s.BoundPanel must be a subclass of Panel.BoundPanel)r7   instancerequestformprefix)r   r   r   r   r   
BoundPanelr   )r*   r8   r9   r:   r;   r   r   r   get_bound_panel   s    

zPanel.get_bound_panelc                 C   s   dS )z
        Called after the panel has been associated with a model class and the ``self.model`` attribute is available;
        panels can override this method to perform additional initialisation related to the model.
        Nr   r.   r   r   r   r4      s    zPanel.on_model_boundc                 C   s   d | jj| jS )Nz<{} with model={}>)formatr,   r   r   r.   r   r   r   __repr__   s    zPanel.__repr__c                 C   s   | j r| j gS g S )z
        Additional CSS classnames to add to whatever kind of object this is at output.
        Subclasses of Panel should override this, invoking super().classes() to
        append more classes specific to the situation.
        )r"   r.   r   r   r   classes   s    zPanel.classesc                 C   s   dS )z
        The ID to be used as the 'for' attribute of any <label> elements that refer
        to this object but are rendered outside of it. Leave blank if this object does not render
        as a single input field.
        r   r   r.   r   r   r   id_for_label   s    zPanel.id_for_labelc                 C   s
   t | jS )ac  
        A name for this panel, consisting only of ASCII alphanumerics and underscores, suitable for use in identifiers.
        Usually generated from the panel heading. Note that this is not guaranteed to be unique or non-empty; anything
        making use of this and requiring uniqueness should validate and modify the return value as needed.
        )r   r!   r.   r   r   r   
clean_name   s    zPanel.clean_namec                 C   sF   t t|ddr,ddd | D p*dS t|ttfrBt|S |S )a  
        Hook to allow formatting of raw field values (and other attribute values) for human-readable
        display. For example, if rendering a ``RichTextField`` value, you might extract text from the HTML
        to generate a safer display value.
        allr   z, c                 s   s   | ]}t |V  qd S r    )str).0objr   r   r   	<genexpr>       z1Panel.format_value_for_display.<locals>.<genexpr>None)callabler2   joinrC   
isinstancer
   r   r   )r*   valuer   r   r   format_value_for_display   s
    zPanel.format_value_for_displayc                       s   e Zd ZdZdd Zedd Zdd Zedd	 Zed
d Z	dd Z
dd Zdd Zdd Zd fdd	Zdd Zdd Zdd Zdd Z  ZS ) zPanel.BoundPanelzu
        A template component for a panel that has been associated with a model instance, form, and request.
        c                 C   s6   || _ || _|| _|| _|| _| j j| _| j j| _d S r    )r7   r8   r9   r:   r;   r!   r#   )r*   r7   r8   r9   r:   r;   r   r   r   r+      s    
zPanel.BoundPanel.__init__c                 C   s   | j jS r    )r7   r"   r.   r   r   r   r"      s    zPanel.BoundPanel.classnamec                 C   s
   | j  S r    )r7   r@   r.   r   r   r   r@      s    zPanel.BoundPanel.classesc                 C   s   | j jS r    )r7   r(   r.   r   r   r   r(     s    zPanel.BoundPanel.attrsc                 C   s   | j jS r    )r7   r%   r.   r   r   r   r%     s    zPanel.BoundPanel.iconc                 C   s
   | j  S )zk
            Returns an HTML ID to be used as the target for any label referencing this panel.
            )r7   rA   r.   r   r   r   rA   	  s    zPanel.BoundPanel.id_for_labelc                 C   s   dS )zp
            Whether this panel should be rendered; if false, it is skipped in the template output.
            Tr   r.   r   r   r   is_shown  s    zPanel.BoundPanel.is_shownc                 C   s   |   S )zo
            Whether this panel shows the panel furniture instead of being rendered outside of it.
            )rO   r.   r   r   r   show_panel_furniture  s    z%Panel.BoundPanel.show_panel_furniturec                 C   s   dS )NFr   r.   r   r   r   is_required  s    zPanel.BoundPanel.is_requiredNc                    s"   t  |}| |d< | j|d< |S )Nr*   r(   )superget_context_datar(   )r*   Zparent_contextcontextr,   r   r   rS     s    
z!Panel.BoundPanel.get_context_datac                 C   s   g S r    r   r.   r   r   r   get_comparison$  s    zPanel.BoundPanel.get_comparisonc                    s8   j  dg   fddjjD }td|S )a  
            Helper function: render all of the fields that are defined on the form but not "claimed" by
            any panels via required_fields. These fields are most likely to be hidden fields introduced
            by the forms framework itself, such as ORDER / DELETE fields on formset members.
            (If they aren't actually hidden fields, then they will appear as ugly unstyled / label-less fields
            outside of the panel furniture. But there's not much we can do about that.)
            r   c                    s"   g | ]}| vrt j| qS r   )rD   r:   )rE   
field_nameZrendered_fieldsr*   r   r   
<listcomp>0  s   z:Panel.BoundPanel.render_missing_fields.<locals>.<listcomp>r   )r7   r1   getr:   r   r   rK   )r*   Zmissing_fields_htmlr   rX   r   render_missing_fields'  s
    z&Panel.BoundPanel.render_missing_fieldsc                 C   s   t |  |   S )z
            Render this as an 'object', ensuring that all fields necessary for a valid form
            submission are included
            )r   Zrender_htmlr[   r.   r   r   r   render_form_content8  s    z$Panel.BoundPanel.render_form_contentc                 C   s$   d | jj| jj| j| j| jjjS )Nz1<{} with model={} instance={} request={} form={}>)r>   r,   r   r7   r   r8   r9   r:   r.   r   r   r   r?   ?  s    zPanel.BoundPanel.__repr__)N)r   
__module____qualname____doc__r+   propertyr"   r@   r(   r%   rA   rO   rP   rQ   rS   rV   r[   r\   r?   __classcell__r   r   rU   r   r<      s$   


r<   )r   r   r   Nr   N)NNNr7   )r   r]   r^   r_   r&   r+   r/   r-   r1   r3   r6   r=   r4   r?   r@   rA   r`   rB   rN   r   r<   r   r   r   r   r   3   s.         
		


r   N)Zdjango.core.exceptionsr   Zdjango.utils.safestringr   Zwagtail.admin.forms.modelsr   r   Zwagtail.admin.ui.componentsr   Zwagtail.blocksr   Zwagtail.coreutilsr   Zwagtail.modelsr	   Zwagtail.rich_textr
   Zwagtail.utils.textr   r   r   r   r   r   r   <module>   s   
#