o
    h̰                     @   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	m
Z
 d dlmZ d dlmZ d dlmZmZmZ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!m"Z" d dl#m$Z$ d dl%m&Z&m'Z' d dl(m)Z)m*Z*m+Z+m,Z, d dl-m.Z. d dl/m0Z0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7m8Z8 d dl9m:Z: d dl;m<Z<m=Z= d dl>m?Z?m@Z@ d dlAmBZBmCZCmDZDmEZEmFZF d dlGmHZH d dlImJZJ d dlKmLZLmMZM d dlNmOZO d dlPmQZQ d d lRmSZS d!d" ZTG d#d$ d$e.jUZVG d%d& d&e.jWe.jXZXG d'd( d(e.jYe.jZZZG d)d* d*e.j[eZZ\G d+d, d,e.jYe.j]Z]G d-d. d.e.j^Z^G d/d0 d0e.j_Z_G d1d2 d2e0j`Z`G d3d4 d4e.jaZaG d5d6 d6e6ZbG d7d8 d8e7ZcG d9d: d:e4e8ZdG d;d< d<e4e.jeZeG d=d> d>e4e.jfZfG d?d@ d@e4e.jgZgG dAdB dBe4e1jhZhG dCdD dDe4e1jiZiG dEdF dFe2jjZkG dGdH dHe2jlZmG dIdJ dJe2jnZoG dKdL dLe2jpZqG dMdN dNe4e0jrZrG dOdP dPe4e0jsZsG dQdR dRe<ZtG dSdT dTe=ZudUS )V    )warn)apps)quote)checks)ImproperlyConfiguredPermissionDenied)Http404)redirect)pathre_pathreversereverse_lazy)cached_property)capfirst)gettext)gettext_lazy)hooks)check_panels_in_model)
ObjectList*extract_panel_definitions_from_model_class)MediaContainer)ChecksSidePanelPreviewSidePanel)BulkActionsCheckboxColumnColumnLiveStatusTagColumnTitleColumn)generic)historylockworkflow)PermissionCheckedMixin)PreviewOnCreatePreviewOnEditPreviewRevision)viewsets)ModelViewSetModelViewSetGroup)BaseDropdownMenuButtonButtonWithDropdown)DraftStateMixinLockableMixinPreviewableMixinRevisionMixinWorkflowMixin)ModelPermissionPolicy)SnippetActionMenu)SnippetAdminURLFinderget_snippet_models)SnippetStatusSidePanel)SnippetChooserViewSet)RemovedInWagtail70Warningc                 C   s6   zt | |}W n	 ty   tw |t vrt|S )z|
    Retrieve a model from an app_label / model_name combo.
    Raise Http404 if the model is not a valid snippet type.
    )r   	get_modelLookupErrorr   r2   )app_name
model_namemodel r;   _/var/www/html/ndineBlogger/venv/lib/python3.10/site-packages/wagtail/snippets/views/snippets.py!get_snippet_model_from_url_params8   s   
r=   c                       st   e Zd ZedZdZdZdZ fddZdd Z	 fd	d
Z
dd Zdd Zedd Z fddZdd Z  ZS )ModelIndexViewSnippetssnippetwagtailsnippets:indexnamec                    s(   t  j|g|R i | |  | _d S N)supersetup_get_snippet_typessnippet_typesselfrequestargskwargs	__class__r;   r<   rE   Q   s   zModelIndexView.setupc                    s    fddt  D S )Nc                    s:   g | ]}  | rt|jj|j  |d qS ))rB   countr:   url)get_list_urlr   _metaverbose_name_plural_default_managerallrO   ).0r:   rI   rP   r;   r<   
<listcomp>V   s    
z5ModelIndexView._get_snippet_types.<locals>.<listcomp>)r2   rI   r;   rW   r<   rF   U   s   z!ModelIndexView._get_snippet_typesc                    s$   | j stt j|g|R i |S rC   )rG   r   rD   dispatchrH   rM   r;   r<   rZ   a   s   zModelIndexView.dispatchc                 C   s,   |j j| jjh drt|j dS d S )N>   addviewchangedeletelist)snippet_viewsetpermission_policyuser_has_any_permissionrJ   userr   get_url_name)rI   r:   r;   r;   r<   rQ   f   s   zModelIndexView.get_list_urlc                 C   s   d S rC   r;   rY   r;   r;   r<   get_querysetm   s   zModelIndexView.get_querysetc                 C   s*   t dtddd ddtdtdddgS )	NrB   Namec                 S      | d S )NrP   r;   typer;   r;   r<   <lambda>v       z(ModelIndexView.columns.<locals>.<lambda>)labelget_urlsort_keyrO   	Instances)rl   rn   )r   _r   rY   r;   r;   r<   columnsp   s   zModelIndexView.columnsc                    sP   | j d dk}| j dv rt| jdd |d}n
t| jdd |d}t j|dS )	Nr   -)rO   z-countc                 S   rg   )NrO   r;   rh   r;   r;   r<   rj      rk   z1ModelIndexView.get_context_data.<locals>.<lambda>)keyr   c                 S   s   | d   S )NrB   )lowerrh   r;   r;   r<   rj      s    )object_list)orderingsortedrG   rD   get_context_data)rI   rL   r   rG   rM   r;   r<   rx      s   
zModelIndexView.get_context_datac                 C   s
   d| j gS )Nz)wagtailsnippets/snippets/model_index.htmltemplate_namerY   r;   r;   r<   get_template_names   s   z!ModelIndexView.get_template_names)__name__
