Ticket #11700: 11700.diff

File 11700.diff, 4.3 KB (added by Simon Meers, 14 years ago)
  • django/contrib/admin/options.py

     
    3131class IncorrectLookupParameters(Exception):
    3232    pass
    3333
     34def changelist_request_is_popup(request):
     35    from django.contrib.admin.views.main import IS_POPUP_VAR
     36    return IS_POPUP_VAR in request.GET
     37
    3438# Defaults for formfield_overrides. ModelAdmin subclasses can change this
    3539# by adding to ModelAdmin.formfield_overrides.
    3640
     
    480484        if self.actions is None:
    481485            return []
    482486
     487        # Do not show actions in popups
     488        if changelist_request_is_popup(request):
     489            return []
     490
    483491        actions = []
    484492
    485493        # Gather actions from the admin site first
     
    962970            except ValueError:
    963971                pass
    964972
     973        # disallow list-editing in popups
     974        if changelist_request_is_popup(request):
     975            list_editable_for_request = ()
     976        else:
     977            list_editable_for_request = self.list_editable
     978
    965979        ChangeList = self.get_changelist(request)
    966980        try:
    967             cl = ChangeList(request, self.model, list_display, self.list_display_links, self.list_filter,
    968                 self.date_hierarchy, self.search_fields, self.list_select_related, self.list_per_page, self.list_editable, self)
     981            cl = ChangeList(request, self.model, list_display,
     982                            self.list_display_links, self.list_filter,
     983                            self.date_hierarchy, self.search_fields,
     984                            self.list_select_related, self.list_per_page,
     985                            list_editable_for_request, self)
    969986        except IncorrectLookupParameters:
    970987            # Wacky lookup parameters were given, so redirect to the main
    971988            # changelist page, without parameters, and pass an 'invalid=1'
     
    10161033        formset = cl.formset = None
    10171034
    10181035        # Handle POSTed bulk-edit data.
    1019         if (request.method == "POST" and self.list_editable and
     1036        if (request.method == "POST" and list_editable_for_request and
    10201037                '_save' in request.POST and not action_failed):
    10211038            FormSet = self.get_changelist_formset(request)
    10221039            formset = cl.formset = FormSet(request.POST, request.FILES, queryset=cl.result_list)
     
    10461063                return HttpResponseRedirect(request.get_full_path())
    10471064
    10481065        # Handle GET -- construct a formset for display.
    1049         elif self.list_editable:
     1066        elif list_editable_for_request:
    10501067            FormSet = self.get_changelist_formset(request)
    10511068            formset = cl.formset = FormSet(queryset=cl.result_list)
    10521069
  • tests/regressiontests/admin_views/tests.py

     
    13171317        self.failUnlessEqual(Person.objects.get(name="John Mauchly").alive, False)
    13181318        self.failUnlessEqual(Person.objects.get(name="Grace Hopper").gender, 2)
    13191319
     1320    def test_list_editable_popup(self):
     1321        """ Fields should not be list-editable in popups. """
     1322        response = self.client.get('/test_admin/admin/admin_views/person/')
     1323        self.assertNotEqual(response.context['cl'].list_editable, ())
     1324        response = self.client.get('/test_admin/admin/admin_views/person/?pop')
     1325        self.assertEqual(response.context['cl'].list_editable, ())
    13201326
    13211327
    1322 
    13231328class AdminSearchTest(TestCase):
    13241329    fixtures = ['admin-views-users','multiple-child-classes']
    13251330
     
    15551560        response = self.client.get('/test_admin/admin/admin_views/subscriber/')
    15561561        self.assertContains(response, '0 of 2 selected')
    15571562
     1563    def test_popup_actions(self):
     1564        """ Actions should not be shown in popups. """
     1565        response = self.client.get('/test_admin/admin/admin_views/subscriber/')
     1566        self.assertNotEquals(response.context["action_form"], None)
     1567        response = self.client.get(
     1568            '/test_admin/admin/admin_views/subscriber/?pop')
     1569        self.assertEquals(response.context["action_form"], None)
    15581570
     1571
    15591572class TestCustomChangeList(TestCase):
    15601573    fixtures = ['admin-views-users.xml']
    15611574    urlbit = 'admin'
Back to Top