U
    {h                     @   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|| || _|| _d S )N
permission)popsuper__init__childrenr   )selfr   argskwargsr   	__class__r   b/var/www/dating/data/www/fatepal.com/env/lib/python3.8/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 krtd| jj i }| jD ]
}| }| D ]\}}||k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childchild_optionskeynew_valZcurrent_valr   r   r   r      sP    

  zPanelGroup.get_form_optionsc                    s    fdd j D  _ d S )Nc                    s   g | ]}|  jqS r   )Zbind_to_modelr   .0r#   r   r   r   
<listcomp>J   s     z-PanelGroup.on_model_bound.<locals>.<listcomp>r   r)   r   r)   r   on_model_boundI   s    zPanelGroup.on_model_boundc                 C   s^   t  }g }| jD ]H}|jpd}|}d}||k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_identifiersL   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*   d   s   z2PanelGroup.BoundPanel.children.<locals>.<listcomp>)zipr-   r   r3   r)   r   r)   r   r   b   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*   r   s      z:PanelGroup.BoundPanel.visible_children.<locals>.<listcomp>r+   r)   r   r   r   visible_childrenp   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*   v   s   zKPanelGroup.BoundPanel.visible_children_with_identifiers.<locals>.<listcomp>)r:   r   r-   r3   r)   r   r   r   !visible_children_with_identifierst   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>   s     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      s     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   Z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   
BoundPanela   s   


	
rJ   )r   )r   rG   rH   __doc__r   r   r   r,   r   r3   r   rJ   __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   rG   rH   Ztemplate_namer   r   r   r   rJ      s   rJ   Nr   rG   rH   r   rJ   r   r   r   r   rM      s   rM   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.htmlNrN   r   r   r   r   rJ      s   rJ   NrO   r   r   r   r   rP      s   rP   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.htmlNrN   r   r   r   r   rJ      s   rJ   NrO   r   r   r   r   rQ      s   rQ   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.htmlNrN   r   r   r   r   rJ      s   rJ   NrO   r   r   r   r   rR      s   rR   N)Zdjango.formsr   Zdjango.utils.functionalr   baser   r   rM   rP   rQ   rR   r   r   r   r   <module>   s    