__module____qualname__r   
page_titleheader_iconindex_url_namedefault_orderingrE   rF   rZ   rQ   re   r   rq   rx   r{   __classcell__r;   r;   rM   r<   r>   K   s    
r>   c                       sD   e Zd ZdZ fddZe fddZ fddZdd	 Z  Z	S )
	IndexViewr_   c                    s"   t | jr| | j| _t  S rC   )callablequerysetrJ   rD   get_base_querysetrY   rM   r;   r<   r      s   

zIndexView.get_base_querysetc                    s   t dddgt jS )Nbulk_actionsr@   )obj_type)r   rD   rq   rY   rM   r;   r<   rq      s   
zIndexView.columnsc                    s   t  j|i |ddd iS )Nget_title_idc                 S   s   dt | j dS )Nsnippet__title)r   pk)instancer;   r;   r<   rj      s    z-IndexView._get_title_column.<locals>.<lambda>)rD   _get_title_column)rI   rK   rL   rM   r;   r<   r      s   zIndexView._get_title_columnc              
   C   s   |  |}| jj}g }tdD ]}||| jj|}|D ]}t|tr)|| q|| qqtdD ]%}z
|||| jj W q5 t	yZ   t
dtdd |||| jji  Y q5w |rq|t|ddtdd	t|i id
 |S )N register_snippet_listing_buttons!construct_snippet_listing_buttonszKconstruct_snippet_listing_buttons hook no longer accepts a context argument   )
stacklevelzdots-horizontalz
aria-labelzMore options for '%(title)s'title)buttons	icon_nameattrs)get_list_more_buttonsrJ   r
   r   	get_hooksrc   
isinstancer(   append	TypeErrorr   r5   r)   rp   str)rI   r   more_buttonsnext_urllist_buttonshookhook_buttonsbuttonr;   r;   r<   get_list_buttons   sB   


zIndexView.get_list_buttons)
r|   r}   r~   	view_namer   r   rq   r   r   r   r;   r;   rM   r<   r      s    r   c                       D   e Zd ZdZdZdd Zdd Zdd Zd	d
 Z fddZ	  Z
S )
CreateViewcreatez$wagtailsnippets/snippets/create.htmlc                 C      |  d| j| jS )Nbefore_create_snippet)run_hookrJ   r:   rY   r;   r;   r<   run_before_hook      zCreateView.run_before_hookc                 C   r   )Nafter_create_snippetr   rJ   objectrY   r;   r;   r<   run_after_hook   r   zCreateView.run_after_hookc                 C   s   t | j| j| jdS )N)r\   r:   )r0   rJ   r   r:   rY   r;   r;   r<   _get_action_menu      zCreateView._get_action_menuc                 C   sv   t | jj| jt| jdd| j| jdg}| jr7| jj r7|	t
| jj| j|  d |	t| jj| j t|S )Nshow_schedule_publishing_toggleF)r   localetranslationspreview_url)r3   formr   rJ   getattrr   r   preview_enabledis_previewabler   r   get_preview_urlr   r   rI   side_panelsr;   r;   r<   get_side_panels   s$   zCreateView.get_side_panelsc                    8   t  jdi |}|  }|d  |j7  < ||d< |S Nmediaaction_menur;   rD   rx   r   r   rI   rL   contextr   rM   r;   r<   rx     
   zCreateView.get_context_datar|   r}   r~   r   rz   r   r   r   r   rx   r   r;   r;   rM   r<   r      s    r   c                   @      e Zd ZdS )CopyViewNr|   r}   r~   r;   r;   r;   r<   r   
      r   c                       r   )EditVieweditz"wagtailsnippets/snippets/edit.htmlc                 C   r   )Nbefore_edit_snippetr   rY   r;   r;   r<   r     r   zEditView.run_before_hookc                 C   r   )Nafter_edit_snippetr   rY   r;   r;   r<   r     r   zEditView.run_after_hookc                 C   s   t | j| j| j| jdS )N)r\   r   locked_for_user)r0   rJ   r   r   r   rY   r;   r;   r<   r     s   zEditView._get_action_menuc                 C   s   t | j| jt| jdd| j| jr| j nd | j| j	| 
 |  |  d
