diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 4d23f8f..40f6e28 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
998 | 998 | 'title': _('Add %s') % force_unicode(opts.verbose_name), |
999 | 999 | 'adminform': adminForm, |
1000 | 1000 | 'is_popup': "_popup" in request.REQUEST, |
1001 | | 'show_delete': False, |
1002 | 1001 | 'media': media, |
1003 | 1002 | 'inline_admin_formsets': inline_admin_formsets, |
1004 | 1003 | 'errors': helpers.AdminErrorList(form, formsets), |
diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py
index e55b3bf..c190533 100644
a
|
b
|
def submit_row(context):
|
32 | 32 | 'onclick_attrib': (opts.get_ordered_objects() and change |
33 | 33 | and 'onclick="submitOrderForm();"' or ''), |
34 | 34 | 'show_delete_link': (not is_popup and context['has_delete_permission'] |
35 | | and (change or context['show_delete'])), |
| 35 | and change and context.get('show_delete', True)), |
36 | 36 | 'show_save_as_new': not is_popup and change and save_as, |
37 | 37 | 'show_save_and_add_another': context['has_add_permission'] and |
38 | 38 | not is_popup and (not save_as or context['add']), |
diff --git a/tests/regressiontests/admin_views/admin.py b/tests/regressiontests/admin_views/admin.py
index 01a19e6..6ec933f 100644
a
|
b
|
from .models import (Article, Chapter, Account, Media, Child, Parent, Picture,
|
27 | 27 | Album, Question, Answer, ComplexSortedPerson, PrePopulatedPostLargeSlug, |
28 | 28 | AdminOrderedField, AdminOrderedModelMethod, AdminOrderedAdminMethod, |
29 | 29 | AdminOrderedCallable, Report, Color2, UnorderedObject, MainPrepopulated, |
30 | | RelatedPrepopulated) |
| 30 | RelatedPrepopulated, UndeletableObject) |
31 | 31 | |
32 | 32 | |
33 | 33 | def callable_year(dt_value): |
… |
… |
class UnorderedObjectAdmin(admin.ModelAdmin):
|
569 | 569 | list_per_page = 2 |
570 | 570 | |
571 | 571 | |
| 572 | class UndeletableObjectAdmin(admin.ModelAdmin): |
| 573 | def change_view(self, *args, **kwargs): |
| 574 | kwargs['extra_context'] = {'show_delete': False} |
| 575 | return super(UndeletableObjectAdmin, self).change_view(*args, **kwargs) |
| 576 | |
572 | 577 | |
573 | 578 | site = admin.AdminSite(name="admin") |
574 | 579 | site.register(Article, ArticleAdmin) |
… |
… |
site.register(OtherStory, OtherStoryAdmin)
|
616 | 621 | site.register(Report, ReportAdmin) |
617 | 622 | site.register(MainPrepopulated, MainPrepopulatedAdmin) |
618 | 623 | site.register(UnorderedObject, UnorderedObjectAdmin) |
| 624 | site.register(UndeletableObject, UndeletableObjectAdmin) |
619 | 625 | |
620 | 626 | # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. |
621 | 627 | # That way we cover all four cases: |
diff --git a/tests/regressiontests/admin_views/customadmin.py b/tests/regressiontests/admin_views/customadmin.py
index d205e0e..142527b 100644
a
|
b
|
site.register(models.Thing, base_admin.ThingAdmin)
|
48 | 48 | site.register(models.Fabric, base_admin.FabricAdmin) |
49 | 49 | site.register(models.ChapterXtra1, base_admin.ChapterXtra1Admin) |
50 | 50 | site.register(User, UserLimitedAdmin) |
| 51 | site.register(models.UndeletableObject, base_admin.UndeletableObjectAdmin) |
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index ab2bc20..975d56a 100644
a
|
b
|
class UnorderedObject(models.Model):
|
611 | 611 | """ |
612 | 612 | name = models.CharField(max_length=255) |
613 | 613 | bool = models.BooleanField(default=True) |
| 614 | |
| 615 | class UndeletableObject(models.Model): |
| 616 | """ |
| 617 | Model whose show_delete in admin change_view has been disabled |
| 618 | """ |
| 619 | name = models.CharField(max_length=255) |
| 620 | |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 49ec3c1..f07697c 100644
a
|
b
|
from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
|
41 | 41 | FoodDelivery, RowLevelChangePermissionModel, Paper, CoverLetter, Story, |
42 | 42 | OtherStory, ComplexSortedPerson, Parent, Child, AdminOrderedField, |
43 | 43 | AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable, |
44 | | Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject) |
| 44 | Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject, |
| 45 | UndeletableObject) |
45 | 46 | |
46 | 47 | |
47 | 48 | ERROR_MESSAGE = "Please enter the correct username and password \ |
… |
… |
class AdminViewBasicTest(TestCase):
|
588 | 589 | self.assertFalse(reverse('admin:password_change') in response.content, |
589 | 590 | msg='The "change password" link should not be displayed if a user does not have a usable password.') |
590 | 591 | |
| 592 | def test_change_view_with_show_delete_extra_context(self): |
| 593 | """ |
| 594 | Tests if a "show_delete" context item supplied to admin's change_view |
| 595 | changes whether or not the delete button is displayed when rendering |
| 596 | the change form. |
| 597 | """ |
| 598 | instance = UndeletableObject.objects.create(name='foo') |
| 599 | response = self.client.get('/test_admin/%s/admin_views/undeletableobject/%d/' % |
| 600 | (self.urlbit, instance.pk)) |
| 601 | self.assertNotContains(response, 'deletelink') |
591 | 602 | |
592 | 603 | @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) |
593 | 604 | class AdminViewFormUrlTest(TestCase): |