From 44f3731b1cd458f1fce0dbf87507805fce5fea4f Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Sun, 10 Jan 2021 16:50:44 +0000 Subject: [PATCH] Use .specific_deferred when calling .get_admin_display_title() --- wagtail/admin/forms/pages.py | 2 +- .../wagtailadmin/home/pages_for_moderation.html | 8 ++++---- .../home/user_pages_in_workflow_moderation.html | 4 ++-- .../home/workflow_pages_to_moderate.html | 4 ++-- .../page_privacy/ancestor_privacy.html | 2 +- .../admin/templates/wagtailadmin/pages/copy.html | 4 ++-- .../wagtailadmin/pages/listing/_list.html | 2 +- .../pages/move_choose_destination.html | 4 ++-- .../pages/workflow_history/detail.html | 2 +- .../pages/workflow_history/index.html | 4 ++-- .../templates/wagtailadmin/reports/workflow.html | 2 +- .../wagtailadmin/reports/workflow_tasks.html | 2 +- .../templates/wagtailadmin/workflows/usage.html | 4 ++-- wagtail/admin/views/pages/copy.py | 4 ++-- wagtail/admin/views/pages/moderation.py | 10 +++++----- wagtail/admin/views/pages/move.py | 3 ++- wagtail/admin/views/pages/usage.py | 2 +- wagtail/admin/views/reports.py | 2 +- wagtail/api/v2/serializers.py | 3 +++ wagtail/contrib/modeladmin/forms.py | 2 +- wagtail/core/models.py | 16 ++++++++-------- 21 files changed, 45 insertions(+), 41 deletions(-) diff --git a/wagtail/admin/forms/pages.py b/wagtail/admin/forms/pages.py index 6c1f747ffc..3cd12a291d 100644 --- a/wagtail/admin/forms/pages.py +++ b/wagtail/admin/forms/pages.py @@ -75,7 +75,7 @@ class CopyForm(forms.Form): # check if user is allowed to create a page at given location. if not parent_page.permissions_for_user(self.user).can_add_subpage(): self._errors['new_parent_page'] = self.error_class([ - _("You do not have permission to copy to page \"%(page_title)s\"") % {'page_title': parent_page.get_admin_display_title()} + _("You do not have permission to copy to page \"%(page_title)s\"") % {'page_title': parent_page.specific_deferred.get_admin_display_title()} ]) # Count the pages with the same slug within the context of our copy's parent page diff --git a/wagtail/admin/templates/wagtailadmin/home/pages_for_moderation.html b/wagtail/admin/templates/wagtailadmin/home/pages_for_moderation.html index 67c513cb26..23b5debff7 100644 --- a/wagtail/admin/templates/wagtailadmin/home/pages_for_moderation.html +++ b/wagtail/admin/templates/wagtailadmin/home/pages_for_moderation.html @@ -23,11 +23,11 @@
{% if page_perms.can_edit %} - {{ revision.page.get_admin_display_title }} + {{ revision.page.specific_deferred.get_admin_display_title }} {% elif revision.page.is_previewable %} - {{ revision.page.get_admin_display_title }} + {{ revision.page.specific_deferred.get_admin_display_title }} {% else %} - {{ revision.page.get_admin_display_title }} + {{ revision.page.specific_deferred.get_admin_display_title }} {% endif %} {% include "wagtailadmin/pages/listing/_privacy_indicator.html" with page=revision.page %} @@ -55,7 +55,7 @@ - {{ revision.page.get_parent.get_admin_display_title }} + {{ revision.page.get_parent.specific_deferred.get_admin_display_title }} {{ revision.page.content_type.model_class.get_verbose_name }} diff --git a/wagtail/admin/templates/wagtailadmin/home/user_pages_in_workflow_moderation.html b/wagtail/admin/templates/wagtailadmin/home/user_pages_in_workflow_moderation.html index fed4c0be1a..9c9c44305d 100644 --- a/wagtail/admin/templates/wagtailadmin/home/user_pages_in_workflow_moderation.html +++ b/wagtail/admin/templates/wagtailadmin/home/user_pages_in_workflow_moderation.html @@ -22,9 +22,9 @@
{% if page_perms.can_edit %} - {{ workflow_state.page.get_admin_display_title }} + {{ workflow_state.page.specific_deferred.get_admin_display_title }} {% else %} - {{ workflow_state.page.get_admin_display_title }} + {{ workflow_state.page.specific_deferred.get_admin_display_title }} {% endif %} {% include "wagtailadmin/pages/listing/_privacy_indicator.html" with page=workflow_state.page %} diff --git a/wagtail/admin/templates/wagtailadmin/home/workflow_pages_to_moderate.html b/wagtail/admin/templates/wagtailadmin/home/workflow_pages_to_moderate.html index 95dba55212..2be6103081 100644 --- a/wagtail/admin/templates/wagtailadmin/home/workflow_pages_to_moderate.html +++ b/wagtail/admin/templates/wagtailadmin/home/workflow_pages_to_moderate.html @@ -22,9 +22,9 @@
{% if page_perms.can_edit %} - {{ revision.page.get_admin_display_title }} + {{ revision.page.specific_deferred.get_admin_display_title }} {% else %} - {{ revision.page.get_admin_display_title }} + {{ revision.page.specific_deferred.get_admin_display_title }} {% endif %} {% include "wagtailadmin/pages/listing/_privacy_indicator.html" with page=revision.page %} diff --git a/wagtail/admin/templates/wagtailadmin/page_privacy/ancestor_privacy.html b/wagtail/admin/templates/wagtailadmin/page_privacy/ancestor_privacy.html index 2e49668fba..1035d31c6d 100644 --- a/wagtail/admin/templates/wagtailadmin/page_privacy/ancestor_privacy.html +++ b/wagtail/admin/templates/wagtailadmin/page_privacy/ancestor_privacy.html @@ -4,5 +4,5 @@