g}| jrG| j rG|t| j| j|  d |t| j| j t|S )Nr   F)r   live_objectscheduled_objectr   r   	usage_urlhistory_urllast_updated_infor   )r3   r   rJ   r   r   r   draftstate_enabled get_scheduled_revision_as_objectr   r   get_usage_urlget_history_urlget_last_updated_infor   r   r   r   r   r   r   r   r;   r;   r<   r      s2   zEditView.get_side_panelsc                    r   r   r   r   rM   r;   r<   rx   <  r   zEditView.get_context_datar   r;   r;   rM   r<   r     s    r   c                   @   s    e Zd ZdZdd Zdd ZdS )
DeleteViewr^   c                 C      |  d| j| jgS )Nbefore_delete_snippetr   rY   r;   r;   r<   r   G  r   zDeleteView.run_before_hookc                 C   r   )Nafter_delete_snippetr   rY   r;   r;   r<   r   J  r   zDeleteView.run_after_hookN)r|   r}   r~   r   r   r   r;   r;   r;   r<   r   D  s    r   c                   @      e Zd ZdZdS )	UsageViewusageNr|   r}   r~   r   r;   r;   r;   r<   r   N      r   c                   @   r   )HistoryViewr   Nr   r;   r;   r;   r<   r   R  r   r   c                   @   r   )InspectViewinspectNr   r;   r;   r;   r<   r   V  r   r   c                   @   r   )PreviewOnCreateViewNr   r;   r;   r;   r<   r   Z  r   r   c                   @   r   )PreviewOnEditViewNr   r;   r;   r;   r<   r   ^  r   r   c                   @   r   )PreviewRevisionViewr]   Nr|   r}   r~   permission_requiredr;   r;   r;   r<   r   b  r   r   c                   @   r   )RevisionsCompareViewr]   Nr   r;   r;   r;   r<   r   f  r   r   c                   @   r   )UnpublishViewpublishNr   r;   r;   r;   r<   r   j  r   r   c                   @   r   )RevisionsUnscheduleViewr   Nr   r;   r;   r;   r<   r   n  r   r   c                           e Zd ZdZ fddZ  ZS )LockViewr   c                    sN   | j jjrdS || jkr!t| jtr!| jj}|r!|| j| j jS t	 
|S NT)rJ   rc   is_superuserr   r   r   r.   current_workflow_taskuser_can_lockrD   user_has_permissionrI   
permissionr   rM   r;   r<   r   u  s   

zLockView.user_has_permissionr|   r}   r~   r   r   r   r;   r;   rM   r<   r   r      r   c                       r   )
UnlockViewunlockc                    sd   | j jjrdS || jkr,| jj| j jjkrdS t| jtr,| jj	}|r,|
| j| j jS t |S r   )rJ   rc   r   r   r   locked_by_idr   r   r.   r   user_can_unlockrD   r   r   rM   r;   r<   r     s   


zUnlockView.user_has_permissionr   r;   r;   rM   r<   r     r   r   c                   @   r   )WorkflowActionViewNr   r;   r;   r;   r<   r    r   r  c                   @   r   )CollectWorkflowActionDataViewNr   r;   r;   r;   r<   r    r   r  c                   @   r   )ConfirmWorkflowCancellationViewNr   r;   r;   r;   r<   r    r   r  c                   @   r   )WorkflowPreviewViewNr   r;   r;   r;   r<   r    r   r  c                   @   r   )WorkflowHistoryViewr]   Nr   r;   r;   r;   r<   r    r   r  c                   @   r   )WorkflowHistoryDetailViewr]   Nr   r;   r;   r;   r<   r    s    r  c                       sd  e Zd ZdZdZdZdZdZdZdZ	e
ZeZeZeZeZeZeZeZeZeZeZe Z!e"Z#e$Z%e&Z'e(Z)e*Z+e,Z-e.Z/e0Z1e2Z3e4Z5e6Z7dZ8 fddZ9e:dd Z;e:d	d
 Z<e=dd Z>e=dd Z? fddZ@ fddZA fddZBdd ZC fddZDe=dd ZEe=dd ZFe=dd ZGe=dd  ZHe=d!d" ZIe=d#d$ ZJe=d%d& ZKe=d'd( ZLe=d)d* ZMe=d+d, ZNe=d-d. ZOe=d/d0 ZPe=d1d2 ZQe=d3d4 ZRe=d5d6 ZSe=d7d8 ZTe=d9d: ZUe=d;d< ZVe: fd=d>ZWe:d?d@ ZXdAdB ZYe:dCdD ZZdEdF Z[e:dGdH Z\dIdJ Z]e:dKdL Z^dMdN Z_e:dOdP Z`dQdR ZadSdT Zbe:dUdV ZcdWdX Zde:dYdZ Zed[d\ Zfe:d]d^ Zgd_d` Zhe:dadb Zidcdd Zje:dedf Zkdgdh Zle:didj Zmdkdl Zne:dmdn Zododp Zpe:dqdr Zqdsdt Zrdudv Zsdwdx Ztdydz Zud{d| Zve=d}d~ Zwdd Zxe:dd Zy fddZzdd Z{dd Z|dd Z} fddZ~  ZS )SnippetViewSeta  
    A viewset that instantiates the admin views for snippets.

    All attributes and methods from
    :class:`~wagtail.admin.viewsets.model.ModelViewSet` are available.

    For more information on how to use this class,
    see :ref:`wagtailsnippets_custom_admin_views`.
    N
   zwagtailsnippets/snippets/c                    s   t  jdi | | jd u rtd| jj| _| jj| _| jj| _t| jt	| _
