From 38dcd6506f6bca6504fa2b19d858146cbbb6f4e4 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Tue, 21 May 2024 16:53:22 +0100 Subject: [PATCH] Use a separate results template for non-page reports This brings us one step closer to the generic BaseListingView and its template. Pagination is now rendered via the base listing_results.html template. Technically we can remove the {% if object_list %} since the check is already done outside of the results block in that base template. However, leave it out for now so Git correctly detects that the files are just renamed for now. Also, only do this for views that extend the base ReportView and base_report.html template for now. We'll do the same for PageReportView and base_page_report.html later, since the template for that one is a bit different (especially around which blocks are named listing vs results...) --- .../reports/base_page_report.html | 1 + .../wagtailadmin/reports/base_report.html | 4 +- .../reports/base_report_results.html | 1 + ...age.html => page_types_usage_results.html} | 8 +- ...history.html => site_history_results.html} | 8 +- .../wagtailadmin/reports/workflow.html | 72 ------------------ .../reports/workflow_results.html | 76 +++++++++++++++++++ .../wagtailadmin/reports/workflow_tasks.html | 54 ------------- .../reports/workflow_tasks_results.html | 58 ++++++++++++++ wagtail/admin/tests/test_reports_views.py | 6 +- wagtail/admin/views/reports/audit_logging.py | 2 +- wagtail/admin/views/reports/base.py | 1 + .../admin/views/reports/page_types_usage.py | 2 +- wagtail/admin/views/reports/workflows.py | 2 + 14 files changed, 157 insertions(+), 138 deletions(-) create mode 100644 wagtail/admin/templates/wagtailadmin/reports/base_report_results.html rename wagtail/admin/templates/wagtailadmin/reports/{page_types_usage.html => page_types_usage_results.html} (58%) rename wagtail/admin/templates/wagtailadmin/reports/{site_history.html => site_history_results.html} (92%) create mode 100644 wagtail/admin/templates/wagtailadmin/reports/workflow_results.html create mode 100644 wagtail/admin/templates/wagtailadmin/reports/workflow_tasks_results.html diff --git a/wagtail/admin/templates/wagtailadmin/reports/base_page_report.html b/wagtail/admin/templates/wagtailadmin/reports/base_page_report.html index 924a7d63ae..e68ab995f1 100644 --- a/wagtail/admin/templates/wagtailadmin/reports/base_page_report.html +++ b/wagtail/admin/templates/wagtailadmin/reports/base_page_report.html @@ -8,6 +8,7 @@ {% block listing %} {% include "wagtailadmin/reports/listing/_list_page_report.html" %} {% endblock %} + {% paginate pages base_url=request.path %} {% else %} {% block no_results %}

{% trans "No pages match this report's criteria." %}

diff --git a/wagtail/admin/templates/wagtailadmin/reports/base_report.html b/wagtail/admin/templates/wagtailadmin/reports/base_report.html index ecb697a84d..677bd2194f 100644 --- a/wagtail/admin/templates/wagtailadmin/reports/base_report.html +++ b/wagtail/admin/templates/wagtailadmin/reports/base_report.html @@ -16,10 +16,8 @@
{% block results %} + {% include view.results_template_name|default:"wagtailadmin/reports/base_report_results.html" %} {% endblock %} - {% if page_obj %} - {% paginate page_obj base_url=request.path %} - {% endif %}
{% if filters %} {% include "wagtailadmin/shared/filters.html" %} diff --git a/wagtail/admin/templates/wagtailadmin/reports/base_report_results.html b/wagtail/admin/templates/wagtailadmin/reports/base_report_results.html new file mode 100644 index 0000000000..e7d8f4d07d --- /dev/null +++ b/wagtail/admin/templates/wagtailadmin/reports/base_report_results.html @@ -0,0 +1 @@ +{% extends "wagtailadmin/generic/listing_results.html" %} diff --git a/wagtail/admin/templates/wagtailadmin/reports/page_types_usage.html b/wagtail/admin/templates/wagtailadmin/reports/page_types_usage_results.html similarity index 58% rename from wagtail/admin/templates/wagtailadmin/reports/page_types_usage.html rename to wagtail/admin/templates/wagtailadmin/reports/page_types_usage_results.html index 3c90196475..5469a8bfc3 100644 --- a/wagtail/admin/templates/wagtailadmin/reports/page_types_usage.html +++ b/wagtail/admin/templates/wagtailadmin/reports/page_types_usage_results.html @@ -1,10 +1,12 @@ -{% extends "wagtailadmin/reports/base_report.html" %} +{% extends "wagtailadmin/reports/base_report_results.html" %} {% load i18n wagtailadmin_tags %} {% block results %} {% if object_list %} {% include "wagtailadmin/reports/listing/_list_page_types_usage.html" with page_types=object_list %} - {% else %} -

