Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #11700 -- Stopped admin actions and list_editable fields to sho…

…w up in popups. Thanks to Simon Meers for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15129 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7a89d3d503cad96689fee3028a218ff5456f73f1 1 parent be56f74
@jezdez jezdez authored
View
7 django/contrib/admin/options.py
@@ -535,7 +535,8 @@ def get_actions(self, request):
"""
# If self.actions is explicitally set to None that means that we don't
# want *any* actions enabled on this page.
- if self.actions is None:
+ from django.contrib.admin.views.main import IS_POPUP_VAR
+ if self.actions is None or IS_POPUP_VAR in request.GET:
return []
actions = []
@@ -1081,7 +1082,7 @@ def changelist_view(self, request, extra_context=None):
formset = cl.formset = None
# Handle POSTed bulk-edit data.
- if (request.method == "POST" and self.list_editable and
+ if (request.method == "POST" and cl.list_editable and
'_save' in request.POST and not action_failed):
FormSet = self.get_changelist_formset(request)
formset = cl.formset = FormSet(request.POST, request.FILES, queryset=cl.result_list)
@@ -1111,7 +1112,7 @@ def changelist_view(self, request, extra_context=None):
return HttpResponseRedirect(request.get_full_path())
# Handle GET -- construct a formset for display.
- elif self.list_editable:
+ elif cl.list_editable:
FormSet = self.get_changelist_formset(request)
formset = cl.formset = FormSet(queryset=cl.result_list)
View
5 django/contrib/admin/views/main.py
@@ -39,7 +39,6 @@ def __init__(self, request, model, list_display, list_display_links, list_filter
self.search_fields = search_fields
self.list_select_related = list_select_related
self.list_per_page = list_per_page
- self.list_editable = list_editable
self.model_admin = model_admin
# Get search parameters from the query string.
@@ -58,6 +57,10 @@ def __init__(self, request, model, list_display, list_display_links, list_filter
if ERROR_FLAG in self.params:
del self.params[ERROR_FLAG]
+ if self.is_popup:
+ self.list_editable = ()
+ else:
+ self.list_editable = list_editable
self.order_field, self.order_type = self.get_ordering()
self.query = request.GET.get(SEARCH_VAR, '')
self.query_set = self.get_query_set()
View
18 tests/regressiontests/admin_views/tests.py
@@ -16,6 +16,7 @@
from django.contrib.admin.sites import LOGIN_FORM_KEY
from django.contrib.admin.util import quote
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
+from django.contrib.admin.views.main import IS_POPUP_VAR
from django.forms.util import ErrorList
import django.template.context
from django.test import TestCase
@@ -1450,7 +1451,14 @@ def test_list_editable_action_choices(self):
self.assertEqual(Person.objects.get(name="John Mauchly").alive, False)
self.assertEqual(Person.objects.get(name="Grace Hopper").gender, 2)
-
+ def test_list_editable_popup(self):
+ """
+ Fields should not be list-editable in popups.
+ """
+ response = self.client.get('/test_admin/admin/admin_views/person/')
+ self.assertNotEqual(response.context['cl'].list_editable, ())
+ response = self.client.get('/test_admin/admin/admin_views/person/?%s' % IS_POPUP_VAR)
+ self.assertEqual(response.context['cl'].list_editable, ())
class AdminSearchTest(TestCase):
@@ -1701,6 +1709,14 @@ def test_selection_counter(self):
response = self.client.get('/test_admin/admin/admin_views/subscriber/')
self.assertContains(response, '0 of 2 selected')
+ def test_popup_actions(self):
+ """ Actions should not be shown in popups. """
+ response = self.client.get('/test_admin/admin/admin_views/subscriber/')
+ self.assertNotEquals(response.context["action_form"], None)
+ response = self.client.get(
+ '/test_admin/admin/admin_views/subscriber/?%s' % IS_POPUP_VAR)
+ self.assertEquals(response.context["action_form"], None)
+
class TestCustomChangeList(TestCase):
fixtures = ['admin-views-users.xml']
Please sign in to comment.
Something went wrong with that request. Please try again.