{% trans "This page has been made private by a parent page." %}

-

{% trans "You can edit the privacy settings on:" %} {{ page_with_restriction.get_admin_display_title }}

+

{% trans "You can edit the privacy settings on:" %} {{ page_with_restriction.specific_deferred.get_admin_display_title }}

diff --git a/wagtail/admin/templates/wagtailadmin/pages/copy.html b/wagtail/admin/templates/wagtailadmin/pages/copy.html index 05dbc8d975..3726161331 100644 --- a/wagtail/admin/templates/wagtailadmin/pages/copy.html +++ b/wagtail/admin/templates/wagtailadmin/pages/copy.html @@ -1,9 +1,9 @@ {% extends "wagtailadmin/base.html" %} {% load i18n %} -{% block titletag %}{% blocktrans with title=page.get_admin_display_title %}Copy {{ title }}{% endblocktrans %}{% endblock %} +{% block titletag %}{% blocktrans with title=page.specific_deferred.get_admin_display_title %}Copy {{ title }}{% endblocktrans %}{% endblock %} {% block content %} {% trans "Copy" as copy_str %} - {% include "wagtailadmin/shared/header.html" with title=copy_str subtitle=page.get_admin_display_title icon="doc-empty-inverse" %} + {% include "wagtailadmin/shared/header.html" with title=copy_str subtitle=page.specific_deferred.get_admin_display_title icon="doc-empty-inverse" %}
diff --git a/wagtail/admin/templates/wagtailadmin/pages/listing/_list.html b/wagtail/admin/templates/wagtailadmin/pages/listing/_list.html index fdd428c68c..95f76e12e4 100644 --- a/wagtail/admin/templates/wagtailadmin/pages/listing/_list.html +++ b/wagtail/admin/templates/wagtailadmin/pages/listing/_list.html @@ -59,7 +59,7 @@ {% block page_parent_page_title %} {% with page.get_parent as parent %} {% if parent %} - {{ parent.get_admin_display_title }} + {{ parent.specific_deferred.get_admin_display_title }} {% endif %} {% endwith %} {% endblock %} diff --git a/wagtail/admin/templates/wagtailadmin/pages/move_choose_destination.html b/wagtail/admin/templates/wagtailadmin/pages/move_choose_destination.html index b90d5b42b7..423b3b997c 100644 --- a/wagtail/admin/templates/wagtailadmin/pages/move_choose_destination.html +++ b/wagtail/admin/templates/wagtailadmin/pages/move_choose_destination.html @@ -1,11 +1,11 @@ {% extends "wagtailadmin/base.html" %} {% load i18n wagtailadmin_tags %} -{% block titletag %}{% blocktrans with title=page_to_move.get_admin_display_title %}Select a new parent page for {{ title }}{% endblocktrans %}{% endblock %} +{% block titletag %}{% blocktrans with title=page_to_move.specific_deferred.get_admin_display_title %}Select a new parent page for {{ title }}{% endblocktrans %}{% endblock %} {% block content %}