{% trans "No page types found." %}

{% endif %} {% endblock %} + +{% block no_results_message %} +

{% trans "No page types found." %}

+{% endblock %} diff --git a/wagtail/admin/templates/wagtailadmin/reports/site_history.html b/wagtail/admin/templates/wagtailadmin/reports/site_history_results.html similarity index 92% rename from wagtail/admin/templates/wagtailadmin/reports/site_history.html rename to wagtail/admin/templates/wagtailadmin/reports/site_history_results.html index fe6b4c983c..c98d6c6f8d 100644 --- a/wagtail/admin/templates/wagtailadmin/reports/site_history.html +++ b/wagtail/admin/templates/wagtailadmin/reports/site_history_results.html @@ -1,4 +1,4 @@ -{% extends 'wagtailadmin/reports/base_report.html' %} +{% extends 'wagtailadmin/reports/base_report_results.html' %} {% load i18n wagtailadmin_tags %} {% block results %} @@ -47,7 +47,9 @@ {% endfor %} - {% else %} -

{% trans "No log entries found." %}

{% endif %} {% endblock %} + +{% block no_results_message %} +

{% trans "No log entries found." %}

+{% endblock %} diff --git a/wagtail/admin/templates/wagtailadmin/reports/workflow.html b/wagtail/admin/templates/wagtailadmin/reports/workflow.html index f552231ee3..aa7f009b09 100644 --- a/wagtail/admin/templates/wagtailadmin/reports/workflow.html +++ b/wagtail/admin/templates/wagtailadmin/reports/workflow.html @@ -7,75 +7,3 @@
{{ block.super }} {% endblock %} - -{% block results %} - {% if object_list %} - - - - - - - - - - - - - {% for workflow_state in object_list %} - - - - - - - - - {% endfor %} - -
- {% trans 'Workflow' %} - - {% trans 'Page/Snippet' %} - - {% trans 'Status' %} - - {% trans 'Tasks' %} - - {% trans 'Requested by' %} - - {% trans 'Started at' %} -
- {{ workflow_state.workflow }} - - - {% latest_str workflow_state.content_object %} - - {% i18n_enabled as show_locale_labels %} - {% if show_locale_labels and workflow_state.content_object.locale_id %} - {% locale_label_from_id workflow_state.content_object.locale_id as locale_label %} - {% status locale_label classname="w-status--label" %} - {% endif %} - - {% admin_url_name workflow_state.content_object 'workflow_history_detail' as workflow_history_detail_url_name %} - {% url workflow_history_detail_url_name workflow_state.content_object.pk|admin_urlquote workflow_state.pk as status_url %} - {% status workflow_state.get_status_display url=status_url classname="w-status--primary" %} - -

{{ workflow_name }}

- {% trans 'Incomplete task' as incomplete_title %} - {% for task in workflow_state.all_tasks_with_status %} - - {% if task.status == 'approved' %} - {% icon "success" title=task.status_display classname="initial" %} - {% elif task.status == 'rejected' %} - {% icon "error" title=task.status_display classname="initial" %} - {% else %} - {% icon "radio-empty" title=incomplete_title classname="initial" %} - {% endif %} - - {% endfor %} -
{{ workflow_state.requested_by|user_display_name }}{{ workflow_state.created_at }}
- {% else %} -

{% trans "No pages/snippets have been submitted for moderation yet" %}