t| jt| _t| jt| _t| jt| _t| jt| _t| dt| j| _d S )NzBSnippetViewSet must be passed a model or define a model attribute.menu_item_is_registeredr;   )rD   __init__r:   r   rR   
model_opts	app_labelr9   
issubclassr,   r   r-   revision_enabledr*   r   r.   workflow_enabledr+   locking_enabledr   bool	menu_hookr	  rI   rL   rM   r;   r<   r
  #  s    




zSnippetViewSet.__init__c                 C      |   S rC   )get_admin_base_pathrY   r;   r;   r<   
url_prefix9  s   zSnippetViewSet.url_prefixc                 C   r  rC   )get_admin_url_namespacerY   r;   r;   r<   url_namespace?  s   zSnippetViewSet.url_namespacec                 C   s   t dtj| jfddi}|S )as  
        The view class to use for reverting to a previous revision.

        By default, this class is generated by combining the edit view with
        ``wagtail.admin.views.generic.mixins.RevisionsRevertMixin``. As a result,
        this class must be a subclass of ``wagtail.snippets.views.snippets.EditView``
        and must handle the reversion correctly.
        _RevisionsRevertViewr   revisions_revert)ri   r   RevisionsRevertMixinedit_view_class)rI   revisions_revert_view_classr;   r;   r<   r  F  s   

z*SnippetViewSet.revisions_revert_view_classc                 C   s
   t | jS rC   )r/   r:   rY   r;   r;   r<   ra   W  s   
z SnippetViewSet.permission_policyc                    sd   t  jdi | d| d| d| d| d| d| d| d| d	| jd

|S )Nr_   list_resultsr   r   revisions_viewr  revisions_comparerevisions_unschedule	unpublish)
r   index_results_url_namelock_url_nameunlock_url_namerevisions_view_url_namerevisions_revert_url_namerevisions_compare_url_namerevisions_unschedule_url_nameunpublish_url_namebreadcrumbs_itemsr;   )rD   get_common_view_kwargsrd   r+  r  rM   r;   r<   r,  [  s"   
z%SnippetViewSet.get_common_view_kwargsc                    s   t  jdd| ji|S )Nr   r;   )rD   get_index_view_kwargsre   r  rM   r;   r<   r-  n  s
   
z$SnippetViewSet.get_index_view_kwargsc                    s   t  jdd| di|S )Npreview_url_namepreview_on_addr;   )rD   get_add_view_kwargsrd   r  rM   r;   r<   r0  t  s
   
z"SnippetViewSet.get_add_view_kwargsc                 K   s   | j di |S )Nr;   )r0  r  r;   r;   r<   get_copy_view_kwargsz     z#SnippetViewSet.get_copy_view_kwargsc                    s,   t  jd| d| d| dd|S )Npreview_on_editworkflow_historyconfirm_workflow_cancellation)r.  workflow_history_url_name&confirm_workflow_cancellation_url_namer;   )rD   get_edit_view_kwargsrd   r  rM   r;   r<   r8  }  s   z#SnippetViewSet.get_edit_view_kwargsc                 C      |  | jS rC   )construct_viewrevisions_view_classrY   r;   r;   r<   r       zSnippetViewSet.revisions_viewc                 C      | j | jfi |  S rC   )r:  r  r8  rY   r;   r;   r<   revisions_revert_view  s
   z$SnippetViewSet.revisions_revert_viewc                 C   s"   | j | j| j| jd| jjddS )Nr   fallback)edit_handlerrz   )r:  revisions_compare_view_class_edit_handlerget_templatesrz   rY   r;   r;   r<   revisions_compare_view  s   z%SnippetViewSet.revisions_compare_viewc                 C      | j | j| jd| jjddS )Nr!  r?  ry   )r:  revisions_unschedule_view_classrD  rz   rY   r;   r;   r<   revisions_unschedule_view  s   z(SnippetViewSet.revisions_unschedule_viewc                 C   rF  )Nr"  r?  ry   )r:  unpublish_view_classrD  rz   rY   r;   r;   r<   unpublish_view  s   zSnippetViewSet.unpublish_viewc                 C   s   | j | j|  dS )N
