mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 17:36:49 +01:00
Move page delete view to wagtail.admin.views.pages.delete
This commit is contained in:
parent
085f38f457
commit
9b9310133c
@ -1,5 +1,4 @@
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import transaction
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.template.response import TemplateResponse
|
||||
@ -13,6 +12,7 @@ from wagtail.core.models import Page, UserPagePermissionsProxy
|
||||
|
||||
from wagtail.admin.views.pages.copy import * # noqa
|
||||
from wagtail.admin.views.pages.create import * # noqa
|
||||
from wagtail.admin.views.pages.delete import * # noqa
|
||||
from wagtail.admin.views.pages.edit import * # noqa
|
||||
from wagtail.admin.views.pages.history import * # noqa
|
||||
from wagtail.admin.views.pages.listing import * # noqa
|
||||
@ -26,41 +26,6 @@ from wagtail.admin.views.pages.usage import * # noqa
|
||||
from wagtail.admin.views.pages.workflow import * # noqa
|
||||
|
||||
|
||||
def delete(request, page_id):
|
||||
page = get_object_or_404(Page, id=page_id).specific
|
||||
if not page.permissions_for_user(request.user).can_delete():
|
||||
raise PermissionDenied
|
||||
|
||||
with transaction.atomic():
|
||||
for fn in hooks.get_hooks('before_delete_page'):
|
||||
result = fn(request, page)
|
||||
if hasattr(result, 'status_code'):
|
||||
return result
|
||||
|
||||
next_url = get_valid_next_url_from_request(request)
|
||||
|
||||
if request.method == 'POST':
|
||||
parent_id = page.get_parent().id
|
||||
page.delete(user=request.user)
|
||||
|
||||
messages.success(request, _("Page '{0}' deleted.").format(page.get_admin_display_title()))
|
||||
|
||||
for fn in hooks.get_hooks('after_delete_page'):
|
||||
result = fn(request, page)
|
||||
if hasattr(result, 'status_code'):
|
||||
return result
|
||||
|
||||
if next_url:
|
||||
return redirect(next_url)
|
||||
return redirect('wagtailadmin_explore', parent_id)
|
||||
|
||||
return TemplateResponse(request, 'wagtailadmin/pages/confirm_delete.html', {
|
||||
'page': page,
|
||||
'descendant_count': page.get_descendant_count(),
|
||||
'next': next_url,
|
||||
})
|
||||
|
||||
|
||||
def unpublish(request, page_id):
|
||||
page = get_object_or_404(Page, id=page_id).specific
|
||||
|
||||
|
45
wagtail/admin/views/pages/delete.py
Normal file
45
wagtail/admin/views/pages/delete.py
Normal file
@ -0,0 +1,45 @@
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db import transaction
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from wagtail.admin import messages
|
||||
from wagtail.admin.views.pages.utils import get_valid_next_url_from_request
|
||||
from wagtail.core import hooks
|
||||
from wagtail.core.models import Page
|
||||
|
||||
|
||||
def delete(request, page_id):
|
||||
page = get_object_or_404(Page, id=page_id).specific
|
||||
if not page.permissions_for_user(request.user).can_delete():
|
||||
raise PermissionDenied
|
||||
|
||||
with transaction.atomic():
|
||||
for fn in hooks.get_hooks('before_delete_page'):
|
||||
result = fn(request, page)
|
||||
if hasattr(result, 'status_code'):
|
||||
return result
|
||||
|
||||
next_url = get_valid_next_url_from_request(request)
|
||||
|
||||
if request.method == 'POST':
|
||||
parent_id = page.get_parent().id
|
||||
page.delete(user=request.user)
|
||||
|
||||
messages.success(request, _("Page '{0}' deleted.").format(page.get_admin_display_title()))
|
||||
|
||||
for fn in hooks.get_hooks('after_delete_page'):
|
||||
result = fn(request, page)
|
||||
if hasattr(result, 'status_code'):
|
||||
return result
|
||||
|
||||
if next_url:
|
||||
return redirect(next_url)
|
||||
return redirect('wagtailadmin_explore', parent_id)
|
||||
|
||||
return TemplateResponse(request, 'wagtailadmin/pages/confirm_delete.html', {
|
||||
'page': page,
|
||||
'descendant_count': page.get_descendant_count(),
|
||||
'next': next_url,
|
||||
})
|
Loading…
Reference in New Issue
Block a user