kopia lustrzana https://github.com/wagtail/wagtail
Deprecate ReportView.title in favour of page_title
The latter is enforced by WagtailAdminTemplateMixinpull/11987/head
rodzic
c18068c079
commit
94baf0645a
|
@ -76,13 +76,16 @@ In this example, we'll change this to a new template in a later section.
|
||||||
.. versionadded:: 6.2
|
.. versionadded:: 6.2
|
||||||
The ``results_template_name`` attribute was added to support updating the listing via AJAX upon filtering and to allow the use of the ``wagtail.admin.ui.tables`` framework.
|
The ``results_template_name`` attribute was added to support updating the listing via AJAX upon filtering and to allow the use of the ``wagtail.admin.ui.tables`` framework.
|
||||||
|
|
||||||
.. attribute:: title
|
.. attribute:: page_title
|
||||||
|
|
||||||
(string)
|
(string)
|
||||||
|
|
||||||
The name of your report, which will be displayed in the header. For our example, we'll set it to
|
The name of your report, which will be displayed in the header. For our example, we'll set it to
|
||||||
``"Pages with unpublished changes"``.
|
``"Pages with unpublished changes"``.
|
||||||
|
|
||||||
|
.. versionchanged:: 6.2
|
||||||
|
The ``title`` attribute was renamed to ``page_title``.
|
||||||
|
|
||||||
.. attribute:: header_icon
|
.. attribute:: header_icon
|
||||||
|
|
||||||
(string)
|
(string)
|
||||||
|
@ -250,7 +253,7 @@ class UnpublishedChangesReportView(PageReportView):
|
||||||
index_results_url_name = "unpublished_changes_report_results"
|
index_results_url_name = "unpublished_changes_report_results"
|
||||||
header_icon = 'doc-empty-inverse'
|
header_icon = 'doc-empty-inverse'
|
||||||
results_template_name = 'reports/unpublished_changes_report_results.html'
|
results_template_name = 'reports/unpublished_changes_report_results.html'
|
||||||
title = "Pages with unpublished changes"
|
page_title = "Pages with unpublished changes"
|
||||||
|
|
||||||
list_export = PageReportView.list_export + ['last_published_at']
|
list_export = PageReportView.list_export + ['last_published_at']
|
||||||
export_headings = dict(last_published_at='Last Published', **PageReportView.export_headings)
|
export_headings = dict(last_published_at='Last Published', **PageReportView.export_headings)
|
||||||
|
|
|
@ -152,6 +152,16 @@ As a result, a number of changes have been made to the `ReportView` and `PageRep
|
||||||
|
|
||||||
If you have custom report views as documented in [](adding_reports), you will need to make the following changes.
|
If you have custom report views as documented in [](adding_reports), you will need to make the following changes.
|
||||||
|
|
||||||
|
#### Change `title` to `page_title`
|
||||||
|
|
||||||
|
The `title` attribute on the view class should be renamed to `page_title`:
|
||||||
|
|
||||||
|
```diff
|
||||||
|
class UnpublishedChangesReportView(PageReportView):
|
||||||
|
- title = "Pages with unpublished changes"
|
||||||
|
+ page_title = "Pages with unpublished changes"
|
||||||
|
```
|
||||||
|
|
||||||
#### Set up the results-only view
|
#### Set up the results-only view
|
||||||
|
|
||||||
Set the `index_url_name` and `index_results_url_name` attributes on the view class:
|
Set the `index_url_name` and `index_results_url_name` attributes on the view class:
|
||||||
|
|
|
@ -33,6 +33,7 @@ from wagtail.test.testapp.models import (
|
||||||
)
|
)
|
||||||
from wagtail.test.utils import WagtailTestUtils
|
from wagtail.test.utils import WagtailTestUtils
|
||||||
from wagtail.test.utils.template_tests import AdminTemplateTestUtils
|
from wagtail.test.utils.template_tests import AdminTemplateTestUtils
|
||||||
|
from wagtail.utils.deprecation import RemovedInWagtail70Warning
|
||||||
|
|
||||||
|
|
||||||
class BaseReportViewTestCase(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
|
class BaseReportViewTestCase(AdminTemplateTestUtils, WagtailTestUtils, TestCase):
|
||||||
|
@ -97,6 +98,14 @@ class BaseReportViewTestCase(AdminTemplateTestUtils, WagtailTestUtils, TestCase)
|
||||||
else:
|
else:
|
||||||
self.assertBreadcrumbsItemsRendered(breadcrumbs, html)
|
self.assertBreadcrumbsItemsRendered(breadcrumbs, html)
|
||||||
|
|
||||||
|
def assertPageTitle(self, soup, title):
|
||||||
|
page_title = soup.select_one("title")
|
||||||
|
if self.results_only:
|
||||||
|
self.assertIsNone(page_title)
|
||||||
|
else:
|
||||||
|
self.assertIsNotNone(page_title)
|
||||||
|
self.assertEqual(page_title.text.strip(), title)
|
||||||
|
|
||||||
|
|
||||||
class TestLockedPagesView(BaseReportViewTestCase):
|
class TestLockedPagesView(BaseReportViewTestCase):
|
||||||
url_name = "wagtailadmin_reports:locked_pages"
|
url_name = "wagtailadmin_reports:locked_pages"
|
||||||
|
@ -131,6 +140,7 @@ class TestLockedPagesView(BaseReportViewTestCase):
|
||||||
self.assertEqual(locked_by_options[0].text, "---------")
|
self.assertEqual(locked_by_options[0].text, "---------")
|
||||||
self.assertEqual(locked_by_options[0].get("value"), "")
|
self.assertEqual(locked_by_options[0].get("value"), "")
|
||||||
self.assertActiveFilterNotRendered(soup)
|
self.assertActiveFilterNotRendered(soup)
|
||||||
|
self.assertPageTitle(soup, "Locked pages - Wagtail")
|
||||||
|
|
||||||
parent_page = Page.objects.first()
|
parent_page = Page.objects.first()
|
||||||
parent_page.add_child(
|
parent_page.add_child(
|
||||||
|
@ -500,6 +510,7 @@ class TestFilteredLogEntriesView(BaseReportViewTestCase):
|
||||||
|
|
||||||
soup = self.get_soup(response.content)
|
soup = self.get_soup(response.content)
|
||||||
self.assertActiveFilterNotRendered(soup)
|
self.assertActiveFilterNotRendered(soup)
|
||||||
|
self.assertPageTitle(soup, "Site history - Wagtail")
|
||||||
|
|
||||||
# The editor should not see the Advert's log entries.
|
# The editor should not see the Advert's log entries.
|
||||||
self.login(user=self.editor)
|
self.login(user=self.editor)
|
||||||
|
@ -797,6 +808,41 @@ class TestFilteredLogEntriesView(BaseReportViewTestCase):
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_deprecated_title_attribute(self):
|
||||||
|
# Remove this test when the deprecation ends
|
||||||
|
with mock.patch.object(
|
||||||
|
LogEntriesView,
|
||||||
|
"page_title",
|
||||||
|
return_value=None,
|
||||||
|
new_callable=mock.PropertyMock,
|
||||||
|
), mock.patch.object(
|
||||||
|
LogEntriesView,
|
||||||
|
"title",
|
||||||
|
return_value="Deprecated page title",
|
||||||
|
new_callable=mock.PropertyMock,
|
||||||
|
):
|
||||||
|
with self.assertWarnsMessage(
|
||||||
|
RemovedInWagtail70Warning,
|
||||||
|
"The `title` attribute in `LogEntriesView` (a `ReportView` subclass) is "
|
||||||
|
"deprecated. Use `page_title` instead.",
|
||||||
|
):
|
||||||
|
self.assertEqual(LogEntriesView.title, "Deprecated page title")
|
||||||
|
self.assertIsNone(LogEntriesView.page_title)
|
||||||
|
response = self.get()
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertPageTitle(
|
||||||
|
self.get_soup(response.content),
|
||||||
|
"Deprecated page title - Wagtail",
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
response.context["page_title"],
|
||||||
|
"Deprecated page title",
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
response.context["title"],
|
||||||
|
"Deprecated page title",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestFilteredLogEntriesResultsView(TestFilteredLogEntriesView):
|
class TestFilteredLogEntriesResultsView(TestFilteredLogEntriesView):
|
||||||
url_name = "wagtailadmin_reports:site_history_results"
|
url_name = "wagtailadmin_reports:site_history_results"
|
||||||
|
@ -855,6 +901,7 @@ class TestAgingPagesView(BaseReportViewTestCase):
|
||||||
)
|
)
|
||||||
soup = self.get_soup(response.content)
|
soup = self.get_soup(response.content)
|
||||||
self.assertActiveFilterNotRendered(soup)
|
self.assertActiveFilterNotRendered(soup)
|
||||||
|
self.assertPageTitle(soup, "Aging pages - Wagtail")
|
||||||
|
|
||||||
def test_displays_only_published_pages(self):
|
def test_displays_only_published_pages(self):
|
||||||
response = self.get()
|
response = self.get()
|
||||||
|
@ -1130,6 +1177,7 @@ class PageTypesUsageReportViewTest(BaseReportViewTestCase):
|
||||||
)
|
)
|
||||||
soup = self.get_soup(response.content)
|
soup = self.get_soup(response.content)
|
||||||
self.assertActiveFilterNotRendered(soup)
|
self.assertActiveFilterNotRendered(soup)
|
||||||
|
self.assertPageTitle(soup, "Page types usage - Wagtail")
|
||||||
|
|
||||||
def test_displays_only_page_types(self):
|
def test_displays_only_page_types(self):
|
||||||
"""Asserts that the correct models are included in the queryset."""
|
"""Asserts that the correct models are included in the queryset."""
|
||||||
|
|
|
@ -2909,6 +2909,9 @@ class TestPageWorkflowReport(BasePageWorkflowTests):
|
||||||
def assertBreadcrumbs(self, breadcrumbs, html):
|
def assertBreadcrumbs(self, breadcrumbs, html):
|
||||||
self.assertBreadcrumbsItemsRendered(breadcrumbs, html)
|
self.assertBreadcrumbsItemsRendered(breadcrumbs, html)
|
||||||
|
|
||||||
|
def assertPageTitle(self, soup, title):
|
||||||
|
self.assertEqual(soup.select_one("title").text.strip(), title)
|
||||||
|
|
||||||
def get(self, url, params=None):
|
def get(self, url, params=None):
|
||||||
return self.client.get(url, params)
|
return self.client.get(url, params)
|
||||||
|
|
||||||
|
@ -2953,6 +2956,7 @@ class TestPageWorkflowReport(BasePageWorkflowTests):
|
||||||
)
|
)
|
||||||
self.assertEqual(list(by_task_link.children)[-1].strip(), "By task")
|
self.assertEqual(list(by_task_link.children)[-1].strip(), "By task")
|
||||||
self.assertIsNone(soup.select_one(".w-active-filters"))
|
self.assertIsNone(soup.select_one(".w-active-filters"))
|
||||||
|
self.assertPageTitle(soup, "Workflows - Wagtail")
|
||||||
|
|
||||||
response = self.get(reverse(self.workflow_tasks_url_name))
|
response = self.get(reverse(self.workflow_tasks_url_name))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
@ -2972,6 +2976,7 @@ class TestPageWorkflowReport(BasePageWorkflowTests):
|
||||||
)
|
)
|
||||||
self.assertEqual(list(by_task_link.children)[-1].strip(), "By workflow")
|
self.assertEqual(list(by_task_link.children)[-1].strip(), "By workflow")
|
||||||
self.assertIsNone(soup.select_one(".w-active-filters"))
|
self.assertIsNone(soup.select_one(".w-active-filters"))
|
||||||
|
self.assertPageTitle(soup, "Workflow tasks - Wagtail")
|
||||||
|
|
||||||
def test_workflow_report_filtered(self):
|
def test_workflow_report_filtered(self):
|
||||||
# the moderator can review the task, so the workflow state should show up even when reports are filtered by reviewable
|
# the moderator can review the task, so the workflow state should show up even when reports are filtered by reviewable
|
||||||
|
@ -3161,6 +3166,9 @@ class TestPageWorkflowReportResults(TestPageWorkflowReport):
|
||||||
def assertBreadcrumbs(self, breadcrumbs, html):
|
def assertBreadcrumbs(self, breadcrumbs, html):
|
||||||
self.assertBreadcrumbsNotRendered(html)
|
self.assertBreadcrumbsNotRendered(html)
|
||||||
|
|
||||||
|
def assertPageTitle(self, soup, title):
|
||||||
|
self.assertIsNone(soup.select_one("title"))
|
||||||
|
|
||||||
def get(self, url, params=None):
|
def get(self, url, params=None):
|
||||||
params = params or {}
|
params = params or {}
|
||||||
params["_w_filter_fragment"] = "true"
|
params["_w_filter_fragment"] = "true"
|
||||||
|
|
|
@ -30,7 +30,7 @@ class AgingPagesReportFilterSet(WagtailFilterSet):
|
||||||
|
|
||||||
class AgingPagesView(PageReportView):
|
class AgingPagesView(PageReportView):
|
||||||
results_template_name = "wagtailadmin/reports/aging_pages_results.html"
|
results_template_name = "wagtailadmin/reports/aging_pages_results.html"
|
||||||
title = _("Aging pages")
|
page_title = _("Aging pages")
|
||||||
header_icon = "time"
|
header_icon = "time"
|
||||||
filterset_class = AgingPagesReportFilterSet
|
filterset_class = AgingPagesReportFilterSet
|
||||||
index_url_name = "wagtailadmin_reports:aging_pages"
|
index_url_name = "wagtailadmin_reports:aging_pages"
|
||||||
|
|
|
@ -74,7 +74,7 @@ class SiteHistoryReportFilterSet(PageHistoryFilterSet):
|
||||||
|
|
||||||
class LogEntriesView(ReportView):
|
class LogEntriesView(ReportView):
|
||||||
results_template_name = "wagtailadmin/reports/site_history_results.html"
|
results_template_name = "wagtailadmin/reports/site_history_results.html"
|
||||||
title = _("Site history")
|
page_title = _("Site history")
|
||||||
header_icon = "history"
|
header_icon = "history"
|
||||||
filterset_class = SiteHistoryReportFilterSet
|
filterset_class = SiteHistoryReportFilterSet
|
||||||
index_url_name = "wagtailadmin_reports:site_history"
|
index_url_name = "wagtailadmin_reports:site_history"
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
|
from warnings import warn
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from wagtail.admin.views.generic.base import BaseListingView
|
from wagtail.admin.views.generic.base import BaseListingView
|
||||||
from wagtail.admin.views.mixins import SpreadsheetExportMixin
|
from wagtail.admin.views.mixins import SpreadsheetExportMixin
|
||||||
|
from wagtail.utils.deprecation import RemovedInWagtail70Warning
|
||||||
|
|
||||||
|
|
||||||
class ReportView(SpreadsheetExportMixin, BaseListingView):
|
class ReportView(SpreadsheetExportMixin, BaseListingView):
|
||||||
|
@ -17,9 +20,17 @@ class ReportView(SpreadsheetExportMixin, BaseListingView):
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_page_title(self):
|
def get_page_title(self):
|
||||||
|
if self.page_title:
|
||||||
|
return self.page_title
|
||||||
# WagtailAdminTemplateMixin uses `page_title`, but the documented approach
|
# WagtailAdminTemplateMixin uses `page_title`, but the documented approach
|
||||||
# for ReportView uses `title`, so we change the reference here to allow
|
# for ReportView used `title`, so we need to support both during the
|
||||||
# using the generic base template while keeping the `title` attribute
|
# deprecation period. When `title` is removed, this and the `get_context_data`
|
||||||
|
# overrides can be removed.
|
||||||
|
warn(
|
||||||
|
f"The `title` attribute in `{self.__class__.__name__}` (a `ReportView` subclass) "
|
||||||
|
"is deprecated. Use `page_title` instead.",
|
||||||
|
RemovedInWagtail70Warning,
|
||||||
|
)
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
def get_filtered_queryset(self):
|
def get_filtered_queryset(self):
|
||||||
|
@ -41,7 +52,7 @@ class ReportView(SpreadsheetExportMixin, BaseListingView):
|
||||||
|
|
||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
context = super().get_context_data(*args, **kwargs)
|
context = super().get_context_data(*args, **kwargs)
|
||||||
context["title"] = self.title
|
context["title"] = self.get_page_title()
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def render_to_response(self, context, **response_kwargs):
|
def render_to_response(self, context, **response_kwargs):
|
||||||
|
|
|
@ -35,7 +35,7 @@ class LockedPagesReportFilterSet(WagtailFilterSet):
|
||||||
|
|
||||||
class LockedPagesView(PageReportView):
|
class LockedPagesView(PageReportView):
|
||||||
results_template_name = "wagtailadmin/reports/locked_pages_results.html"
|
results_template_name = "wagtailadmin/reports/locked_pages_results.html"
|
||||||
title = _("Locked pages")
|
page_title = _("Locked pages")
|
||||||
header_icon = "lock"
|
header_icon = "lock"
|
||||||
list_export = PageReportView.list_export + [
|
list_export = PageReportView.list_export + [
|
||||||
"locked_at",
|
"locked_at",
|
||||||
|
|
|
@ -97,7 +97,7 @@ class PageTypesUsageReportFilterSet(WagtailFilterSet):
|
||||||
|
|
||||||
class PageTypesUsageReportView(ReportView):
|
class PageTypesUsageReportView(ReportView):
|
||||||
results_template_name = "wagtailadmin/reports/page_types_usage_results.html"
|
results_template_name = "wagtailadmin/reports/page_types_usage_results.html"
|
||||||
title = _("Page types usage")
|
page_title = _("Page types usage")
|
||||||
header_icon = "doc-empty-inverse"
|
header_icon = "doc-empty-inverse"
|
||||||
filterset_class = PageTypesUsageReportFilterSet
|
filterset_class = PageTypesUsageReportFilterSet
|
||||||
index_url_name = "wagtailadmin_reports:page_types_usage"
|
index_url_name = "wagtailadmin_reports:page_types_usage"
|
||||||
|
|
|
@ -140,7 +140,7 @@ class WorkflowTasksReportFilterSet(WagtailFilterSet):
|
||||||
|
|
||||||
class WorkflowView(ReportView):
|
class WorkflowView(ReportView):
|
||||||
results_template_name = "wagtailadmin/reports/workflow_results.html"
|
results_template_name = "wagtailadmin/reports/workflow_results.html"
|
||||||
title = _("Workflows")
|
page_title = _("Workflows")
|
||||||
header_icon = "tasks"
|
header_icon = "tasks"
|
||||||
filterset_class = WorkflowReportFilterSet
|
filterset_class = WorkflowReportFilterSet
|
||||||
index_url_name = "wagtailadmin_reports:workflow"
|
index_url_name = "wagtailadmin_reports:workflow"
|
||||||
|
@ -224,7 +224,7 @@ class WorkflowView(ReportView):
|
||||||
|
|
||||||
class WorkflowTasksView(ReportView):
|
class WorkflowTasksView(ReportView):
|
||||||
results_template_name = "wagtailadmin/reports/workflow_tasks_results.html"
|
results_template_name = "wagtailadmin/reports/workflow_tasks_results.html"
|
||||||
title = _("Workflow tasks")
|
page_title = _("Workflow tasks")
|
||||||
header_icon = "thumbtack"
|
header_icon = "thumbtack"
|
||||||
filterset_class = WorkflowTasksReportFilterSet
|
filterset_class = WorkflowTasksReportFilterSet
|
||||||
index_url_name = "wagtailadmin_reports:workflow_tasks"
|
index_url_name = "wagtailadmin_reports:workflow_tasks"
|
||||||
|
|
Ładowanie…
Reference in New Issue