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

Add remove workflow action to page list. Move save button out of footer to emphasize that removing a page is not an unsaved action

This commit is contained in:
jacobtm 2019-11-12 11:33:57 +00:00 committed by Matt Westcott
parent 7fceab2306
commit c38e9cfcd4
4 changed files with 84 additions and 30 deletions

View File

@ -28,24 +28,36 @@
{% csrf_token %} {% csrf_token %}
{% block form %}{{ edit_handler.render_form_content }}{% endblock %} {% block form %}{{ edit_handler.render_form_content }}{% endblock %}
<div class="object">
{% block footer %} <ul class="object-layout">
<footer role="contentinfo"> <li class="object-layout_big-part">
<ul> {% block form_actions %}
<li class="actions"> <p class="save">
{% block form_actions %} <button type="submit" class="button action-save button-longrunning" data-clicked-text="{% trans 'Saving…' %}">
<div class="dropdown dropup dropdown-button match-width"> <span class="icon icon-spinner"></span><em>{% trans 'Save' %}</em>
<button type="submit" class="button action-save button-longrunning" data-clicked-text="{% trans 'Saving…' %}"> </button>
<span class="icon icon-spinner"></span><em>{% trans 'Save' %}</em> </p>
</button> {% endblock %}
</div> </li>
{% endblock %} </ul>
</li> </div>
<li>
<a href="{{ view.delete_url }}" class="button">Disable</a>
</li>
</ul>
</footer>
{% endblock %}
</form> </form>
{% if pages %}
<div class="object">
<div class="title-wrapper">Pages</div>
<div class="object-layout">
<div class="object-layout_big-part">
<div class="multiple">
{% include "wagtailadmin/workflows/listing/_list_workflow_pages.html" %}
<p class="add">
<a class="button bicolor icon icon-plus">
Add
</a>
</p>
</div>
</div>
</div>
</div>
{% endif %}
{% endblock %} {% endblock %}

View File

@ -0,0 +1,13 @@
{% extends "wagtailadmin/pages/listing/_list_explore.html" %}
{% load i18n wagtailadmin_tags %}
{% block page_navigation %}
<td class="remove-workflow" valign="top">
<form action="{% url 'wagtailadmin_workflows:remove' page.id %}" method="post">
{% csrf_token %}
<input type="hidden" name="next" value="{{ request.path }}">
<button type="submit" class="button button-secondary button-small">{% trans 'Remove' %}</button>
</form>
</td>
{% endblock %}

View File

@ -7,4 +7,5 @@ urlpatterns = [
path('', workflows.Index.as_view(), name='index'), path('', workflows.Index.as_view(), name='index'),
path('add/', workflows.create, name='add'), path('add/', workflows.create, name='add'),
path('edit/<int:pk>', workflows.edit, name='edit'), path('edit/<int:pk>', workflows.edit, name='edit'),
path('remove/<int:pk>', workflows.remove_workflow, name='remove')
] ]

View File

@ -1,21 +1,23 @@
from django.http import HttpResponseForbidden from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404, redirect from django.utils.http import is_safe_url
from django.utils.translation import ugettext_lazy from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import require_POST
from wagtail.admin import messages from wagtail.admin import messages
from wagtail.admin.edit_handlers import ObjectList, FieldPanel, InlinePanel, get_edit_handler from wagtail.admin.edit_handlers import ObjectList, FieldPanel, InlinePanel, get_edit_handler
from wagtail.admin.views.generic import CreateView, DeleteView, EditView, IndexView from wagtail.admin.views.generic import CreateView, DeleteView, EditView, IndexView
from wagtail.core import hooks from wagtail.core.models import Page, Workflow
from wagtail.core.models import Workflow
from wagtail.admin.views.pages import get_valid_next_url_from_request from wagtail.admin.views.pages import get_valid_next_url_from_request
from wagtail.core.permissions import workflow_permission_policy from wagtail.core.permissions import workflow_permission_policy
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
Workflow.panels = [ Workflow.panels = [
FieldPanel("name"), FieldPanel("name"),
InlinePanel("workflow_tasks"), FieldPanel("active"),
InlinePanel("workflow_tasks", heading="Tasks"),
] ]
def get_handler(): def get_handler():
handler = ObjectList(Workflow.panels) handler = ObjectList(Workflow.panels)
handler.bind_to(model=Workflow) handler.bind_to(model=Workflow)
@ -32,8 +34,8 @@ class Index(IndexView):
template_name = 'wagtailadmin/workflows/index.html' template_name = 'wagtailadmin/workflows/index.html'
add_url_name = 'wagtailadmin_workflows:add' add_url_name = 'wagtailadmin_workflows:add'
edit_url_name = 'wagtailadmin_workflows:edit' edit_url_name = 'wagtailadmin_workflows:edit'
page_title = ugettext_lazy("Workflows") page_title = _("Workflows")
add_item_label = ugettext_lazy("Add a workflow") add_item_label = _("Add a workflow")
header_icon = 'placeholder' header_icon = 'placeholder'
@ -58,7 +60,7 @@ def create(request):
'edit_handler': edit_handler, 'edit_handler': edit_handler,
'form': form, 'form': form,
'icon': 'placeholder', 'icon': 'placeholder',
'title': ugettext_lazy("Workflows"), 'title': _("Workflows"),
'next': next_url, 'next': next_url,
}) })
@ -68,6 +70,7 @@ def edit(request, pk):
edit_handler = Workflow.get_edit_handler() edit_handler = Workflow.get_edit_handler()
edit_handler = edit_handler.bind_to(request=request, instance=workflow) edit_handler = edit_handler.bind_to(request=request, instance=workflow)
form_class = edit_handler.get_form_class() form_class = edit_handler.get_form_class()
pages = Page.objects.filter(workflow=workflow)
next_url = get_valid_next_url_from_request(request) next_url = get_valid_next_url_from_request(request)
@ -84,7 +87,32 @@ def edit(request, pk):
'edit_handler': edit_handler, 'edit_handler': edit_handler,
'form': form, 'form': form,
'icon': 'placeholder', 'icon': 'placeholder',
'title': ugettext_lazy("Workflows"), 'title': _("Workflows"),
'subtitle': ugettext_lazy("Edit Workflow"), 'subtitle': _("Edit Workflow"),
'next': next_url, 'next': next_url,
'pages': pages
}) })
@require_POST
def remove_workflow(request, pk):
# Get the page
page = get_object_or_404(Page, id=pk).specific
# Check permissions
if not request.user.is_superuser:
raise PermissionDenied
# Unlock the page
if page.workflow:
page.workflow = None
page.save()
messages.success(request, _("Workflow unassigned from Page '{0}'.").format(page.get_admin_display_title()))
# Redirect
redirect_to = request.POST.get('next', None)
if redirect_to and is_safe_url(url=redirect_to, allowed_hosts={request.get_host()}):
return redirect(redirect_to)
else:
return redirect('wagtailadmin_explore', page.get_parent().id)