- {% endif %} -{% endblock %} diff --git a/wagtail/admin/templates/wagtailadmin/reports/workflow_results.html b/wagtail/admin/templates/wagtailadmin/reports/workflow_results.html new file mode 100644 index 0000000000..9794b9f9ed --- /dev/null +++ b/wagtail/admin/templates/wagtailadmin/reports/workflow_results.html @@ -0,0 +1,76 @@ +{% extends 'wagtailadmin/reports/base_report_results.html' %} +{% load i18n wagtailadmin_tags %} + +{% block results %} + {% if object_list %} + + + + + + + + + + + + + {% for workflow_state in object_list %} + + + + + + + + + {% endfor %} + +
+ {% trans 'Workflow' %} + + {% trans 'Page/Snippet' %} + + {% trans 'Status' %} + + {% trans 'Tasks' %} + + {% trans 'Requested by' %} + + {% trans 'Started at' %} +
+ {{ workflow_state.workflow }} + + + {% latest_str workflow_state.content_object %} + + {% i18n_enabled as show_locale_labels %} + {% if show_locale_labels and workflow_state.content_object.locale_id %} + {% locale_label_from_id workflow_state.content_object.locale_id as locale_label %} + {% status locale_label classname="w-status--label" %} + {% endif %} + + {% admin_url_name workflow_state.content_object 'workflow_history_detail' as workflow_history_detail_url_name %} + {% url workflow_history_detail_url_name workflow_state.content_object.pk|admin_urlquote workflow_state.pk as status_url %} + {% status workflow_state.get_status_display url=status_url classname="w-status--primary" %} + +

{{ workflow_name }}

+ {% trans 'Incomplete task' as incomplete_title %} + {% for task in workflow_state.all_tasks_with_status %} + + {% if task.status == 'approved' %} + {% icon "success" title=task.status_display classname="initial" %} + {% elif task.status == 'rejected' %} + {% icon "error" title=task.status_display classname="initial" %} + {% else %} + {% icon "radio-empty" title=incomplete_title classname="initial" %} + {% endif %} + + {% endfor %} +
{{ workflow_state.requested_by|user_display_name }}{{ workflow_state.created_at }}
+ {% endif %} +{% endblock %} + +{% block no_results_message %} +

{% trans "No pages/snippets have been submitted for moderation yet" %}

+{% endblock %} diff --git a/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks.html b/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks.html index d12fac3f3a..5e1e75093e 100644 --- a/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks.html +++ b/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks.html @@ -7,57 +7,3 @@ {{ block.super }} {% endblock %} - -{% block results %} - {% if object_list %} - - - - - - - - - - - - {% for task_state in object_list %} - - - - - - - - {% endfor %} - -
- {% trans 'Task' %} - - {% trans 'Page/Snippet' %} - - {% trans 'Status' %} - - {% trans 'Started at' %} - - {% trans 'Completed at' %} -
- {{ task_state.task }} - - {% with task_state.workflow_state.content_object as object %} - - {% latest_str object %} - - {% i18n_enabled as show_locale_labels %} - {% if show_locale_labels and object.locale_id %} - {% locale_label_from_id object.locale_id as locale_label %} - {% status locale_label classname="w-status--label" %} - {% endif %} - {% endwith %} - - {% status task_state.get_status_display classname="w-status--primary" %} - {{ task_state.started_at }}{{ task_state.finished_at }}
- {% else %} -

{% trans "No pages/snippets have been submitted for moderation yet" %}

- {% endif %} -{% endblock %} diff --git a/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks_results.html b/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks_results.html new file mode 100644 index 0000000000..ccdf1ebd4e --- /dev/null +++ b/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks_results.html @@ -0,0 +1,58 @@ +{% extends 'wagtailadmin/reports/base_report_results.html' %} +{% load i18n wagtailadmin_tags %} + +{% block results %} + {% if object_list %} + + + + + + + + + + + + {% for task_state in object_list %} + + + + + + + + {% endfor %} + +
+ {% trans 'Task' %} + + {% trans 'Page/Snippet' %} + + {% trans 'Status' %} + + {% trans 'Started at' %} + + {% trans 'Completed at' %} +
+ {{ task_state.task }} + + {% with task_state.workflow_state.content_object as object %} + + {% latest_str object %} + + {% i18n_enabled as show_locale_labels %} + {% if show_locale_labels and object.locale_id %} + {% locale_label_from_id object.locale_id as locale_label %} + {% status locale_label classname="w-status--label" %} + {% endif %} + {% endwith %} + + {% status task_state.get_status_display classname="w-status--primary" %} + {{ task_state.started_at }}{{ task_state.finished_at }}
+ {% endif %} +{% endblock %} + +{% block no_results_message %} +

