kopia lustrzana https://github.com/wagtail/wagtail
Convert page listing view to a class-based view
rodzic
6d4265cbfa
commit
ccb08a3a8a
|
|
@ -28,8 +28,12 @@ urlpatterns = [
|
|||
path("api/", include(api_urls)),
|
||||
path("failwhale/", home.error_test, name="wagtailadmin_error_test"),
|
||||
# TODO: Move into wagtailadmin_pages namespace
|
||||
path("pages/", listing.index, name="wagtailadmin_explore_root"),
|
||||
path("pages/<int:parent_page_id>/", listing.index, name="wagtailadmin_explore"),
|
||||
path("pages/", listing.IndexView.as_view(), name="wagtailadmin_explore_root"),
|
||||
path(
|
||||
"pages/<int:parent_page_id>/",
|
||||
listing.IndexView.as_view(),
|
||||
name="wagtailadmin_explore",
|
||||
),
|
||||
# bulk actions
|
||||
path(
|
||||
"bulk/<str:app_label>/<str:model_name>/<str:action>/",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ from django.http import Http404
|
|||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.generic import View
|
||||
|
||||
from wagtail import hooks
|
||||
from wagtail.admin.auth import user_has_any_page_permission, user_passes_test
|
||||
|
|
@ -12,8 +14,9 @@ from wagtail.admin.ui.side_panels import PageSidePanels
|
|||
from wagtail.permission_policies.pages import Page, PagePermissionPolicy
|
||||
|
||||
|
||||
@user_passes_test(user_has_any_page_permission)
|
||||
def index(request, parent_page_id=None):
|
||||
class IndexView(View):
|
||||
@method_decorator(user_passes_test(user_has_any_page_permission))
|
||||
def get(self, request, parent_page_id=None):
|
||||
if parent_page_id:
|
||||
parent_page = get_object_or_404(Page, id=parent_page_id)
|
||||
else:
|
||||
|
|
@ -26,7 +29,9 @@ def index(request, parent_page_id=None):
|
|||
|
||||
# If this page isn't a descendant of the user's explorable root page,
|
||||
# then redirect to that explorable root page instead.
|
||||
if not (parent_page.pk == root_page.pk or parent_page.is_descendant_of(root_page)):
|
||||
if not (
|
||||
parent_page.pk == root_page.pk or parent_page.is_descendant_of(root_page)
|
||||
):
|
||||
return redirect("wagtailadmin_explore", root_page.pk)
|
||||
|
||||
parent_page = parent_page.specific
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue