Ticket #10057: 10057.diff

File 10057.diff, 5.6 KB (added by David Gouldin, 12 years ago)
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 4d23f8f..40f6e28 100644
    a b class ModelAdmin(BaseModelAdmin):  
    998998            'title': _('Add %s') % force_unicode(opts.verbose_name),
    999999            'adminform': adminForm,
    10001000            'is_popup': "_popup" in request.REQUEST,
    1001             'show_delete': False,
    10021001            'media': media,
    10031002            'inline_admin_formsets': inline_admin_formsets,
    10041003            'errors': helpers.AdminErrorList(form, formsets),
  • django/contrib/admin/templatetags/admin_modify.py

    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):  
    3232        'onclick_attrib': (opts.get_ordered_objects() and change
    3333                            and 'onclick="submitOrderForm();"' or ''),
    3434        '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)),
    3636        'show_save_as_new': not is_popup and change and save_as,
    3737        'show_save_and_add_another': context['has_add_permission'] and
    3838                            not is_popup and (not save_as or context['add']),
  • tests/regressiontests/admin_views/admin.py

    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,  
    2727    Album, Question, Answer, ComplexSortedPerson, PrePopulatedPostLargeSlug,
    2828    AdminOrderedField, AdminOrderedModelMethod, AdminOrderedAdminMethod,
    2929    AdminOrderedCallable, Report, Color2, UnorderedObject, MainPrepopulated,
    30     RelatedPrepopulated)
     30    RelatedPrepopulated, UndeletableObject)
    3131
    3232
    3333def callable_year(dt_value):
    class UnorderedObjectAdmin(admin.ModelAdmin):  
    569569    list_per_page = 2
    570570
    571571
     572class 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
    572577
    573578site = admin.AdminSite(name="admin")
    574579site.register(Article, ArticleAdmin)
    site.register(OtherStory, OtherStoryAdmin)  
    616621site.register(Report, ReportAdmin)
    617622site.register(MainPrepopulated, MainPrepopulatedAdmin)
    618623site.register(UnorderedObject, UnorderedObjectAdmin)
     624site.register(UndeletableObject, UndeletableObjectAdmin)
    619625
    620626# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    621627# That way we cover all four cases:
  • tests/regressiontests/admin_views/customadmin.py

    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)  
    4848site.register(models.Fabric, base_admin.FabricAdmin)
    4949site.register(models.ChapterXtra1, base_admin.ChapterXtra1Admin)
    5050site.register(User, UserLimitedAdmin)
     51site.register(models.UndeletableObject, base_admin.UndeletableObjectAdmin)
  • tests/regressiontests/admin_views/models.py

    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):  
    611611    """
    612612    name = models.CharField(max_length=255)
    613613    bool = models.BooleanField(default=True)
     614
     615class 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
  • tests/regressiontests/admin_views/tests.py

    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,  
    4141    FoodDelivery, RowLevelChangePermissionModel, Paper, CoverLetter, Story,
    4242    OtherStory, ComplexSortedPerson, Parent, Child, AdminOrderedField,
    4343    AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable,
    44     Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject)
     44    Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject,
     45    UndeletableObject)
    4546
    4647
    4748ERROR_MESSAGE = "Please enter the correct username and password \
    class AdminViewBasicTest(TestCase):  
    588589        self.assertFalse(reverse('admin:password_change') in response.content,
    589590            msg='The "change password" link should not be displayed if a user does not have a usable password.')
    590591
     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')
    591602
    592603@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
    593604class AdminViewFormUrlTest(TestCase):
Back to Top