{% trans "No pages/snippets have been submitted for moderation yet" %}

+{% endblock %} diff --git a/wagtail/admin/tests/test_reports_views.py b/wagtail/admin/tests/test_reports_views.py index 3a72d20473..f48c27d34c 100644 --- a/wagtail/admin/tests/test_reports_views.py +++ b/wagtail/admin/tests/test_reports_views.py @@ -792,7 +792,11 @@ class PageTypesUsageReportViewTest(WagtailTestUtils, TestCase): def test_simple(self): response = self.get() self.assertEqual(response.status_code, 200) - self.assertTemplateUsed(response, "wagtailadmin/reports/page_types_usage.html") + self.assertTemplateUsed(response, "wagtailadmin/reports/base_report.html") + self.assertTemplateUsed( + response, + "wagtailadmin/reports/page_types_usage_results.html", + ) def test_displays_only_page_types(self): """Asserts that the correct models are included in the queryset.""" diff --git a/wagtail/admin/views/reports/audit_logging.py b/wagtail/admin/views/reports/audit_logging.py index 051f1b3c20..176664e8f1 100644 --- a/wagtail/admin/views/reports/audit_logging.py +++ b/wagtail/admin/views/reports/audit_logging.py @@ -104,7 +104,7 @@ class SiteHistoryReportFilterSet(WagtailFilterSet): class LogEntriesView(ReportView): - template_name = "wagtailadmin/reports/site_history.html" + results_template_name = "wagtailadmin/reports/site_history_results.html" title = _("Site history") header_icon = "history" filterset_class = SiteHistoryReportFilterSet diff --git a/wagtail/admin/views/reports/base.py b/wagtail/admin/views/reports/base.py index 00f8a519f6..32e872a98c 100644 --- a/wagtail/admin/views/reports/base.py +++ b/wagtail/admin/views/reports/base.py @@ -6,6 +6,7 @@ from wagtail.admin.views.mixins import SpreadsheetExportMixin class ReportView(SpreadsheetExportMixin, BaseListingView): template_name = "wagtailadmin/reports/base_report.html" + results_template_name = "wagtailadmin/reports/base_report_results.html" title = "" paginate_by = 50 diff --git a/wagtail/admin/views/reports/page_types_usage.py b/wagtail/admin/views/reports/page_types_usage.py index 4b789a2076..6816bed5a7 100644 --- a/wagtail/admin/views/reports/page_types_usage.py +++ b/wagtail/admin/views/reports/page_types_usage.py @@ -96,7 +96,7 @@ class PageTypesUsageReportFilterSet(WagtailFilterSet): class PageTypesUsageReportView(ReportView): - template_name = "wagtailadmin/reports/page_types_usage.html" + results_template_name = "wagtailadmin/reports/page_types_usage_results.html" title = _("Page types usage") header_icon = "doc-empty-inverse" filterset_class = PageTypesUsageReportFilterSet diff --git a/wagtail/admin/views/reports/workflows.py b/wagtail/admin/views/reports/workflows.py index 2319a20bc7..13445b359c 100644 --- a/wagtail/admin/views/reports/workflows.py +++ b/wagtail/admin/views/reports/workflows.py @@ -136,6 +136,7 @@ class WorkflowTasksReportFilterSet(WagtailFilterSet): class WorkflowView(ReportView): template_name = "wagtailadmin/reports/workflow.html" + results_template_name = "wagtailadmin/reports/workflow_results.html" title = _("Workflows") header_icon = "tasks" filterset_class = WorkflowReportFilterSet @@ -208,6 +209,7 @@ class WorkflowView(ReportView): class WorkflowTasksView(ReportView): template_name = "wagtailadmin/reports/workflow_tasks.html" + results_template_name = "wagtailadmin/reports/workflow_tasks_results.html" title = _("Workflow tasks") header_icon = "thumbtack" filterset_class = WorkflowTasksReportFilterSet