{% icon name="doc-empty-inverse" class_name="header-title-icon" %} - {% blocktrans with title=page_to_move.get_admin_display_title %}Select a new parent page for {{ title }}{% endblocktrans %} + {% blocktrans with title=page_to_move.specific_deferred.get_admin_display_title %}Select a new parent page for {{ title }}{% endblocktrans %}

diff --git a/wagtail/admin/templates/wagtailadmin/pages/workflow_history/detail.html b/wagtail/admin/templates/wagtailadmin/pages/workflow_history/detail.html index 28e53b6a66..cea91bf413 100644 --- a/wagtail/admin/templates/wagtailadmin/pages/workflow_history/detail.html +++ b/wagtail/admin/templates/wagtailadmin/pages/workflow_history/detail.html @@ -8,7 +8,7 @@ {% include "wagtailadmin/shared/header.html" with title=title_str %}
-

{% icon "doc-empty-inverse" class_name="initial" %} {{ page.get_admin_display_title }}

+

{% icon "doc-empty-inverse" class_name="initial" %} {{ page.specific_deferred.get_admin_display_title }}

{% trans "Edit / Review" %} {% trans "Workflow history" %} diff --git a/wagtail/admin/templates/wagtailadmin/pages/workflow_history/index.html b/wagtail/admin/templates/wagtailadmin/pages/workflow_history/index.html index eaf113e63b..24f029c20a 100644 --- a/wagtail/admin/templates/wagtailadmin/pages/workflow_history/index.html +++ b/wagtail/admin/templates/wagtailadmin/pages/workflow_history/index.html @@ -1,11 +1,11 @@ {% extends "wagtailadmin/base.html" %} {% load i18n %} -{% block titletag %}{% blocktrans with title=page.get_admin_display_title %}Workflow history for {{ title }}{% endblocktrans %}{% endblock %} +{% block titletag %}{% blocktrans with title=page.specific_deferred.get_admin_display_title %}Workflow history for {{ title }}{% endblocktrans %}{% endblock %} {% block content %} {% trans "Workflow history for" as workflow_history_str %} - {% include "wagtailadmin/shared/header.html" with title=workflow_history_str subtitle=page.get_admin_display_title icon="doc-empty-inverse" %} + {% include "wagtailadmin/shared/header.html" with title=workflow_history_str subtitle=page.specific_deferred.get_admin_display_title icon="doc-empty-inverse" %}

diff --git a/wagtail/admin/templates/wagtailadmin/reports/workflow.html b/wagtail/admin/templates/wagtailadmin/reports/workflow.html index f0c160f38a..2d772e65b8 100644 --- a/wagtail/admin/templates/wagtailadmin/reports/workflow.html +++ b/wagtail/admin/templates/wagtailadmin/reports/workflow.html @@ -41,7 +41,7 @@ - {{ workflow_state.page.get_admin_display_title }} + {{ workflow_state.page.specific_deferred.get_admin_display_title }} diff --git a/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks.html b/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks.html index fad2ed6226..fe38400607 100644 --- a/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks.html +++ b/wagtail/admin/templates/wagtailadmin/reports/workflow_tasks.html @@ -39,7 +39,7 @@ {% with task_state.workflow_state.page as page %} - {{ page.get_admin_display_title }} + {{ page.specific_deferred.get_admin_display_title }} {% endwith %} diff --git a/wagtail/admin/templates/wagtailadmin/workflows/usage.html b/wagtail/admin/templates/wagtailadmin/workflows/usage.html index 2bbd49f32d..bcabc00924 100644 --- a/wagtail/admin/templates/wagtailadmin/workflows/usage.html +++ b/wagtail/admin/templates/wagtailadmin/workflows/usage.html @@ -23,11 +23,11 @@ {% for page in used_by %} -

