Use .specific_deferred when calling .get_admin_display_title()

pull/6676/head
Karl Hobley 2021-01-10 16:50:44 +00:00 zatwierdzone przez Matt Westcott
rodzic c0c7f1bd5d
commit 44f3731b1c
21 zmienionych plików z 45 dodań i 41 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -23,11 +23,11 @@
<td class="title" valign="top">
<div class="title-wrapper">
{% if page_perms.can_edit %}
<a href="{% url 'wagtailadmin_pages:edit' revision.page.id %}" title="{% trans 'Edit this page' %}">{{ revision.page.get_admin_display_title }}</a>
<a href="{% url 'wagtailadmin_pages:edit' revision.page.id %}" title="{% trans 'Edit this page' %}">{{ revision.page.specific_deferred.get_admin_display_title }}</a>
{% elif revision.page.is_previewable %}
<a href="{% url 'wagtailadmin_pages:preview_for_moderation' revision.id %}" title="{% trans 'Preview this page' %}">{{ revision.page.get_admin_display_title }}</a>
<a href="{% url 'wagtailadmin_pages:preview_for_moderation' revision.id %}" title="{% trans 'Preview this page' %}">{{ revision.page.specific_deferred.get_admin_display_title }}</a>
{% 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 @@
</ul>
</td>
<td valign="top">
<a href="{% url 'wagtailadmin_explore' revision.page.get_parent.id %}">{{ revision.page.get_parent.get_admin_display_title }}</a>
<a href="{% url 'wagtailadmin_explore' revision.page.get_parent.id %}">{{ revision.page.get_parent.specific_deferred.get_admin_display_title }}</a>
</td>
<td class="type" valign="top">
{{ revision.page.content_type.model_class.get_verbose_name }}

Wyświetl plik

@ -22,9 +22,9 @@
<td class="title" valign="top">
<div class="title-wrapper">
{% if page_perms.can_edit %}
<a href="{% url 'wagtailadmin_pages:edit' workflow_state.page.id %}" title="{% trans 'Edit this page' %}">{{ workflow_state.page.get_admin_display_title }}</a>
<a href="{% url 'wagtailadmin_pages:edit' workflow_state.page.id %}" title="{% trans 'Edit this page' %}">{{ workflow_state.page.specific_deferred.get_admin_display_title }}</a>
{% 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 %}

Wyświetl plik

@ -22,9 +22,9 @@
<td class="title" valign="top">
<div class="title-wrapper">
{% if page_perms.can_edit %}
<a href="{% url 'wagtailadmin_pages:edit' revision.page.id %}" title="{% trans 'Edit this page' %}">{{ revision.page.get_admin_display_title }}</a>
<a href="{% url 'wagtailadmin_pages:edit' revision.page.id %}" title="{% trans 'Edit this page' %}">{{ revision.page.specific_deferred.get_admin_display_title }}</a>
{% 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 %}

Wyświetl plik

@ -4,5 +4,5 @@
<div class="nice-padding">
<p>{% trans "This page has been made private by a parent page." %}</p>
<p>{% trans "You can edit the privacy settings on:" %} <a href="{% url 'wagtailadmin_pages:edit' page_with_restriction.id %}">{{ page_with_restriction.get_admin_display_title }}</a></p>
<p>{% trans "You can edit the privacy settings on:" %} <a href="{% url 'wagtailadmin_pages:edit' page_with_restriction.id %}">{{ page_with_restriction.specific_deferred.get_admin_display_title }}</a></p>
</div>

Wyświetl plik

@ -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" %}
<div class="nice-padding">
<form action="{% url 'wagtailadmin_pages:copy' page.id %}" method="POST" novalidate>

Wyświetl plik

@ -59,7 +59,7 @@
{% block page_parent_page_title %}
{% with page.get_parent as parent %}
{% if parent %}
<a href="{% url 'wagtailadmin_explore' parent.id %}">{{ parent.get_admin_display_title }}</a>
<a href="{% url 'wagtailadmin_explore' parent.id %}">{{ parent.specific_deferred.get_admin_display_title }}</a>
{% endif %}
{% endwith %}
{% endblock %}

Wyświetl plik

@ -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 %}
<header class="nice-padding">
<h1>
{% 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 <span>{{ title }}</span>{% endblocktrans %}
{% blocktrans with title=page_to_move.specific_deferred.get_admin_display_title %}Select a new parent page for <span>{{ title }}</span>{% endblocktrans %}
</h1>
</header>

Wyświetl plik

@ -8,7 +8,7 @@
{% include "wagtailadmin/shared/header.html" with title=title_str %}
<div class="nice-padding">
<h2>{% icon "doc-empty-inverse" class_name="initial" %} {{ page.get_admin_display_title }}</h2>
<h2>{% icon "doc-empty-inverse" class_name="initial" %} {{ page.specific_deferred.get_admin_display_title }}</h2>
<p>
<a href="{% url 'wagtailadmin_pages:edit' page.id %}" class="button button-small button-secondary">{% trans "Edit / Review" %}</a>
<a href="{% url 'wagtailadmin_pages:workflow_history' page.id %}" class="button button-small button-secondary">{% trans "Workflow history" %}</a>

Wyświetl plik

@ -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" %}
<div class="nice-padding">
<p style="margin-bottom: 30px;">

Wyświetl plik

@ -41,7 +41,7 @@
</td>
<td>
<a href="{% url 'wagtailadmin_pages:edit' workflow_state.page.id %}">
{{ workflow_state.page.get_admin_display_title }}
{{ workflow_state.page.specific_deferred.get_admin_display_title }}
</a>
</td>
<td>

Wyświetl plik

@ -39,7 +39,7 @@
<td>
{% with task_state.workflow_state.page as page %}
<a href="{% url 'wagtailadmin_pages:edit' page.id %}">
{{ page.get_admin_display_title }}
{{ page.specific_deferred.get_admin_display_title }}
</a>
{% endwith %}
</td>

Wyświetl plik

@ -23,11 +23,11 @@
{% for page in used_by %}
<tr>
<td class="title" valign="top">
<div class="title-wrapper"><a href="{% url 'wagtailadmin_pages:edit' page.id %}" title="{% trans 'Edit this page' %}">{{ page.title }}</a></div>
<div class="title-wrapper"><a href="{% url 'wagtailadmin_pages:edit' page.id %}" title="{% trans 'Edit this page' %}">{{ page.get_admin_display_title }}</a></div>
</td>
<td>
{% if page.get_parent %}
<a href="{% url 'wagtailadmin_explore' page.get_parent.id %}">{{ page.get_parent.title }}</a>
<a href="{% url 'wagtailadmin_explore' page.get_parent.id %}">{{ page.get_parent.specific_deferred.get_admin_display_title }}</a>
{% endif %}
</td>
<td>

Wyświetl plik

@ -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)

Wyświetl plik

@ -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()

Wyświetl plik

@ -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

Wyświetl plik

@ -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'))

Wyświetl plik

@ -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()

Wyświetl plik

@ -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

Wyświetl plik

@ -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('<span class="icon icon-arrow-right"></span>'.join(bits))

Wyświetl plik

@ -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)