form_class)r:  preview_on_add_view_classget_form_classrY   r;   r;   r<   preview_on_add_view  s   z"SnippetViewSet.preview_on_add_viewc                 C   s   | j | j| jdddS )NT)
for_updaterK  )r:  preview_on_edit_view_classrN  rY   r;   r;   r<   preview_on_edit_view  s   
z#SnippetViewSet.preview_on_edit_viewc                 C      | j | j| ddS Nr   )success_url_name)r:  lock_view_classrd   rY   r;   r;   r<   	lock_view     zSnippetViewSet.lock_viewc                 C   r=  rC   )r:  copy_view_classr1  rY   r;   r;   r<   	copy_view  s   zSnippetViewSet.copy_viewc                 C   rS  rT  )r:  unlock_view_classrd   rY   r;   r;   r<   unlock_view  rX  zSnippetViewSet.unlock_viewc                 C      | j | j| d| ddS )Nr   workflow_actionredirect_url_namesubmit_url_name)r:  workflow_action_view_classrd   rY   r;   r;   r<   workflow_action_view  
   z#SnippetViewSet.workflow_action_viewc                 C   r]  )Nr   collect_workflow_action_datar_  )r:  'collect_workflow_action_data_view_classrd   rY   r;   r;   r<   !collect_workflow_action_data_view  rd  z0SnippetViewSet.collect_workflow_action_data_viewc                 C   r9  rC   )r:  (confirm_workflow_cancellation_view_classrY   r;   r;   r<   "confirm_workflow_cancellation_view  r<  z1SnippetViewSet.confirm_workflow_cancellation_viewc                 C   r9  rC   )r:  workflow_preview_view_classrY   r;   r;   r<   workflow_preview_view  r<  z$SnippetViewSet.workflow_preview_viewc                 C   &   | j | j| jd| jjd| ddS )Nzworkflow_history/indexr?  workflow_history_detail)rz    workflow_history_detail_url_name)r:  workflow_history_view_classrD  rz   rd   rY   r;   r;   r<   workflow_history_view  s   z$SnippetViewSet.workflow_history_viewc                 C   rl  )Nzworkflow_history/detailr?  r4  )rz   r6  )r:  "workflow_history_detail_view_classrD  rz   rd   rY   r;   r;   r<   workflow_history_detail_view  s   z+SnippetViewSet.workflow_history_detail_viewc                    s    fdd}|S )Nc                    s(   t d jj td t d|ddS )NzY%s's `/<pk>/usage/` usage view URL pattern has been deprecated in favour of /usage/<pk>/.)categoryr   T)	permanent)r   rN   r|   r5   r	   rd   )rJ   r   rY   r;   r<   redirect_to_usage  s   z@SnippetViewSet.redirect_to_usage_view.<locals>.redirect_to_usager;   )rI   ru  r;   rY   r<   redirect_to_usage_view   s   z%SnippetViewSet.redirect_to_usage_viewc                 C   s"   | j |  | j|  | j| jdS )N)r:   r  iconper_page)chooser_viewset_classget_chooser_admin_url_namespacer:   get_chooser_admin_base_pathrw  chooser_per_pagerY   r;   r;   r<   chooser_viewset  s   zSnippetViewSet.chooser_viewsetc                    s"   t  j }| jr|t  |S rC   )rD   list_displaycopyr   r   r   )rI   r~  rM   r;   r<   r~    s   zSnippetViewSet.list_displayc                 C   r  rC   )get_iconrY   r;   r;   r<   rw        zSnippetViewSet.iconc                 C      dS )z
        Returns the icon to be used for the admin views.

        **Deprecated** - the preferred way to customise this is to define an ``icon`` property.
        r@   r;   rY   r;   r;   r<   r  $     zSnippetViewSet.get_iconc                 C   r  rC   )get_menu_labelrY   r;   r;   r<   
menu_label,  r  zSnippetViewSet.menu_labelc                 C   s   t | jjS )z
        Returns the label text to be used for the menu item.

        **Deprecated** - the preferred way to customise this is to define a ``menu_label`` property.
        )r   r  rS   rY   r;   r;   r<   r  0  s   zSnippetViewSet.get_menu_labelc                 C   r  rC   )get_menu_namerY   r;   r;   r<   	menu_name8  r  zSnippetViewSet.menu_namec                 C   r  )z
        Returns the name to be used for the menu item.

        **Deprecated** - the preferred way to customise this is to define a ``menu_name`` property.
         r;   rY   r;   r;   r<   r  <  r  zSnippetViewSet.get_menu_namec                 C   r  rC   )get_menu_iconrY   r;   r;   r<   	menu_iconD  r  zSnippetViewSet.menu_iconc                 C      | j S )z
        Returns the icon to be used for the menu item.

        **Deprecated** - the preferred way to customise this is to define a ``menu_icon`` property.
        )rw  rY   r;   r;   r<   r  H  s   zSnippetViewSet.get_menu_iconc                 C   r  rC   )get_menu_orderrY   r;   r;   r<   