+ {% if page.get_parent %} - {{ page.get_parent.title }} + {{ page.get_parent.specific_deferred.get_admin_display_title }} {% endif %} diff --git a/wagtail/admin/views/pages/copy.py b/wagtail/admin/views/pages/copy.py index 13e3a52234..7924c588e1 100644 --- a/wagtail/admin/views/pages/copy.py +++ b/wagtail/admin/views/pages/copy.py @@ -76,10 +76,10 @@ def copy(request, page_id): if form.cleaned_data.get('copy_subpages'): messages.success( request, - _("Page '{0}' and {1} subpages copied.").format(page.get_admin_display_title(), new_page.get_descendants().count()) + _("Page '{0}' and {1} subpages copied.").format(page.specific_deferred.get_admin_display_title(), new_page.get_descendants().count()) ) else: - messages.success(request, _("Page '{0}' copied.").format(page.get_admin_display_title())) + messages.success(request, _("Page '{0}' copied.").format(page.specific_deferred.get_admin_display_title())) for fn in hooks.get_hooks('after_copy_page'): result = fn(request, page, new_page) diff --git a/wagtail/admin/views/pages/moderation.py b/wagtail/admin/views/pages/moderation.py index f54c3a70e4..81d4413065 100644 --- a/wagtail/admin/views/pages/moderation.py +++ b/wagtail/admin/views/pages/moderation.py @@ -15,13 +15,13 @@ def approve_moderation(request, revision_id): raise PermissionDenied if not revision.submitted_for_moderation: - messages.error(request, _("The page '{0}' is not currently awaiting moderation.").format(revision.page.get_admin_display_title())) + messages.error(request, _("The page '{0}' is not currently awaiting moderation.").format(revision.page.specific_deferred.get_admin_display_title())) return redirect('wagtailadmin_home') if request.method == 'POST': revision.approve_moderation(user=request.user) - message = _("Page '{0}' published.").format(revision.page.get_admin_display_title()) + message = _("Page '{0}' published.").format(revision.page.specific_deferred.get_admin_display_title()) buttons = [] if revision.page.url is not None: buttons.append(messages.button(revision.page.url, _('View live'), new_window=True)) @@ -40,13 +40,13 @@ def reject_moderation(request, revision_id): raise PermissionDenied if not revision.submitted_for_moderation: - messages.error(request, _("The page '{0}' is not currently awaiting moderation.").format(revision.page.get_admin_display_title())) + messages.error(request, _("The page '{0}' is not currently awaiting moderation.").format(revision.page.specific_deferred.get_admin_display_title())) return redirect('wagtailadmin_home') if request.method == 'POST': revision.reject_moderation(user=request.user) - messages.success(request, _("Page '{0}' rejected for publication.").format(revision.page.get_admin_display_title()), buttons=[ + messages.success(request, _("Page '{0}' rejected for publication.").format(revision.page.specific_deferred.get_admin_display_title()), buttons=[ messages.button(reverse('wagtailadmin_pages:edit', args=(revision.page.id,)), _('Edit')) ]) @@ -63,7 +63,7 @@ def preview_for_moderation(request, revision_id): raise PermissionDenied if not revision.submitted_for_moderation: - messages.error(request, _("The page '{0}' is not currently awaiting moderation.").format(revision.page.get_admin_display_title())) + messages.error(request, _("The page '{0}' is not currently awaiting moderation.").format(revision.page.specific_deferred.get_admin_display_title())) return redirect('wagtailadmin_home') page = revision.as_page_object() diff --git a/wagtail/admin/views/pages/move.py b/wagtail/admin/views/pages/move.py index 31843cd576..1a9e5eed9d 100644 --- a/wagtail/admin/views/pages/move.py +++ b/wagtail/admin/views/pages/move.py @@ -49,7 +49,8 @@ def move_choose_destination(request, page_to_move_id, viewed_page_id=None): def move_confirm(request, page_to_move_id, destination_id): page_to_move = get_object_or_404(Page, id=page_to_move_id).specific - destination = get_object_or_404(Page, id=destination_id) + # Needs .specific_deferred because the .get_admin_display_title method is called in template + destination = get_object_or_404(Page, id=destination_id).specific_deferred if not page_to_move.permissions_for_user(request.user).can_move_to(destination): raise PermissionDenied diff --git a/wagtail/admin/views/pages/usage.py b/wagtail/admin/views/pages/usage.py index 522ed7d8b9..19424804e0 100644 --- a/wagtail/admin/views/pages/usage.py +++ b/wagtail/admin/views/pages/usage.py @@ -18,7 +18,7 @@ def content_type_use(request, content_type_app_name, content_type_model_name): if not issubclass(page_class, Page): raise Http404 - pages = page_class.objects.all() + pages = page_class.objects.all().specific(defer=True) paginator = Paginator(pages, per_page=10) pages = paginator.get_page(request.GET.get('p')) diff --git a/wagtail/admin/views/reports.py b/wagtail/admin/views/reports.py index ae38aa46d1..464fc491ac 100644 --- a/wagtail/admin/views/reports.py +++ b/wagtail/admin/views/reports.py @@ -84,7 +84,7 @@ class LockedPagesView(PageReportView): pages = ( UserPagePermissionsProxy(self.request.user).editable_pages() | Page.objects.filter(locked_by=self.request.user) - ).filter(locked=True) + ).filter(locked=True).specific(defer=True) self.queryset = pages return super().get_queryset() diff --git a/wagtail/api/v2/serializers.py b/wagtail/api/v2/serializers.py index 360cb346ee..ebfa988ab5 100644 --- a/wagtail/api/v2/serializers.py +++ b/wagtail/api/v2/serializers.py @@ -292,6 +292,9 @@ class BaseSerializer(serializers.ModelSerializer): # Serialise core fields for field in fields: try: + if field.field_name == 'admin_display_title': + instance = instance.specific_deferred + attribute = field.get_attribute(instance) except SkipField: continue diff --git a/wagtail/contrib/modeladmin/forms.py b/wagtail/contrib/modeladmin/forms.py index 0ab147546f..f667c45421 100644 --- a/wagtail/contrib/modeladmin/forms.py +++ b/wagtail/contrib/modeladmin/forms.py @@ -8,7 +8,7 @@ from wagtail.core.models import Page class PageChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): bits = [] - for ancestor in obj.get_ancestors(inclusive=True).exclude(depth=1): + for ancestor in obj.get_ancestors(inclusive=True).exclude(depth=1).specific(defer=True): bits.append(ancestor.get_admin_display_title()) return mark_safe(''.join(bits)) diff --git a/wagtail/core/models.py b/wagtail/core/models.py index 79d868096f..eb3d00c4d6 100644 --- a/wagtail/core/models.py +++ b/wagtail/core/models.py @@ -2019,11 +2019,11 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase): data={ 'source': { 'id': parent_before.id, - 'title': parent_before.get_admin_display_title() + 'title': parent_before.specific_deferred.get_admin_display_title() }, 'destination': { 'id': parent_after.id, - 'title': parent_after.get_admin_display_title() + 'title': parent_after.specific_deferred.get_admin_display_title() } } ) @@ -2164,8 +2164,8 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase): 'id': page_copy.id, 'title': page_copy.get_admin_display_title() }, - 'source': {'id': parent.id, 'title': parent.get_admin_display_title()} if parent else None, - 'destination': {'id': to.id, 'title': to.get_admin_display_title()} if to else None, + 'source': {'id': parent.id, 'title': parent.specific_deferred.get_admin_display_title()} if parent else None, + 'destination': {'id': to.id, 'title': to.specific_deferred.get_admin_display_title()} if to else None, 'keep_live': page_copy.live and keep_live }, ) @@ -2306,8 +2306,8 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase): 'id': alias.id, 'title': alias.get_admin_display_title() }, - 'source': {'id': source_parent.id, 'title': source_parent.get_admin_display_title()} if source_parent else None, - 'destination': {'id': parent.id, 'title': parent.get_admin_display_title()} if parent else None, + 'source': {'id': source_parent.id, 'title': source_parent.specific_deferred.get_admin_display_title()} if source_parent else None, + 'destination': {'id': parent.id, 'title': parent.specific_deferred.get_admin_display_title()} if parent else None, }, ) if alias.live: @@ -4592,8 +4592,8 @@ class BaseLogEntryManager(models.Manager): data = kwargs.pop('data', '') title = kwargs.pop('title', None) if not title: - if hasattr(instance, 'get_admin_display_title'): - title = instance.get_admin_display_title() + if isinstance(instance, Page): + title = instance.specific_deferred.get_admin_display_title() else: title = str(instance)