0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Add workflow deletion view

This commit is contained in:
jacobtm 2020-01-16 13:47:46 +00:00 committed by Matt Westcott
parent a181a85820
commit 759228d37d
4 changed files with 43 additions and 2 deletions

View File

@ -0,0 +1,17 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n %}
{% block titletag %}{{ view.page_title }}{% endblock %}
{% block content %}
{% include "wagtailadmin/shared/header.html" with title=view.page_title subtitle=view.get_page_subtitle icon=view.header_icon %}
<div class="nice-padding">
<p>This workflow is currently in progress on {{ workflow_states_in_progress }} pages. Deleting this workflow will cancel moderation on these page.
Are you sure you want to delete this workflow?</p>
<form action="{{ view.get_delete_url }}" method="POST">
{% csrf_token %}
<input type="submit" value="{% trans 'Yes, delete' %}" class="button serious" />
<a class="button button-secondary" href="{{ view.get_edit_url }}">No</a>
</form>
</div>
{% endblock %}

View File

@ -30,10 +30,13 @@
<div class="object">
<ul class="object-layout">
<li class="object-layout_big-part">
<p class="save">
<p class="actions">
<button type="submit" class="button action-save button-longrunning" data-clicked-text="{% trans 'Saving…' %}">
<span class="icon icon-spinner"></span><em>{% trans 'Save' %}</em>
</button>
{% if can_delete %}
<a href="{{ view.get_delete_url }}" class="button button-secondary no">{{ view.delete_item_label }}</a>
{% endif %}
</p>
</li>
</ul>

View File

@ -7,6 +7,7 @@ app_name = 'wagtailadmin_workflows'
urlpatterns = [
path('', workflows.Index.as_view(), name='index'),
path('add/', workflows.Create.as_view(), name='add'),
path('delete/<int:pk>/', workflows.Delete.as_view(), name='delete'),
path('edit/<int:pk>/', workflows.Edit.as_view(), name='edit'),
path('remove/<int:page_pk>/', workflows.remove_workflow, name='remove'),
path('remove/<int:page_pk>/<int:workflow_pk>/', workflows.remove_workflow, name='remove'),

View File

@ -12,7 +12,7 @@ from wagtail.admin import messages
from wagtail.admin.edit_handlers import Workflow
from wagtail.admin.forms.workflows import AddWorkflowToPageForm
from wagtail.admin.views.generic import CreateView, DeleteView, EditView, IndexView
from wagtail.core.models import Page, Task, WorkflowPage, WorkflowTask
from wagtail.core.models import Page, Task, WorkflowPage, WorkflowState, WorkflowTask
from wagtail.admin.views.pages import get_valid_next_url_from_request
from wagtail.core.permissions import workflow_permission_policy, task_permission_policy
from django.shortcuts import get_object_or_404, redirect, render
@ -70,6 +70,7 @@ class Edit(EditView):
success_message = _("Workflow '{0}' updated.")
add_url_name = 'wagtailadmin_workflows:add'
edit_url_name = 'wagtailadmin_workflows:edit'
delete_url_name = 'wagtailadmin_workflows:delete'
index_url_name = 'wagtailadmin_workflows:index'
header_icon = 'placeholder'
edit_handler = None
@ -104,6 +105,25 @@ class Edit(EditView):
return context
class Delete(DeleteView):
permission_policy = workflow_permission_policy
model = Workflow
page_title = _("Delete workflow")
template_name = 'wagtailadmin/workflows/confirm_delete.html'
success_message = _("Workflow '{0}' deleted.")
add_url_name = 'wagtailadmin_workflows:add'
edit_url_name = 'wagtailadmin_workflows:edit'
delete_url_name = 'wagtailadmin_workflows:delete'
index_url_name = 'wagtailadmin_workflows:index'
header_icon = 'placeholder'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['workflow_states_in_progress'] = WorkflowState.objects.filter(status=WorkflowState.STATUS_IN_PROGRESS).count()
return context
@require_POST
def remove_workflow(request, page_pk, workflow_pk=None):
# Remove a workflow from a page (specifically a single workflow if workflow_pk is set)