From f40e71a957aa00b4572c19b269179cded6c8c500 Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Wed, 23 May 2018 12:02:37 -0300 Subject: [PATCH] Fixed #29417 -- Corrected two admin page titles for view-only users. --- .../admin/locale/en/LC_MESSAGES/django.po | 38 ++++++++++++------- django/contrib/admin/options.py | 8 +++- django/contrib/admin/views/main.py | 4 +- tests/admin_views/tests.py | 4 ++ 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/django/contrib/admin/locale/en/LC_MESSAGES/django.po b/django/contrib/admin/locale/en/LC_MESSAGES/django.po index 28cb897129..79f4c268f9 100644 --- a/django/contrib/admin/locale/en/LC_MESSAGES/django.po +++ b/django/contrib/admin/locale/en/LC_MESSAGES/django.po @@ -4,7 +4,7 @@ msgid "" msgstr "" "Project-Id-Version: Django\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-05-17 12:08+0200\n" +"POT-Creation-Date: 2018-05-21 14:16-0300\n" "PO-Revision-Date: 2010-05-13 15:35+0200\n" "Last-Translator: Django team\n" "Language-Team: English \n" @@ -19,12 +19,12 @@ msgstr "" msgid "Successfully deleted %(count)d %(items)s." msgstr "" -#: contrib/admin/actions.py:54 contrib/admin/options.py:1835 +#: contrib/admin/actions.py:54 contrib/admin/options.py:1841 #, python-format msgid "Cannot delete %(name)s" msgstr "" -#: contrib/admin/actions.py:56 contrib/admin/options.py:1837 +#: contrib/admin/actions.py:56 contrib/admin/options.py:1843 msgid "Are you sure?" msgstr "" @@ -185,7 +185,7 @@ msgstr "" msgid "Added." msgstr "" -#: contrib/admin/models.py:117 contrib/admin/options.py:2049 +#: contrib/admin/models.py:117 contrib/admin/options.py:2055 msgid "and" msgstr "" @@ -257,7 +257,7 @@ msgstr "" msgid "The {name} \"{obj}\" was changed successfully." msgstr "" -#: contrib/admin/options.py:1386 contrib/admin/options.py:1676 +#: contrib/admin/options.py:1386 contrib/admin/options.py:1682 msgid "" "Items must be selected in order to perform actions on them. No items have " "been changed." @@ -277,52 +277,57 @@ msgstr "" msgid "%(name)s with ID \"%(key)s\" doesn't exist. Perhaps it was deleted?" msgstr "" -#: contrib/admin/options.py:1597 +#: contrib/admin/options.py:1596 #, python-format msgid "Add %s" msgstr "" -#: contrib/admin/options.py:1597 +#: contrib/admin/options.py:1598 #, python-format msgid "Change %s" msgstr "" -#: contrib/admin/options.py:1652 +#: contrib/admin/options.py:1600 +#, python-format +msgid "View %s" +msgstr "" + +#: contrib/admin/options.py:1658 msgid "Database error" msgstr "" -#: contrib/admin/options.py:1724 +#: contrib/admin/options.py:1730 #, python-format msgid "%(count)s %(name)s was changed successfully." msgid_plural "%(count)s %(name)s were changed successfully." msgstr[0] "" msgstr[1] "" -#: contrib/admin/options.py:1755 +#: contrib/admin/options.py:1761 #, python-format msgid "%(total_count)s selected" msgid_plural "All %(total_count)s selected" msgstr[0] "" msgstr[1] "" -#: contrib/admin/options.py:1763 +#: contrib/admin/options.py:1769 #, python-format msgid "0 of %(cnt)s selected" msgstr "" -#: contrib/admin/options.py:1880 +#: contrib/admin/options.py:1886 #, python-format msgid "Change history: %s" msgstr "" #. Translators: Model verbose name and instance representation, #. suitable to be an item in a list. -#: contrib/admin/options.py:2043 +#: contrib/admin/options.py:2049 #, python-format msgid "%(class_name)s %(instance)s" msgstr "" -#: contrib/admin/options.py:2050 +#: contrib/admin/options.py:2056 #, python-format msgid "" "Deleting %(class_name)s %(instance)s would require deleting the following " @@ -869,6 +874,11 @@ msgstr "" msgid "Select %s to change" msgstr "" +#: contrib/admin/views/main.py:87 +#, python-format +msgid "Select %s to view" +msgstr "" + #: contrib/admin/widgets.py:101 msgid "Date:" msgstr "" diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index e78e99f9fb..5b7de20e2d 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1592,9 +1592,15 @@ class ModelAdmin(BaseModelAdmin): for inline_formset in inline_formsets: media = media + inline_formset.media + if add: + title = _('Add %s') + elif self.has_change_permission(request, obj): + title = _('Change %s') + else: + title = _('View %s') context = { **self.admin_site.each_context(request), - 'title': (_('Add %s') if add else _('Change %s')) % opts.verbose_name, + 'title': title % opts.verbose_name, 'adminform': adminForm, 'object_id': object_id, 'original': obj, diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index fa7b2a6036..cbbe45a5c7 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -81,8 +81,10 @@ class ChangeList: self.get_results(request) if self.is_popup: title = gettext('Select %s') - else: + elif self.model_admin.has_change_permission(request): title = gettext('Select %s to change') + else: + title = gettext('Select %s to view') self.title = title % self.opts.verbose_name self.pk_attname = self.lookup_opts.pk.attname diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index f7f247fd37..95fa487c5f 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -1764,8 +1764,10 @@ class AdminViewPermissionsTest(TestCase): self.client.force_login(self.viewuser) response = self.client.get(article_changelist_url) self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['title'], 'Select article to view') response = self.client.get(article_change_url) self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['title'], 'View article') self.assertContains(response, 'Close') post = self.client.post(article_change_url, change_dict) self.assertEqual(post.status_code, 302) @@ -1776,8 +1778,10 @@ class AdminViewPermissionsTest(TestCase): self.client.force_login(self.changeuser) response = self.client.get(article_changelist_url) self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['title'], 'Select article to change') response = self.client.get(article_change_url) self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['title'], 'Change article') post = self.client.post(article_change_url, change_dict) self.assertRedirects(post, article_changelist_url) self.assertEqual(Article.objects.get(pk=self.a1.pk).content, '

edited article

')