o
    hh                     @   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   Z/var/www/html/ndineBlogger/venv/lib/python3.10/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   s.  | j d u rtd| jj i }| jD ]}| }| D ]w\}}||vr?t|ts3t|t	s3t|t
r:| ||< q|||< q|| }t|trUt|ttfrU|| qt|trkt|ttfrkt||||< qt|t	r{t|t	r{|| qt|t
rt|t
r|| qtd|||f 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childchild_optionskeynew_valcurrent_valr   r   r   r      sN   


!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   )bind_to_modelr   .0r#   r   r   r   
<listcomp>M       z-PanelGroup.on_model_bound.<locals>.<listcomp>)model_utilsr(   r   r   )r   r(   child_panelsr   r,   r   on_model_boundI   s   zPanelGroup.on_model_boundc                 C   sd   t  }g }| jD ]'}|jpd}|}d}||v r%|d7 }d||f }||v s|| || 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   
clean_nameappendadd)r   
used_namesresultr2   	base_name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)get_bound_panelr<   r=   r>   r?   r+   r#   
identifierr,   r   r   r-   g   s    z2PanelGroup.BoundPanel.children.<locals>.<listcomp>)zipr2   r   r;   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   rD   rA   r   r   r   r-   y   s    zKPanelGroup.BoundPanel.visible_children_with_identifiers.<locals>.<listcomp>)rC   r   r2   r;   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       | ]}|  V  qd S N)show_panel_furniturer*   r   r   r   	<genexpr>       z=PanelGroup.BoundPanel.show_panel_furniture.<locals>.<genexpr>)anyr   r,   r   r   r   rJ      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   rH   rI   rD   r*   r   r   r   rK      rL   z1PanelGroup.BoundPanel.is_shown.<locals>.<genexpr>)r2   r   r=   userhas_permrM   r   r,   r   r   r   rE      s   zPanelGroup.BoundPanel.is_shownc                 C   s    t  }| jD ]}||j7 }q|S rI   )r   rF   media)r   rP   itemr   r   r   rP      s   
zPanelGroup.BoundPanel.mediac                 C   s"   g }| j D ]	}||  q|S rI   )r   r   get_comparison)r   comparatorsr#   r   r   r   rR      s   
z$PanelGroup.BoundPanel.get_comparisonN)r   
__module____qualname__r   r   rF   rG   rJ   rE   propertyrP   rR   r   r   r   r   
BoundPaneld   s    


	
rW   )r   )r   rT   rU   __doc__r   r   r   r1   r   r;   r   rW   __classcell__r   r   r   r   r      s    0
r   c                   @      e Zd ZG dd dejZdS )TabbedInterfacec                   @      e Zd ZdZdS )zTabbedInterface.BoundPanelz)wagtailadmin/panels/tabbed_interface.htmlNr   rT   rU   template_namer   r   r   r   rW          rW   Nr   rT   rU   r   rW   r   r   r   r   r[          r[   c                   @   rZ   )
ObjectListc                   @   r\   )zObjectList.BoundPanelz$wagtailadmin/panels/object_list.htmlNr]   r   r   r   r   rW      r_   rW   Nr`   r   r   r   r   rb      ra   rb   c                   @   rZ   )FieldRowPanelc                   @   r\   )zFieldRowPanel.BoundPanelz(wagtailadmin/panels/field_row_panel.htmlNr]   r   r   r   r   rW      r_   rW   Nr`   r   r   r   r   rc      ra   rc   c                   @   rZ   )MultiFieldPanelc                   @   r\   )zMultiFieldPanel.BoundPanelz*wagtailadmin/panels/multi_field_panel.htmlNr]   r   r   r   r   rW      r_   rW   Nr`   r   r   r   r   rd      ra   rd   N)django.formsr   django.utils.functionalr   baser   r   r[   rb   rc   rd   r   r   r   r   <module>   s     