menu_orderP  r  zSnippetViewSet.menu_orderc                 C   r  )z
        Returns the ordering number to be applied to the menu item.

        **Deprecated** - the preferred way to customise this is to define a ``menu_order`` property.
        i'#  r;   rY   r;   r;   r<   r  T  s   zSnippetViewSet.get_menu_orderc                 C   r  rC   )r	  rY   r;   r;   r<   get_menu_item_is_registered]  s   z*SnippetViewSet.get_menu_item_is_registeredc                 C   s$   t dtddt dtddgS )Nwagtailadmin_homeHome)rP   rl   rA   r?   )r   rp   rY   r;   r;   r<   r+  `  s   z SnippetViewSet.breadcrumbs_itemsc                 C   r  )z
        Returns a QuerySet of all model instances to be shown on the index view.
        If ``None`` is returned (the default), the logic in
        ``index_view.get_base_queryset()`` will be used instead.
        Nr;   )rI   rJ   r;   r;   r<   re   i  r  zSnippetViewSet.get_querysetc                 C   r  rC   )get_index_templaterY   r;   r;   r<   index_template_nameq  r  z"SnippetViewSet.index_template_namec                 C   
   |  dS )ab  
        Returns a template to be used when rendering ``index_view``. If a
        template is specified by the ``index_template_name`` attribute, that will
        be used. Otherwise, a list of preferred template names are returned.

        **Deprecated** - the preferred way to customise this is to define an ``index_template_name`` property.
        indexrD  rY   r;   r;   r<   r  u     
z!SnippetViewSet.get_index_templatec                 C   r  rC   )get_index_results_templaterY   r;   r;   r<   index_results_template_name  r  z*SnippetViewSet.index_results_template_namec                 C   r  )az  
        Returns a template to be used when rendering ``index_results_view``. If a
        template is specified by the ``index_results_template_name`` attribute, that will
        be used. Otherwise, a list of preferred template names are returned.

        **Deprecated** - the preferred way to customise this is to define an ``index_results_template_name`` property.
        index_resultsr  rY   r;   r;   r<   r    r  z)SnippetViewSet.get_index_results_templatec                 C   r  rC   )get_create_templaterY   r;   r;   r<   create_template_name  r  z#SnippetViewSet.create_template_namec                 C   r  )aa  
        Returns a template to be used when rendering ``add_view``. If a
        template is specified by the ``create_template_name`` attribute, that will
        be used. Otherwise, a list of preferred template names are returned.

        **Deprecated** - the preferred way to customise this is to define a ``create_template_name`` property.
        r   r  rY   r;   r;   r<   r    r  z"SnippetViewSet.get_create_templatec                 C   r  rC   )get_edit_templaterY   r;   r;   r<   edit_template_name  r  z!SnippetViewSet.edit_template_namec                 C   r  )a_  
        Returns a template to be used when rendering ``edit_view``. If a
        template is specified by the ``edit_template_name`` attribute, that will
        be used. Otherwise, a list of preferred template names are returned.

        **Deprecated** - the preferred way to customise this is to define an ``edit_template_name`` property.
        r   r  rY   r;   r;   r<   r    r  z SnippetViewSet.get_edit_templatec                 C   r  rC   )get_delete_templaterY   r;   r;   r<   delete_template_name  r  z#SnippetViewSet.delete_template_namec                 C   r  )ad  
        Returns a template to be used when rendering ``delete_view``. If a
        template is specified by the ``delete_template_name`` attribute, that will
        be used. Otherwise, a list of preferred template names are returned.

        **Deprecated** - the preferred way to customise this is to define a ``delete_template_name`` property.
        r^   r  rY   r;   r;   r<   r    r  z"SnippetViewSet.get_delete_templatec                 C   r  )ah  
        A template to be used when rendering ``history_view``.

        Default: if :attr:`template_prefix` is specified, a ``history.html``
        template in the prefix directory and its ``{app_label}/{model_name}/``
        or ``{app_label}/`` subdirectories will be used. Otherwise, the
        ``history_view_class.template_name`` will be used.
        )get_history_templaterY   r;   r;   r<   history_template_name     
