o
    h                     @   sD   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dS )	    )format_lazy)gettext_lazy)Page   )
FieldPanelc                       sL   e Zd ZdZddddgd fdd
Z fd	d
ZG dd dejZ  ZS )TitleFieldPanela  
    Prepares the default widget attributes that are used on Page title fields.
    Can be used outside of pages to easily enable the slug field sync functionality.

    :param apply_if_live: (optional) If ``True``, the built in slug sync behaviour will apply irrespective of the published state.
        The default is ``False``, where the slug sync will only apply when the instance is not live (or does not have a live property).
    :param classname: (optional) A CSS class name to add to the panel's HTML element. Default is ``"title"``.
    :param placeholder: (optional) If a value is provided, it will be used as the field's placeholder, if ``False`` is provided no placeholder will be shown.
        If ``True``, a placeholder value of ``"Title*"`` will be used or ``"Page Title*"`` if the model is a ``Page`` model.
        The default is ``True``. If a widget is provided with a placeholder, the widget's value will be used instead.
    :param targets: (optional) This allows you to override the default target of the field named `slug` on the form.
        Accepts a list of field names, default is ``["slug"]``.
        Note that the slugify/urlify behaviour relies on usage of the ``wagtail.admin.widgets.slug`` widget on the slug field.
    FtitleTslug)apply_if_live	classnameplaceholdertargetsc                   s0   ||d< || _ || _|| _t j|i | d S )Nr   )r
   r   r   super__init__)selfr
   r   r   r   argskwargs	__class__ f/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/admin/panels/title_field_panel.pyr      s
   	zTitleFieldPanel.__init__c                    s    i t   | j| j| jdS )N)r
   r   r   )r   clone_kwargsr
   r   r   r   r   r   r   r   (   s   zTitleFieldPanel.clone_kwargsc                       sF   e Zd Zg dZd fdd	Zdd Zdd Zd	d
 Zdd Z  Z	S )zTitleFieldPanel.BoundPanel)zfocus->w-sync#checkzblur->w-sync#applyzchange->w-sync#applyzkeyup->w-sync#applyNc                    s6   | j j}|r| js|jjjdi |   t |S )Nr   )	bound_fieldfield	read_onlywidgetattrsupdate	get_attrsr   get_context_data)r   parent_contextr   r   r   r   r    8   s   
z+TitleFieldPanel.BoundPanel.get_context_datac                    s    j } jjj}i }|jdddg}dtd||d<   r6|jddg j	 }dtd||d<  fdd|j
D }dtd||d	<   }|rYd
|jvrY||d
< |S )zy
            Generates a dict of widget attributes to be updated on the widget
            before rendering.
            zdata-controllerNzw-sync zdata-actionc                    s"   g | ]}| j jv r |qS r   )formfieldsget_target_selector).0targetr   r   r   
<listcomp>P   s
    z8TitleFieldPanel.BoundPanel.get_attrs.<locals>.<listcomp>z, zdata-w-sync-target-valuer   )panelr   r   r   r   getjoinfilterget_should_applyapply_actionsr   get_placeholder)r   r)   r   r   controllersactionsr   r   r   r   r   r   >   s    

z$TitleFieldPanel.BoundPanel.get_attrsc                 C   sF   | j j}|sdS |du r!td}t| j jtrtd}td|dS |S )z
            If placeholder is falsey, return None. Otherwise allow a valid placeholder
            to be resolved.
            NTTitlez
Page titlez{title}*)r   )r)   r   r   
issubclassmodelr   r   )r   r   r   r   r   r   r/   ]   s   z*TitleFieldPanel.BoundPanel.get_placeholderc                 C   s2   | j jrdS | j}|sdS |jot|dd}| S )zb
            Check that the title field should apply the sync with the target fields.
            TliveF)r)   r
   instancepkgetattr)r   r6   is_liver   r   r   r-   q   s   z+TitleFieldPanel.BoundPanel.get_should_applyc                 C   s   | j | }d|j S )zL
            Prepare a selector for an individual target field.
            #)r#   id_for_label)r   r'   r   r   r   r   r%      s   
z.TitleFieldPanel.BoundPanel.get_target_selector)N)
__name__
__module____qualname__r.   r    r   r/   r-   r%   __classcell__r   r   r   r   
BoundPanel0   s    r@   )	r<   r=   r>   __doc__r   r   r   r@   r?   r   r   r   r   r   	   s    r   N)	django.utils.textr   django.utils.translationr   wagtail.modelsr   field_panelr   r   r   r   r   r   <module>   s
    