a
    Dg                     @   s   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 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G dd deZG dd deZdS )    )warn)flatatt)reverse)cached_property)	urlencode)hooks)	Component)accepts_kwarg)RemovedInWagtail70Warningc                   @   s   e Zd ZdZdZdZdZdZi Zddddi df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d Zdd ZdS )Buttonzwagtailadmin/shared/button.htmlT Ni  c                 C   sl   |r
|| _ |r|| _|| _|r$|| _| j | _| j| d| jv rbd| jvrb| jd| jd< || _d S )Ntitle
aria-label)	labelurl	classname	icon_nameattrscopyupdatepoppriority)selfr   r   r   r   r   r    r   [/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/admin/widgets/button.py__init__   s    zButton.__init__c                 C   s   d| iS )Nbuttonr   r   Zparent_contextr   r   r   get_context_data.   s    zButton.get_context_datac                 C   s
   t | jS N)r   r   r   r   r   r   base_attrs_string1   s    zButton.base_attrs_stringc                 C   s   | j ddS )Nr   r   )r   getr    r   r   r   
aria_label9   s    zButton.aria_labelc                 C   s   d| j  dS )Nz	<Button: >)r   r    r   r   r   __repr__=   s    zButton.__repr__c                 C   s&   t |tstS | j| jf|j|jfk S r   
isinstancer   NotImplementedr   r   r   otherr   r   r   __lt__@   s    
zButton.__lt__c                 C   s&   t |tstS | j| jf|j|jfkS r   r&   r)   r   r   r   __le__E   s    
zButton.__le__c                 C   s&   t |tstS | j| jf|j|jfkS r   r&   r)   r   r   r   __gt__J   s    
zButton.__gt__c                 C   s&   t |tstS | j| jf|j|jfkS r   r&   r)   r   r   r   __ge__O   s    
zButton.__ge__c                 C   sJ   t |tstS | j|jkoH| j|jkoH| j|jkoH| j|jkoH| j|jkS r   )r'   r   r(   r   r   r   r   r   r)   r   r   r   __eq__T   s    




zButton.__eq__)__name__
__module____qualname__template_nameshowr   r   r   r   r   r   propertyr!   r#   r%   r+   r,   r-   r.   r/   r   r   r   r   r      s&   


r   c                       s.   e Zd ZdZddddi df fdd	Z  ZS )HeaderButtonzHAn icon-only button to be displayed after the breadcrumbs in the header.r   NFc           	         sn   | d  }| }|rL|dd d  }||d< ||d< ||d< d}t jf |||||d| d S )Nz w-header-button buttonzdata-controllerr   z
 w-tooltipzdata-w-tooltip-content-valuer   )r   r   r   r   r   )stripr   r"   superr   )	r   r   r   r   r   r   Z	icon_onlykwargs
controller	__class__r   r   r   c   s"    
zHeaderButton.__init__)r0   r1   r2   __doc__r   __classcell__r   r   r;   r   r6   `   s   r6   c                       s   e Zd Zd fdd	Z  ZS )ListingButtonr   Nc                    s,   | d  }t jf |||d| d S )Nz% button button-small button-secondary)r   r   r   )r7   r8   r   )r   r   r   r   r9   r;   r   r   r      s    zListingButton.__init__)r   Nr   r0   r1   r2   r   r>   r   r   r;   r   r?      s   r?   c                       sH   e Zd ZdZdZddi dd fdd
Zedd Zedd Z  Z	S )	PageListingButtonN)pagenext_urlr   userc                   sd   || _ || _|| _| }| j rJ| jd urJd|vrJ| jd| j  i |d< t j|d|i| d S )Nr   r   r   )rB   rD   rC   r   aria_label_formatZget_admin_display_titler8   r   )r   rB   rC   r   rD   argsr9   r;   r   r   r      s    

zPageListingButton.__init__c                 C   sH   | j rD| jd urDt| j| j jgd}| jr@|dtd| ji 7 }|S d S )N)rF   ?next)rB   url_namer   idrC   r   )r   r   r   r   r   r      s
    zPageListingButton.urlc                 C   s   | j r| j | jS d S r   )rB   permissions_for_userrD   r    r   r   r   
page_perms   s    zPageListingButton.page_perms)
r0   r1   r2   rE   rI   r   r   r   rL   r>   r   r   r;   r   rA      s   
rA   c                       s4   e Zd ZdZ fddZedd Zdd Z  ZS )BaseDropdownMenuButtonz5wagtailadmin/pages/listing/_button_with_dropdown.htmlc                    s   t  j|dd i| d S )Nr   )r8   r   r   rF   r9   r;   r   r   r      s    zBaseDropdownMenuButton.__init__c                 C   s   t d S r   )NotImplementedErrorr    r   r   r   dropdown_buttons   s    z'BaseDropdownMenuButton.dropdown_buttonsc                 C   s   t | j| j| j| j| jdS )N)buttonsr   r   Ztoggle_classnamer   )sortedrP   r   r#   r   r   r   r   r   r   r      s    z'BaseDropdownMenuButton.get_context_data)	r0   r1   r2   r3   r   r   rP   r   r>   r   r   r;   r   rM      s
   
rM   c                       s   e Zd Z fddZ  ZS )ButtonWithDropdownc                    s$   | dg | _t j|i | d S )NrQ   )r   rP   r8   r   rN   r;   r   r   r      s    zButtonWithDropdown.__init__r@   r   r   r;   r   rS      s   rS   c                       s6   e Zd Zd fdd	Zedd Zedd Z  ZS )	ButtonWithDropdownFromHookNc                    sb   || _ || _|d u r>|d ur4tdtdd |j| _qDtdn|| _|| _t j|fi | d S )NzUButtonWithDropdownFromHook should be passed a `user` argument instead of `page_perms`   )category
stacklevelz5ButtonWithDropdownFromHook requires a `user` argument)		hook_namerB   r   r
   rD   	TypeErrorrC   r8   r   )r   r   rX   rB   rD   rL   rC   r9   r;   r   r   r      s    


z#ButtonWithDropdownFromHook.__init__c                 C   s
   t | jS r   )boolrP   r    r   r   r   r4      s    zButtonWithDropdownFromHook.showc              	   C   s   t | j}g }|D ]t}t|dr>||| j| j| jd qtd| j d|j	 d|j
 dtd | j| j}||| j|| j qdd	 |D }|S )
NrD   )rB   rD   rC   `zK` hook functions should accept a `user` argument instead of `page_perms` - .z needs to be updated)rV   c                 S   s   g | ]}|j r|qS r   )r4   ).0br   r   r   
<listcomp>       z?ButtonWithDropdownFromHook.dropdown_buttons.<locals>.<listcomp>)r   Z	get_hooksrX   r	   extendrB   rD   rC   r   r1   r0   r
   rK   )r   Zbutton_hooksrQ   hookrL   r   r   r   rP      s&    

z+ButtonWithDropdownFromHook.dropdown_buttons)NNN)	r0   r1   r2   r   r5   r4   r   rP   r>   r   r   r;   r   rT      s      
rT   N)warningsr   Zdjango.forms.utilsr   Zdjango.urlsr   Zdjango.utils.functionalr   Zdjango.utils.httpr   Zwagtailr   Zwagtail.admin.ui.componentsr   Zwagtail.coreutilsr	   Zwagtail.utils.deprecationr
   r   r6   r?   rA   rM   rS   rT   r   r   r   r   <module>   s   R""