a
    Dgh                     @   sx   d dl mZ d dlmZ ddlmZ G dd deZG dd deZG d	d
 d
eZG dd deZ	G dd deZ
dS )    )Media)cached_property   )Panelc                       s\   e Zd ZdZd fdd	Z fddZdd Zd	d
 Zedd Z	G dd de
jZ  ZS )
PanelGroupz~
    Abstract class for panels that manage a set of sub-panels.
    Concrete subclasses must attach a 'children' property
     c                    s.   | dd }t j|i | || _|| _d S )N
permission)popsuper__init__childrenr   )selfr   argskwargsr   	__class__r   Y/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/admin/panels/group.pyr      s    zPanelGroup.__init__c                    s"   t   }| j|d< | j|d< |S )Nr   r   )r
   clone_kwargsr   r   )r   r   r   r   r   r      s    


zPanelGroup.clone_kwargsc                 C   s6  | j d u rtd| jj i }| jD ]
}| }| D ]\}}||vrt|tsht|t	sht|t
rv| ||< n|||< q:|| }t|trt|ttfr|| q:t|trt|ttfrt||||< q:t|t	rt|t	r|| q:t|t
rt|t
r|| q:td|||f q:q$|S )NzU%s is not bound to a model yet. Use `.bind_to_model(model)` before using this method.z;Don't know how to merge values %r and %r for form option %r)modelAttributeErrorr   __name__r   get_form_optionsitems
isinstancelistdictsetcopytupleextendupdate
ValueError)r   optionschildZchild_optionskeynew_valZcurrent_valr   r   r   r      sL    

zPanelGroup.get_form_optionsc                    s2   ddl m} | j j} fdd|D  _d S )Nr   )expand_panel_listc                    s   g | ]}|  jqS r   )Zbind_to_modelr   .0r#   r   r   r   
<listcomp>M       z-PanelGroup.on_model_bound.<locals>.<listcomp>)Zmodel_utilsr&   r   r   )r   r&   Zchild_panelsr   r)   r   on_model_boundI   s    zPanelGroup.on_model_boundc                 C   s^   t  }g }| jD ]H}|jpd}|}d}||v rD|d7 }d||f }q&|| || q|S )z
        A list of identifiers corresponding to child panels in ``self.children``, formed from the clean_name property
        but validated to be unique and non-empty.
        panelr   r   z%s%d)r   r   Z
clean_nameappendadd)r   Z
used_namesresultr-   	base_nameZcandidate_namesuffixr   r   r   child_identifiersO   s    


zPanelGroup.child_identifiersc                   @   sT   e Zd Zedd Zedd Zedd Zdd Zd	d
 Ze	dd Z
dd ZdS )zPanelGroup.BoundPanelc                    s     fddt  jj jjD S )Nc              	      s4   g | ],\}}|j  j j j j d | dqS )z-child-)instancerequestformprefix)Zget_bound_panelr4   r5   r6   r7   r(   r#   
identifierr)   r   r   r*   g   s   z2PanelGroup.BoundPanel.children.<locals>.<listcomp>)zipr-   r   r3   r)   r   r)   r   r   e   s
    
zPanelGroup.BoundPanel.childrenc                 C   s   dd | j D S )Nc                 S   s   g | ]}|  r|qS r   is_shownr'   r   r   r   r*   u   r+   z:PanelGroup.BoundPanel.visible_children.<locals>.<listcomp>)r   r)   r   r   r   visible_childrens   s    z&PanelGroup.BoundPanel.visible_childrenc                 C   s   dd t | j| jjD S )Nc                 S   s    g | ]\}}|  r||fqS r   r;   r8   r   r   r   r*   y   s   zKPanelGroup.BoundPanel.visible_children_with_identifiers.<locals>.<listcomp>)r:   r   r-   r3   r)   r   r   r   !visible_children_with_identifiersw   s
    
z7PanelGroup.BoundPanel.visible_children_with_identifiersc                 C   s   t dd | jD S )Nc                 s   s   | ]}|  V  qd S N)show_panel_furniturer'   r   r   r   	<genexpr>   r+   z=PanelGroup.BoundPanel.show_panel_furniture.<locals>.<genexpr>)anyr   r)   r   r   r   r@      s    z*PanelGroup.BoundPanel.show_panel_furniturec                 C   s2   | j jr| jj| j jsdS tdd | jD S )zx
            Check permissions on the panel group overall then check if any children
            are shown.
            Fc                 s   s   | ]}|  V  qd S r?   r;   r'   r   r   r   rA      r+   z1PanelGroup.BoundPanel.is_shown.<locals>.<genexpr>)r-   r   r5   userZhas_permrB   r   r)   r   r   r   r<      s    zPanelGroup.BoundPanel.is_shownc                 C   s    t  }| jD ]}||j7 }q|S r?   )r   r=   media)r   rD   itemr   r   r   rD      s    
zPanelGroup.BoundPanel.mediac                 C   s"   g }| j D ]}||  q
|S r?   )r   r   get_comparison)r   comparatorsr#   r   r   r   rF      s    
z$PanelGroup.BoundPanel.get_comparisonN)r   
__module____qualname__r   r   r=   r>   r@   r<   propertyrD   rF   r   r   r   r   
BoundPaneld   s   


	
rK   )r   )r   rH   rI   __doc__r   r   r   r,   r   r3   r   rK   __classcell__r   r   r   r   r      s   0
r   c                   @   s   e Zd ZG dd dejZdS )TabbedInterfacec                   @   s   e Zd ZdZdS )zTabbedInterface.BoundPanelz)wagtailadmin/panels/tabbed_interface.htmlNr   rH   rI   Ztemplate_namer   r   r   r   rK      s   rK   Nr   rH   rI   r   rK   r   r   r   r   rN      s   rN   c                   @   s   e Zd ZG dd dejZdS )
ObjectListc                   @   s   e Zd ZdZdS )zObjectList.BoundPanelz$wagtailadmin/panels/object_list.htmlNrO   r   r   r   r   rK      s   rK   NrP   r   r   r   r   rQ      s   rQ   c                   @   s   e Zd ZG dd dejZdS )FieldRowPanelc                   @   s   e Zd ZdZdS )zFieldRowPanel.BoundPanelz(wagtailadmin/panels/field_row_panel.htmlNrO   r   r   r   r   rK      s   rK   NrP   r   r   r   r   rR      s   rR   c                   @   s   e Zd ZG dd dejZdS )MultiFieldPanelc                   @   s   e Zd ZdZdS )zMultiFieldPanel.BoundPanelz*wagtailadmin/panels/multi_field_panel.htmlNrO   r   r   r   r   rK      s   rK   NrP   r   r   r   r   rS      s   rS   N)Zdjango.formsr   Zdjango.utils.functionalr   baser   r   rN   rQ   rR   rS   r   r   r   r   <module>   s    