z$SnippetViewSet.history_template_namec                 C   r  )ag  
        Returns a template to be used when rendering ``history_view``. If a
        template is specified by the ``history_template_name`` attribute, that will
        be used. Otherwise, a list of preferred template names are returned.

        **Deprecated** - the preferred way to customise this is to define a ``history_template_name`` property.
        r   r  rY   r;   r;   r<   r    r  z#SnippetViewSet.get_history_templatec                 C   r  )ai  
        A template to be used when rendering ``inspect_view``.

        Default: if :attr:`template_prefix` is specified, an ``inspect.html``
        template in the prefix directory and its ``{app_label}/{model_name}/``
        or ``{app_label}/`` subdirectories will be used. Otherwise, the
        ``inspect_view_class.template_name`` will be used.
        )get_inspect_templaterY   r;   r;   r<   inspect_template_name  r  z$SnippetViewSet.inspect_template_namec                 C   s   | j d| jjdS )ah  
        Returns a template to be used when rendering ``inspect_view``. If a
        template is specified by the ``inspect_template_name`` attribute, that will
        be used. Otherwise, a list of preferred template names are returned.

        **Deprecated** - the preferred way to customise this is to define an ``inspect_template_name`` property.
        r   r?  )rD  inspect_view_classrz   rY   r;   r;   r<   r    s   z#SnippetViewSet.get_inspect_templatec                 C       | j r| j S d| j d| j S )z
        Returns the URL namespace for the admin URLs for this model.

        **Deprecated** - the preferred way to customise this is to define a ``url_namespace`` property.
        wagtailsnippets_rp   )admin_url_namespacer  r9   rY   r;   r;   r<   r    s   z&SnippetViewSet.get_admin_url_namespacec                 C   *   | j r| j  dS d| j d| j S )z
        Returns the base path for the admin URLs for this model.
        The returned string must not begin or end with a slash.

        **Deprecated** - the preferred way to customise this is to define a ``url_prefix`` property.
        /z	snippets/)base_url_pathstripr  r9   rY   r;   r;   r<   r    s   z"SnippetViewSet.get_admin_base_pathc                 C   r  )zDReturns the URL namespace for the chooser admin URLs for this model.wagtailsnippetchoosers_rp   )chooser_admin_url_namespacer  r9   rY   r;   r;   r<   rz    s   z.SnippetViewSet.get_chooser_admin_url_namespacec                 C   r  )z
        Returns the base path for the chooser admin URLs for this model.
        The returned string must not begin or end with a slash.
        r  zsnippets/choose/)chooser_base_url_pathr  r  r9   rY   r;   r;   r<   r{     s   z*SnippetViewSet.get_chooser_admin_base_pathc                 C   s   t dtfd| jiS )N_SnippetAdminURLFinderr:   )ri   r1   r:   rY   r;   r;   r<   url_finder_class	  s   zSnippetViewSet.url_finder_classc                 C   s  t d| jddt d| jddt d| jddt d| jd	dt d
| jddt d| jddt d| jddt d| jddg}| j	rH|t d| j
ddg7 }| jrV|t d| jddg7 }| jrk|t d| jddt d| jddg7 }| jr| jr||t d| jddg7 }|t d| jddtd| jddg7 }| jr|t d | jd!dt d"| jd#dg7 }| jr|t d$| jd%dt d&| jd'dg7 }| jr|t d(| jd)dt d*| jd+dt d,| jd-dt d.| jd/dt d0| j d1dg7 }| jr|t d2| j!d3dg7 }|| j" S )4Nr  r_   )rB   zresults/r  zadd/r[   zedit/<str:pk>/r   zdelete/<str:pk>/r^   zusage/<str:pk>/r   zhistory/<str:pk>/r   zhistory-results/<str:pk>/history_resultszcopy/<str:pk>/r  zinspect/<str:pk>/r   zpreview/r/  zpreview/<str:pk>/r3  z2history/<str:pk>/revisions/<int:revision_id>/view/r  z4history/<str:pk>/revisions/<int:revision_id>/revert/r  zshistory/(?P<pk>.+)/revisions/compare/(?P<revision_id_a>live|earliest|\d+)\.\.\.(?P<revision_id_b>live|latest|\d+)/$r   z8history/<str:pk>/revisions/<int:revision_id>/unschedule/r!  zunpublish/<str:pk>/r"  zlock/<str:pk>/r   zunlock/<str:pk>/r   z@workflow/action/<str:pk>/<slug:action_name>/<int:task_state_id>/r^  zMworkflow/collect_action_data/<str:pk>/<slug:action_name>/<int:task_state_id>/re  z'workflow/confirm_cancellation/<str:pk>/r5  zworkflow_history/<str:pk>/r4  z9workflow_history/<str:pk>/detail/<int:workflow_state_id>/rm  z(workflow/preview/<str:pk>/<int:task_id>/workflow_preview)#r
   
index_viewindex_results_viewadd_view	edit_viewdelete_view
usage_viewhistory_viewhistory_results_viewcopy_view_enabledrZ  inspect_view_enabledinspect_viewr   rO  rR  r  r  r>  r   rE  r   rH  rJ  r  rW  r\  r  rc  rg  ri  rp  rr  rk  _legacy_urlpatterns)rI   urlpatternsr;   r;   r<   get_urlpatterns  s   		
	zSnippetViewSet.get_urlpatternsc                 C   s"   t d| jt d| jt d| jgS )Nz	<str:pk>/z<str:pk>/delete/z<str:pk>/usage/)r
   redirect_to_edit_viewredirect_to_delete_viewrv  rY   r;   r;   r<   r    s   


