Code

Ticket #20288: ticket_20288.diff

File ticket_20288.diff, 15.5 KB (added by tomask, 12 months ago)
Line 
1diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
2index b35f100..53b1d2c 100644
3--- a/django/contrib/admin/options.py
4+++ b/django/contrib/admin/options.py
5@@ -821,6 +821,7 @@ class ModelAdmin(BaseModelAdmin):
6         """
7         Determines the HttpResponse for the add_view stage.
8         """
9+        from django.contrib.admin.views.main import IS_POPUP_VAR
10         opts = obj._meta
11         pk_value = obj._get_pk_val()
12 
13@@ -835,11 +836,11 @@ class ModelAdmin(BaseModelAdmin):
14                                             (opts.app_label, opts.model_name),
15                                             args=(pk_value,),
16                                             current_app=self.admin_site.name)
17-            if "_popup" in request.POST:
18-                post_url_continue += "?_popup=1"
19+            if "_popup" in request.POST or IS_POPUP_VAR in request.POST:
20+                post_url_continue += "?%s=1" % IS_POPUP_VAR
21             return HttpResponseRedirect(post_url_continue)
22 
23-        if "_popup" in request.POST:
24+        if "_popup" in request.POST or IS_POPUP_VAR in request.POST:
25             return HttpResponse(
26                 '<!DOCTYPE html><html><head><title></title></head><body>'
27                 '<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script></body></html>' % \
28@@ -858,6 +859,7 @@ class ModelAdmin(BaseModelAdmin):
29         """
30         Determines the HttpResponse for the change_view stage.
31         """
32+        from django.contrib.admin.views.main import IS_POPUP_VAR
33         opts = self.model._meta
34 
35         pk_value = obj._get_pk_val()
36@@ -866,8 +868,8 @@ class ModelAdmin(BaseModelAdmin):
37         if "_continue" in request.POST:
38             msg = _('The %(name)s "%(obj)s" was changed successfully. You may edit it again below.') % msg_dict
39             self.message_user(request, msg, messages.SUCCESS)
40-            if "_popup" in request.REQUEST:
41-                return HttpResponseRedirect(request.path + "?_popup=1")
42+            if "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST:
43+                return HttpResponseRedirect(request.path + ("?%s=1" % IS_POPUP_VAR))
44             else:
45                 return HttpResponseRedirect(request.path)
46         elif "_saveasnew" in request.POST:
47@@ -1060,10 +1062,11 @@ class ModelAdmin(BaseModelAdmin):
48             inline_admin_formsets.append(inline_admin_formset)
49             media = media + inline_admin_formset.media
50 
51+        from django.contrib.admin.views.main import IS_POPUP_VAR
52         context = {
53             'title': _('Add %s') % force_text(opts.verbose_name),
54             'adminform': adminForm,
55-            'is_popup': "_popup" in request.REQUEST,
56+            'is_popup': "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST,
57             'media': media,
58             'inline_admin_formsets': inline_admin_formsets,
59             'errors': helpers.AdminErrorList(form, formsets),
60@@ -1150,12 +1153,13 @@ class ModelAdmin(BaseModelAdmin):
61             inline_admin_formsets.append(inline_admin_formset)
62             media = media + inline_admin_formset.media
63 
64+        from django.contrib.admin.views.main import IS_POPUP_VAR
65         context = {
66             'title': _('Change %s') % force_text(opts.verbose_name),
67             'adminform': adminForm,
68             'object_id': object_id,
69             'original': obj,
70-            'is_popup': "_popup" in request.REQUEST,
71+            'is_popup': "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST,
72             'media': media,
73             'inline_admin_formsets': inline_admin_formsets,
74             'errors': helpers.AdminErrorList(form, formsets),
75diff --git a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
76index ce54fa5..1334701 100644
77--- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
78+++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
79@@ -57,9 +57,9 @@ function showAddAnotherPopup(triggeringLink) {
80     name = id_to_windowname(name);
81     href = triggeringLink.href
82     if (href.indexOf('?') == -1) {
83-        href += '?_popup=1';
84+        href += '?pop=1';
85     } else {
86-        href  += '&_popup=1';
87+        href  += '&pop=1';
88     }
89     var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
90     win.focus();
91diff --git a/django/contrib/admin/templates/admin/auth/user/change_password.html b/django/contrib/admin/templates/admin/auth/user/change_password.html
92index 9d1b917..0fbfaf2 100644
93--- a/django/contrib/admin/templates/admin/auth/user/change_password.html
94+++ b/django/contrib/admin/templates/admin/auth/user/change_password.html
95@@ -1,6 +1,7 @@
96 {% extends "admin/base_site.html" %}
97 {% load i18n admin_static %}
98 {% load admin_urls %}
99+{% load admin_popup_var %}
100 
101 {% block extrahead %}{{ block.super }}
102 <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
103@@ -21,7 +22,7 @@
104 {% block content %}<div id="content-main">
105 <form action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
106 <div>
107-{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
108+{% if is_popup %}{% get_popup_var as popup_var %}<input type="hidden" name="{{ popup_var }}" value="1" />{% endif %}
109 {% if form.errors %}
110     <p class="errornote">
111     {% blocktrans count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
112diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html
113index daf3775..938254c 100644
114--- a/django/contrib/admin/templates/admin/change_form.html
115+++ b/django/contrib/admin/templates/admin/change_form.html
116@@ -1,6 +1,7 @@
117 {% extends "admin/base_site.html" %}
118 {% load i18n admin_static admin_modify %}
119 {% load admin_urls %}
120+{% load admin_popup_var %}
121 
122 {% block extrahead %}{{ block.super }}
123 <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
124@@ -37,7 +38,7 @@
125 {% endblock %}
126 <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
127 <div>
128-{% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
129+{% if is_popup %}{% get_popup_var as popup_var %}<input type="hidden" name="{{ popup_var }}" value="1" />{% endif %}
130 {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}
131 {% if errors %}
132     <p class="errornote">
133diff --git a/django/contrib/admin/templates/admin/change_list.html b/django/contrib/admin/templates/admin/change_list.html
134index c72b663..7fd43d4 100644
135--- a/django/contrib/admin/templates/admin/change_list.html
136+++ b/django/contrib/admin/templates/admin/change_list.html
137@@ -1,6 +1,7 @@
138 {% extends "admin/base_site.html" %}
139 {% load i18n admin_static admin_list %}
140 {% load admin_urls %}
141+{% load admin_popup_var %}
142 
143 {% block extrastyle %}
144   {{ block.super }}
145@@ -54,7 +55,7 @@
146         <ul class="object-tools">
147           {% block object-tools-items %}
148             <li>
149-              <a href="{% url cl.opts|admin_urlname:'add' %}{% if is_popup %}?_popup=1{% endif %}" class="addlink">
150+              <a href="{% url cl.opts|admin_urlname:'add' %}{% if is_popup %}?{% get_popup_var as popup_var %}{{ popup_var }}=1{% endif %}" class="addlink">
151                 {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
152               </a>
153             </li>
154diff --git a/django/contrib/admin/templates/admin/search_form.html b/django/contrib/admin/templates/admin/search_form.html
155index f5a9e7b..4a9b3f8 100644
156--- a/django/contrib/admin/templates/admin/search_form.html
157+++ b/django/contrib/admin/templates/admin/search_form.html
158@@ -1,4 +1,4 @@
159-{% load i18n admin_static %}
160+{% load i18n admin_static admin_popup_var %}
161 {% if cl.search_fields %}
162 <div id="toolbar"><form id="changelist-search" action="" method="get">
163 <div><!-- DIV needed for valid HTML -->
164@@ -6,7 +6,7 @@
165 <input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" />
166 <input type="submit" value="{% trans 'Search' %}" />
167 {% if show_result_count %}
168-    <span class="small quiet">{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} (<a href="?{% if cl.is_popup %}pop=1{% endif %}">{% blocktrans with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktrans %}</a>)</span>
169+<span class="small quiet">{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} (<a href="?{% if cl.is_popup %}{% get_popup_var as popup_var %}{{ popup_var }}=1{% endif %}">{% blocktrans with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktrans %}</a>)</span>
170 {% endif %}
171 {% for pair in cl.params.items %}
172     {% ifnotequal pair.0 search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endifnotequal %}
173diff --git a/django/contrib/admin/templatetags/admin_popup_var.py b/django/contrib/admin/templatetags/admin_popup_var.py
174index e69de29..6cad4b1 100644
175--- a/django/contrib/admin/templatetags/admin_popup_var.py
176+++ b/django/contrib/admin/templatetags/admin_popup_var.py
177@@ -0,0 +1,9 @@
178+from django import template
179+from django.contrib.admin.views.main import IS_POPUP_VAR
180+
181+register = template.Library()
182+
183+@register.assignment_tag
184+def get_popup_var():
185+    return IS_POPUP_VAR
186+
187diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
188index 409078f..5aff535 100644
189--- a/django/contrib/auth/admin.py
190+++ b/django/contrib/auth/admin.py
191@@ -138,12 +138,13 @@ class UserAdmin(admin.ModelAdmin):
192         fieldsets = [(None, {'fields': list(form.base_fields)})]
193         adminForm = admin.helpers.AdminForm(form, fieldsets, {})
194 
195+        from django.contrib.admin.views.main import IS_POPUP_VAR
196         context = {
197             'title': _('Change password: %s') % escape(user.get_username()),
198             'adminForm': adminForm,
199             'form_url': form_url,
200             'form': form,
201-            'is_popup': '_popup' in request.REQUEST,
202+            'is_popup': '_popup' in request.REQUEST or IS_POPUP_VAR in request.REQUEST,
203             'add': True,
204             'change': False,
205             'has_delete_permission': False,
206@@ -170,7 +171,9 @@ class UserAdmin(admin.ModelAdmin):
207         # button except in two scenarios:
208         # * The user has pressed the 'Save and add another' button
209         # * We are adding a user in a popup
210-        if '_addanother' not in request.POST and '_popup' not in request.POST:
211+        from django.contrib.admin.views.main import IS_POPUP_VAR
212+        if ('_addanother' not in request.POST and '_popup' not in request.POST and
213+            IS_POPUP_VAR not in request.POST):
214             request.POST['_continue'] = 1
215         return super(UserAdmin, self).response_add(request, obj,
216                                                    post_url_continue)
217diff --git a/tests/admin_custom_urls/tests.py b/tests/admin_custom_urls/tests.py
218index 31c9341..dc24355 100644
219--- a/tests/admin_custom_urls/tests.py
220+++ b/tests/admin_custom_urls/tests.py
221@@ -49,13 +49,25 @@ class AdminCustomUrlsTest(TestCase):
222         """
223         post_data = {
224             '_popup': '1',
225-            "name": 'Action added through a popup',
226+            "name": 'Action added through a _popup',
227             "description": "Description of added action",
228         }
229         response = self.client.post('/custom_urls/admin/admin_custom_urls/action/!add/', post_data)
230         self.assertEqual(response.status_code, 200)
231         self.assertContains(response, 'dismissAddAnotherPopup')
232-        self.assertContains(response, 'Action added through a popup')
233+        self.assertContains(response, 'Action added through a _popup')
234+
235+        from django.contrib.admin.views.main import IS_POPUP_VAR
236+        post_data = {
237+            IS_POPUP_VAR: '1',
238+            "name": 'Action added through a IS_POPUP_VAR',
239+            "description": "Another description of added action",
240+        }
241+        response = self.client.post('/custom_urls/admin/admin_custom_urls/action/!add/', post_data)
242+        self.assertEqual(response.status_code, 200)
243+        self.assertContains(response, 'dismissAddAnotherPopup')
244+        self.assertContains(response, 'Action added through a IS_POPUP_VAR')
245+
246 
247     def testAdminUrlsNoClash(self):
248         """
249diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
250index e0000ff..0246a3d 100644
251--- a/tests/admin_views/tests.py
252+++ b/tests/admin_views/tests.py
253@@ -159,6 +159,7 @@ class AdminViewBasicTest(TestCase):
254         """
255         Ensure http response from a popup is properly escaped.
256         """
257+        # _popup for backwards compatibility
258         post_data = {
259             '_popup': '1',
260             'title': 'title with a new\nline',
261@@ -171,6 +172,19 @@ class AdminViewBasicTest(TestCase):
262         self.assertContains(response, 'dismissAddAnotherPopup')
263         self.assertContains(response, 'title with a new\\u000Aline')
264 
265+        post_data = {
266+            IS_POPUP_VAR: '1',
267+            'title': 'title with a new\nline',
268+            'content': 'some content',
269+            'date_0': '2010-09-10',
270+            'date_1': '14:55:39',
271+        }
272+        response = self.client.post('/test_admin/%s/admin_views/article/add/' % self.urlbit, post_data)
273+        self.assertEqual(response.status_code, 200)
274+        self.assertContains(response, 'dismissAddAnotherPopup')
275+        self.assertContains(response, 'title with a new\\u000Aline')
276+
277+
278     # Post data for edit inline
279     inline_post_data = {
280         "name": "Test section",
281@@ -3572,10 +3586,18 @@ class UserAdminTest(TestCase):
282         self.assertEqual(response.status_code, 200)
283         self.assertContains(response, '/test_admin/admin/auth/user/add')
284         self.assertContains(response, 'class="add-another" id="add_id_owner" onclick="return showAddAnotherPopup(this);"')
285+        # _popup for backwards compatibility
286         response = self.client.get('/test_admin/admin/auth/user/add/?_popup=1')
287         self.assertEqual(response.status_code, 200)
288         self.assertNotContains(response, 'name="_continue"')
289         self.assertNotContains(response, 'name="_addanother"')
290+
291+        response = self.client.get('/test_admin/admin/auth/user/add/?%s=1' % IS_POPUP_VAR)
292+        self.assertEqual(response.status_code, 200)
293+        self.assertNotContains(response, 'name="_continue"')
294+        self.assertNotContains(response, 'name="_addanother"')
295+
296+        # _popup for backwards compatibility
297         data = {
298             'username': 'newuser',
299             'password1': 'newpassword',
300@@ -3587,6 +3609,18 @@ class UserAdminTest(TestCase):
301         self.assertEqual(response.status_code, 200)
302         self.assertContains(response, 'dismissAddAnotherPopup')
303 
304+        data = {
305+            'username': 'newuser2',
306+            'password1': 'newpassword',
307+            'password2': 'newpassword',
308+            IS_POPUP_VAR: '1',
309+            '_save': '1',
310+        }
311+        response = self.client.post('/test_admin/admin/auth/user/add/?%s=1' % IS_POPUP_VAR, data, follow=True)
312+        self.assertEqual(response.status_code, 200)
313+        self.assertContains(response, 'dismissAddAnotherPopup')
314+
315+
316     def test_save_add_another_button(self):
317         user_count = User.objects.count()
318         response = self.client.post('/test_admin/admin/auth/user/add/', {