Skip to content

Commit

Permalink
Remove conditional code from Wagtail < 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
katdom13 committed Feb 26, 2024
1 parent ee9aedb commit 2750602
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
16 changes: 4 additions & 12 deletions src/wagtail_periodic_review/views.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
from django.core.exceptions import FieldError
from django.utils.translation import gettext as _
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail.admin.views.reports import ReportView
from wagtail.permission_policies.pages import PagePermissionPolicy

from .filters import PeriodicReviewFilterSet
from .utils import add_review_date_annotations, filter_across_subtypes


if WAGTAIL_VERSION >= (5, 1):
from wagtail.permission_policies.pages import PagePermissionPolicy
else:
from wagtail.models import UserPagePermissionsProxy


class PeriodicReviewContentReport(ReportView):
title = _("Periodic review content")
header_icon = "wpr-calendar-stats"
template_name = "reports/periodic_review_report.html"
filterset_class = PeriodicReviewFilterSet

def _get_editable_pages(self):
if WAGTAIL_VERSION >= (5, 1):
return PagePermissionPolicy().instances_user_has_permission_for(
self.request.user, "change"
)
return UserPagePermissionsProxy(self.request.user).editable_pages()
return PagePermissionPolicy().instances_user_has_permission_for(
self.request.user, "change"
)

def get_queryset(self):
queryset = filter_across_subtypes(
Expand Down
16 changes: 4 additions & 12 deletions src/wagtail_periodic_review/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

from django.urls import path, reverse
from django.utils.translation import gettext as _
from wagtail import VERSION as WAGTAIL_VERSION
from wagtail import hooks
from wagtail.admin.menu import MenuItem
from wagtail.admin.ui.components import Component
from wagtail.permission_policies.pages import PagePermissionPolicy

from .utils import for_review_this_month, review_overdue
from .views import PeriodicReviewContentReport


if WAGTAIL_VERSION >= (5, 1):
from wagtail.permission_policies.pages import PagePermissionPolicy
else:
from wagtail.models import UserPagePermissionsProxy


class BaseHomePanel(Component):
heading = ""
description = ""
Expand All @@ -28,11 +22,9 @@ def __init__(self, request):
self.request = request

def get_page_list(self):
if WAGTAIL_VERSION >= (5, 1):
return PagePermissionPolicy().instances_user_has_permission_for(
self.request.user, "change"
)
return UserPagePermissionsProxy(self.request.user).editable_pages()
return PagePermissionPolicy().instances_user_has_permission_for(
self.request.user, "change"
)

def get_context_data(self, parent_context: Mapping[str, Any]) -> Mapping[str, Any]:
context = super().get_context_data(parent_context)
Expand Down

0 comments on commit 2750602

Please sign in to comment.