z"SnippetViewSet._legacy_urlpatternsc                    s<   t   }|r	|S |  }t| j|d}t|}|| jS )z
        Like :meth:`ModelViewSet.get_edit_handler()
        <wagtail.admin.viewsets.model.ModelViewSet.get_edit_handler>`,
        but falls back to extracting panel definitions from the model class
        if no edit handler is defined.
        )exclude)rD   get_edit_handlerget_exclude_form_fieldsr   r:   r   bind_to_model)rI   rA  r  panelsrM   r;   r<   r    s   
zSnippetViewSet.get_edit_handlerc                 C   s   t | j d S rC   )r%   registerr}  rY   r;   r;   r<   register_chooser_viewset  r2  z'SnippetViewSet.register_chooser_viewsetc                    s    fdd}t |d d S )Nc                    s   t  jdS )Nsnippets)r   r:   )app_configsrL   rY   r;   r<   snippets_model_check  s   zASnippetViewSet.register_model_check.<locals>.snippets_model_checkr  )r   r  )rI   r  r;   rY   r<   register_model_check  s   z#SnippetViewSet.register_model_checkc                 C   sD   t  }| j|v rtd| jj d|| j |jdd d d S )NzThe z) model is already registered as a snippetc                 S   s   | j jS rC   )rR   verbose_name)xr;   r;   r<   rj     rk   z7SnippetViewSet.register_snippet_model.<locals>.<lambda>)rs   )r2   r:   r   r|   r   sort)rI   snippet_modelsr;   r;   r<   register_snippet_model  s   
z%SnippetViewSet.register_snippet_modelc                    s.   t    | | j_|   |   |   d S rC   )rD   on_registerr:   r`   r  r  r  rY   rM   r;   r<   r    s
   
zSnippetViewSet.on_register)r|   r}   r~   __doc__r:   r|  r  r  r  r  r   index_view_classr   add_view_classr   rY  r   r  r   delete_view_classr   usage_view_classr   history_view_classr   r  r   r;  r   rB  r   rG  r   rI  r   rM  r   rQ  r   rV  r   r[  r  rb  r  rf  r  rh  r  rj  r  ro  r  rq  r4   ry  template_prefixr
  r   r  r  propertyr  ra   r,  r-  r0  r1  r8  r  r>  rE  rH  rJ  rO  rR  rW  rZ  r\  rc  rg  ri  rk  rp  rr  rv  r}  r~  rw  r  r  r  r  r  r  r  r  r  r  r+  re   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rz  r{  r  r  r  r  r  r  r  r  r   r;   r;   rM   r<   r    s   









	














	




	














	
r

	r  c                       r   )SnippetViewSetGroupz
    A container for grouping together multiple
    :class:`~wagtail.snippets.views.snippets.SnippetViewSet` instances.

    All attributes and methods from
    :class:`~wagtail.admin.viewsets.model.ModelViewSetGroup` are available.
    c                    s2   t | dt| j}| jD ]}||_qt   d S )Nr	  )r   r  r  itemsr	  rD   r
  )rI   r	  itemrM   r;   r<   r
    s   
zSnippetViewSetGroup.__init__)r|   r}   r~   r  r
  r   r;   r;   rM   r<   r    s    r  N)vwarningsr   django.appsr   django.contrib.admin.utilsr   django.corer   django.core.exceptionsr   r   django.httpr   django.shortcutsr	   django.urlsr
   r   r   r   django.utils.functionalr   django.utils.textr   django.utils.translationr   rp   r   wagtailr   wagtail.admin.checksr   wagtail.admin.panelsr   r   wagtail.admin.ui.componentsr   wagtail.admin.ui.side_panelsr   r   wagtail.admin.ui.tablesr   r   r   r   wagtail.admin.viewsr   wagtail.admin.views.genericr   r   r    'wagtail.admin.views.generic.permissionsr!   #wagtail.admin.views.generic.previewr"   r#   r$   wagtail.admin.viewsetsr%   wagtail.admin.viewsets.modelr&   r'   wagtail.admin.widgets.buttonr(   r)   wagtail.modelsr*   r+   r,   r-   r.   wagtail.permissionsr/   wagtail.snippets.action_menur0   wagtail.snippets.modelsr1   r2   wagtail.snippets.side_panelsr3   wagtail.snippets.views.chooserr4   wagtail.utils.deprecationr5   r=   BaseListingViewr>   IndexViewOptionalFeaturesMixinr   #CreateEditViewOptionalFeaturesMixinr   CopyViewMixinr   r   r   r   r   r   r   r   r   r   r   r   r   r   WorkflowActionr  CollectWorkflowActionDatar  ConfirmWorkflowCancellationr  PreviewRevisionForTaskr  r  r  r  r  r;   r;   r;   r<   <module>   s    QD*6

      