Fixed #29417 -- Corrected two admin page titles for view-only users.

This commit is contained in:
Ramiro Morales 2018-05-23 12:02:37 -03:00 committed by Tim Graham
parent 40ff93310f
commit f40e71a957
4 changed files with 38 additions and 16 deletions

View File

@ -4,7 +4,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Django\n" "Project-Id-Version: Django\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: 2010-05-13 15:35+0200\n"
"Last-Translator: Django team\n" "Last-Translator: Django team\n"
"Language-Team: English <en@li.org>\n" "Language-Team: English <en@li.org>\n"
@ -19,12 +19,12 @@ msgstr ""
msgid "Successfully deleted %(count)d %(items)s." msgid "Successfully deleted %(count)d %(items)s."
msgstr "" msgstr ""
#: contrib/admin/actions.py:54 contrib/admin/options.py:1835 #: contrib/admin/actions.py:54 contrib/admin/options.py:1841
#, python-format #, python-format
msgid "Cannot delete %(name)s" msgid "Cannot delete %(name)s"
msgstr "" 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?" msgid "Are you sure?"
msgstr "" msgstr ""
@ -185,7 +185,7 @@ msgstr ""
msgid "Added." msgid "Added."
msgstr "" msgstr ""
#: contrib/admin/models.py:117 contrib/admin/options.py:2049 #: contrib/admin/models.py:117 contrib/admin/options.py:2055
msgid "and" msgid "and"
msgstr "" msgstr ""
@ -257,7 +257,7 @@ msgstr ""
msgid "The {name} \"{obj}\" was changed successfully." msgid "The {name} \"{obj}\" was changed successfully."
msgstr "" msgstr ""
#: contrib/admin/options.py:1386 contrib/admin/options.py:1676 #: contrib/admin/options.py:1386 contrib/admin/options.py:1682
msgid "" msgid ""
"Items must be selected in order to perform actions on them. No items have " "Items must be selected in order to perform actions on them. No items have "
"been changed." "been changed."
@ -277,52 +277,57 @@ msgstr ""
msgid "%(name)s with ID \"%(key)s\" doesn't exist. Perhaps it was deleted?" msgid "%(name)s with ID \"%(key)s\" doesn't exist. Perhaps it was deleted?"
msgstr "" msgstr ""
#: contrib/admin/options.py:1597 #: contrib/admin/options.py:1596
#, python-format #, python-format
msgid "Add %s" msgid "Add %s"
msgstr "" msgstr ""
#: contrib/admin/options.py:1597 #: contrib/admin/options.py:1598
#, python-format #, python-format
msgid "Change %s" msgid "Change %s"
msgstr "" 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" msgid "Database error"
msgstr "" msgstr ""
#: contrib/admin/options.py:1724 #: contrib/admin/options.py:1730
#, python-format #, python-format
msgid "%(count)s %(name)s was changed successfully." msgid "%(count)s %(name)s was changed successfully."
msgid_plural "%(count)s %(name)s were changed successfully." msgid_plural "%(count)s %(name)s were changed successfully."
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: contrib/admin/options.py:1755 #: contrib/admin/options.py:1761
#, python-format #, python-format
msgid "%(total_count)s selected" msgid "%(total_count)s selected"
msgid_plural "All %(total_count)s selected" msgid_plural "All %(total_count)s selected"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
#: contrib/admin/options.py:1763 #: contrib/admin/options.py:1769
#, python-format #, python-format
msgid "0 of %(cnt)s selected" msgid "0 of %(cnt)s selected"
msgstr "" msgstr ""
#: contrib/admin/options.py:1880 #: contrib/admin/options.py:1886
#, python-format #, python-format
msgid "Change history: %s" msgid "Change history: %s"
msgstr "" msgstr ""
#. Translators: Model verbose name and instance representation, #. Translators: Model verbose name and instance representation,
#. suitable to be an item in a list. #. suitable to be an item in a list.
#: contrib/admin/options.py:2043 #: contrib/admin/options.py:2049
#, python-format #, python-format
msgid "%(class_name)s %(instance)s" msgid "%(class_name)s %(instance)s"
msgstr "" msgstr ""
#: contrib/admin/options.py:2050 #: contrib/admin/options.py:2056
#, python-format #, python-format
msgid "" msgid ""
"Deleting %(class_name)s %(instance)s would require deleting the following " "Deleting %(class_name)s %(instance)s would require deleting the following "
@ -869,6 +874,11 @@ msgstr ""
msgid "Select %s to change" msgid "Select %s to change"
msgstr "" msgstr ""
#: contrib/admin/views/main.py:87
#, python-format
msgid "Select %s to view"
msgstr ""
#: contrib/admin/widgets.py:101 #: contrib/admin/widgets.py:101
msgid "Date:" msgid "Date:"
msgstr "" msgstr ""

View File

@ -1592,9 +1592,15 @@ class ModelAdmin(BaseModelAdmin):
for inline_formset in inline_formsets: for inline_formset in inline_formsets:
media = media + inline_formset.media 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 = { context = {
**self.admin_site.each_context(request), **self.admin_site.each_context(request),
'title': (_('Add %s') if add else _('Change %s')) % opts.verbose_name, 'title': title % opts.verbose_name,
'adminform': adminForm, 'adminform': adminForm,
'object_id': object_id, 'object_id': object_id,
'original': obj, 'original': obj,

View File

@ -81,8 +81,10 @@ class ChangeList:
self.get_results(request) self.get_results(request)
if self.is_popup: if self.is_popup:
title = gettext('Select %s') title = gettext('Select %s')
else: elif self.model_admin.has_change_permission(request):
title = gettext('Select %s to change') title = gettext('Select %s to change')
else:
title = gettext('Select %s to view')
self.title = title % self.opts.verbose_name self.title = title % self.opts.verbose_name
self.pk_attname = self.lookup_opts.pk.attname self.pk_attname = self.lookup_opts.pk.attname

View File

@ -1764,8 +1764,10 @@ class AdminViewPermissionsTest(TestCase):
self.client.force_login(self.viewuser) self.client.force_login(self.viewuser)
response = self.client.get(article_changelist_url) response = self.client.get(article_changelist_url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['title'], 'Select article to view')
response = self.client.get(article_change_url) response = self.client.get(article_change_url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['title'], 'View article')
self.assertContains(response, '<a href="/test_admin/admin/admin_views/article/" class="closelink">Close</a>') self.assertContains(response, '<a href="/test_admin/admin/admin_views/article/" class="closelink">Close</a>')
post = self.client.post(article_change_url, change_dict) post = self.client.post(article_change_url, change_dict)
self.assertEqual(post.status_code, 302) self.assertEqual(post.status_code, 302)
@ -1776,8 +1778,10 @@ class AdminViewPermissionsTest(TestCase):
self.client.force_login(self.changeuser) self.client.force_login(self.changeuser)
response = self.client.get(article_changelist_url) response = self.client.get(article_changelist_url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['title'], 'Select article to change')
response = self.client.get(article_change_url) response = self.client.get(article_change_url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['title'], 'Change article')
post = self.client.post(article_change_url, change_dict) post = self.client.post(article_change_url, change_dict)
self.assertRedirects(post, article_changelist_url) self.assertRedirects(post, article_changelist_url)
self.assertEqual(Article.objects.get(pk=self.a1.pk).content, '<p>edited article</p>') self.assertEqual(Article.objects.get(pk=self.a1.pk).content, '<p>edited article</p>')