diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index b35f100..53b1d2c 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
821 | 821 | """ |
822 | 822 | Determines the HttpResponse for the add_view stage. |
823 | 823 | """ |
| 824 | from django.contrib.admin.views.main import IS_POPUP_VAR |
824 | 825 | opts = obj._meta |
825 | 826 | pk_value = obj._get_pk_val() |
826 | 827 | |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
835 | 836 | (opts.app_label, opts.model_name), |
836 | 837 | args=(pk_value,), |
837 | 838 | current_app=self.admin_site.name) |
838 | | if "_popup" in request.POST: |
839 | | post_url_continue += "?_popup=1" |
| 839 | if "_popup" in request.POST or IS_POPUP_VAR in request.POST: |
| 840 | post_url_continue += "?%s=1" % IS_POPUP_VAR |
840 | 841 | return HttpResponseRedirect(post_url_continue) |
841 | 842 | |
842 | | if "_popup" in request.POST: |
| 843 | if "_popup" in request.POST or IS_POPUP_VAR in request.POST: |
843 | 844 | return HttpResponse( |
844 | 845 | '<!DOCTYPE html><html><head><title></title></head><body>' |
845 | 846 | '<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script></body></html>' % \ |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
858 | 859 | """ |
859 | 860 | Determines the HttpResponse for the change_view stage. |
860 | 861 | """ |
| 862 | from django.contrib.admin.views.main import IS_POPUP_VAR |
861 | 863 | opts = self.model._meta |
862 | 864 | |
863 | 865 | pk_value = obj._get_pk_val() |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
866 | 868 | if "_continue" in request.POST: |
867 | 869 | msg = _('The %(name)s "%(obj)s" was changed successfully. You may edit it again below.') % msg_dict |
868 | 870 | self.message_user(request, msg, messages.SUCCESS) |
869 | | if "_popup" in request.REQUEST: |
870 | | return HttpResponseRedirect(request.path + "?_popup=1") |
| 871 | if "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST: |
| 872 | return HttpResponseRedirect(request.path + ("?%s=1" % IS_POPUP_VAR)) |
871 | 873 | else: |
872 | 874 | return HttpResponseRedirect(request.path) |
873 | 875 | elif "_saveasnew" in request.POST: |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1060 | 1062 | inline_admin_formsets.append(inline_admin_formset) |
1061 | 1063 | media = media + inline_admin_formset.media |
1062 | 1064 | |
| 1065 | from django.contrib.admin.views.main import IS_POPUP_VAR |
1063 | 1066 | context = { |
1064 | 1067 | 'title': _('Add %s') % force_text(opts.verbose_name), |
1065 | 1068 | 'adminform': adminForm, |
1066 | | 'is_popup': "_popup" in request.REQUEST, |
| 1069 | 'is_popup': "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST, |
1067 | 1070 | 'media': media, |
1068 | 1071 | 'inline_admin_formsets': inline_admin_formsets, |
1069 | 1072 | 'errors': helpers.AdminErrorList(form, formsets), |
… |
… |
class ModelAdmin(BaseModelAdmin):
|
1150 | 1153 | inline_admin_formsets.append(inline_admin_formset) |
1151 | 1154 | media = media + inline_admin_formset.media |
1152 | 1155 | |
| 1156 | from django.contrib.admin.views.main import IS_POPUP_VAR |
1153 | 1157 | context = { |
1154 | 1158 | 'title': _('Change %s') % force_text(opts.verbose_name), |
1155 | 1159 | 'adminform': adminForm, |
1156 | 1160 | 'object_id': object_id, |
1157 | 1161 | 'original': obj, |
1158 | | 'is_popup': "_popup" in request.REQUEST, |
| 1162 | 'is_popup': "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST, |
1159 | 1163 | 'media': media, |
1160 | 1164 | 'inline_admin_formsets': inline_admin_formsets, |
1161 | 1165 | 'errors': helpers.AdminErrorList(form, formsets), |
diff --git a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
index ce54fa5..1334701 100644
a
|
b
|
function showAddAnotherPopup(triggeringLink) {
|
57 | 57 | name = id_to_windowname(name); |
58 | 58 | href = triggeringLink.href |
59 | 59 | if (href.indexOf('?') == -1) { |
60 | | href += '?_popup=1'; |
| 60 | href += '?pop=1'; |
61 | 61 | } else { |
62 | | href += '&_popup=1'; |
| 62 | href += '&pop=1'; |
63 | 63 | } |
64 | 64 | var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes'); |
65 | 65 | win.focus(); |
diff --git a/django/contrib/admin/templates/admin/auth/user/change_password.html b/django/contrib/admin/templates/admin/auth/user/change_password.html
index 9d1b917..0fbfaf2 100644
a
|
b
|
|
1 | 1 | {% extends "admin/base_site.html" %} |
2 | 2 | {% load i18n admin_static %} |
3 | 3 | {% load admin_urls %} |
| 4 | {% load admin_popup_var %} |
4 | 5 | |
5 | 6 | {% block extrahead %}{{ block.super }} |
6 | 7 | <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script> |
… |
… |
|
21 | 22 | {% block content %}<div id="content-main"> |
22 | 23 | <form action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %} |
23 | 24 | <div> |
24 | | {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %} |
| 25 | {% if is_popup %}{% get_popup_var as popup_var %}<input type="hidden" name="{{ popup_var }}" value="1" />{% endif %} |
25 | 26 | {% if form.errors %} |
26 | 27 | <p class="errornote"> |
27 | 28 | {% blocktrans count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} |
diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html
index daf3775..938254c 100644
a
|
b
|
|
1 | 1 | {% extends "admin/base_site.html" %} |
2 | 2 | {% load i18n admin_static admin_modify %} |
3 | 3 | {% load admin_urls %} |
| 4 | {% load admin_popup_var %} |
4 | 5 | |
5 | 6 | {% block extrahead %}{{ block.super }} |
6 | 7 | <script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script> |
… |
… |
|
37 | 38 | {% endblock %} |
38 | 39 | <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 %} |
39 | 40 | <div> |
40 | | {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %} |
| 41 | {% if is_popup %}{% get_popup_var as popup_var %}<input type="hidden" name="{{ popup_var }}" value="1" />{% endif %} |
41 | 42 | {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %} |
42 | 43 | {% if errors %} |
43 | 44 | <p class="errornote"> |
diff --git a/django/contrib/admin/templates/admin/change_list.html b/django/contrib/admin/templates/admin/change_list.html
index c72b663..7fd43d4 100644
a
|
b
|
|
1 | 1 | {% extends "admin/base_site.html" %} |
2 | 2 | {% load i18n admin_static admin_list %} |
3 | 3 | {% load admin_urls %} |
| 4 | {% load admin_popup_var %} |
4 | 5 | |
5 | 6 | {% block extrastyle %} |
6 | 7 | {{ block.super }} |
… |
… |
|
54 | 55 | <ul class="object-tools"> |
55 | 56 | {% block object-tools-items %} |
56 | 57 | <li> |
57 | | <a href="{% url cl.opts|admin_urlname:'add' %}{% if is_popup %}?_popup=1{% endif %}" class="addlink"> |
| 58 | <a href="{% url cl.opts|admin_urlname:'add' %}{% if is_popup %}?{% get_popup_var as popup_var %}{{ popup_var }}=1{% endif %}" class="addlink"> |
58 | 59 | {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %} |
59 | 60 | </a> |
60 | 61 | </li> |
diff --git a/django/contrib/admin/templates/admin/search_form.html b/django/contrib/admin/templates/admin/search_form.html
index f5a9e7b..4a9b3f8 100644
a
|
b
|
|
1 | | {% load i18n admin_static %} |
| 1 | {% load i18n admin_static admin_popup_var %} |
2 | 2 | {% if cl.search_fields %} |
3 | 3 | <div id="toolbar"><form id="changelist-search" action="" method="get"> |
4 | 4 | <div><!-- DIV needed for valid HTML --> |
… |
… |
|
6 | 6 | <input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" /> |
7 | 7 | <input type="submit" value="{% trans 'Search' %}" /> |
8 | 8 | {% if show_result_count %} |
9 | | <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> |
| 9 | <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> |
10 | 10 | {% endif %} |
11 | 11 | {% for pair in cl.params.items %} |
12 | 12 | {% ifnotequal pair.0 search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endifnotequal %} |
diff --git a/django/contrib/admin/templatetags/admin_popup_var.py b/django/contrib/admin/templatetags/admin_popup_var.py
index e69de29..6cad4b1 100644
a
|
b
|
|
| 1 | from django import template |
| 2 | from django.contrib.admin.views.main import IS_POPUP_VAR |
| 3 | |
| 4 | register = template.Library() |
| 5 | |
| 6 | @register.assignment_tag |
| 7 | def get_popup_var(): |
| 8 | return IS_POPUP_VAR |
| 9 | |
diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
index 409078f..5aff535 100644
a
|
b
|
class UserAdmin(admin.ModelAdmin):
|
138 | 138 | fieldsets = [(None, {'fields': list(form.base_fields)})] |
139 | 139 | adminForm = admin.helpers.AdminForm(form, fieldsets, {}) |
140 | 140 | |
| 141 | from django.contrib.admin.views.main import IS_POPUP_VAR |
141 | 142 | context = { |
142 | 143 | 'title': _('Change password: %s') % escape(user.get_username()), |
143 | 144 | 'adminForm': adminForm, |
144 | 145 | 'form_url': form_url, |
145 | 146 | 'form': form, |
146 | | 'is_popup': '_popup' in request.REQUEST, |
| 147 | 'is_popup': '_popup' in request.REQUEST or IS_POPUP_VAR in request.REQUEST, |
147 | 148 | 'add': True, |
148 | 149 | 'change': False, |
149 | 150 | 'has_delete_permission': False, |
… |
… |
class UserAdmin(admin.ModelAdmin):
|
170 | 171 | # button except in two scenarios: |
171 | 172 | # * The user has pressed the 'Save and add another' button |
172 | 173 | # * We are adding a user in a popup |
173 | | if '_addanother' not in request.POST and '_popup' not in request.POST: |
| 174 | from django.contrib.admin.views.main import IS_POPUP_VAR |
| 175 | if ('_addanother' not in request.POST and '_popup' not in request.POST and |
| 176 | IS_POPUP_VAR not in request.POST): |
174 | 177 | request.POST['_continue'] = 1 |
175 | 178 | return super(UserAdmin, self).response_add(request, obj, |
176 | 179 | post_url_continue) |
diff --git a/tests/admin_custom_urls/tests.py b/tests/admin_custom_urls/tests.py
index 31c9341..dc24355 100644
a
|
b
|
class AdminCustomUrlsTest(TestCase):
|
49 | 49 | """ |
50 | 50 | post_data = { |
51 | 51 | '_popup': '1', |
52 | | "name": 'Action added through a popup', |
| 52 | "name": 'Action added through a _popup', |
53 | 53 | "description": "Description of added action", |
54 | 54 | } |
55 | 55 | response = self.client.post('/custom_urls/admin/admin_custom_urls/action/!add/', post_data) |
56 | 56 | self.assertEqual(response.status_code, 200) |
57 | 57 | self.assertContains(response, 'dismissAddAnotherPopup') |
58 | | self.assertContains(response, 'Action added through a popup') |
| 58 | self.assertContains(response, 'Action added through a _popup') |
| 59 | |
| 60 | from django.contrib.admin.views.main import IS_POPUP_VAR |
| 61 | post_data = { |
| 62 | IS_POPUP_VAR: '1', |
| 63 | "name": 'Action added through a IS_POPUP_VAR', |
| 64 | "description": "Another description of added action", |
| 65 | } |
| 66 | response = self.client.post('/custom_urls/admin/admin_custom_urls/action/!add/', post_data) |
| 67 | self.assertEqual(response.status_code, 200) |
| 68 | self.assertContains(response, 'dismissAddAnotherPopup') |
| 69 | self.assertContains(response, 'Action added through a IS_POPUP_VAR') |
| 70 | |
59 | 71 | |
60 | 72 | def testAdminUrlsNoClash(self): |
61 | 73 | """ |
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index e0000ff..0246a3d 100644
a
|
b
|
class AdminViewBasicTest(TestCase):
|
159 | 159 | """ |
160 | 160 | Ensure http response from a popup is properly escaped. |
161 | 161 | """ |
| 162 | # _popup for backwards compatibility |
162 | 163 | post_data = { |
163 | 164 | '_popup': '1', |
164 | 165 | 'title': 'title with a new\nline', |
… |
… |
class AdminViewBasicTest(TestCase):
|
171 | 172 | self.assertContains(response, 'dismissAddAnotherPopup') |
172 | 173 | self.assertContains(response, 'title with a new\\u000Aline') |
173 | 174 | |
| 175 | post_data = { |
| 176 | IS_POPUP_VAR: '1', |
| 177 | 'title': 'title with a new\nline', |
| 178 | 'content': 'some content', |
| 179 | 'date_0': '2010-09-10', |
| 180 | 'date_1': '14:55:39', |
| 181 | } |
| 182 | response = self.client.post('/test_admin/%s/admin_views/article/add/' % self.urlbit, post_data) |
| 183 | self.assertEqual(response.status_code, 200) |
| 184 | self.assertContains(response, 'dismissAddAnotherPopup') |
| 185 | self.assertContains(response, 'title with a new\\u000Aline') |
| 186 | |
| 187 | |
174 | 188 | # Post data for edit inline |
175 | 189 | inline_post_data = { |
176 | 190 | "name": "Test section", |
… |
… |
class UserAdminTest(TestCase):
|
3572 | 3586 | self.assertEqual(response.status_code, 200) |
3573 | 3587 | self.assertContains(response, '/test_admin/admin/auth/user/add') |
3574 | 3588 | self.assertContains(response, 'class="add-another" id="add_id_owner" onclick="return showAddAnotherPopup(this);"') |
| 3589 | # _popup for backwards compatibility |
3575 | 3590 | response = self.client.get('/test_admin/admin/auth/user/add/?_popup=1') |
3576 | 3591 | self.assertEqual(response.status_code, 200) |
3577 | 3592 | self.assertNotContains(response, 'name="_continue"') |
3578 | 3593 | self.assertNotContains(response, 'name="_addanother"') |
| 3594 | |
| 3595 | response = self.client.get('/test_admin/admin/auth/user/add/?%s=1' % IS_POPUP_VAR) |
| 3596 | self.assertEqual(response.status_code, 200) |
| 3597 | self.assertNotContains(response, 'name="_continue"') |
| 3598 | self.assertNotContains(response, 'name="_addanother"') |
| 3599 | |
| 3600 | # _popup for backwards compatibility |
3579 | 3601 | data = { |
3580 | 3602 | 'username': 'newuser', |
3581 | 3603 | 'password1': 'newpassword', |
… |
… |
class UserAdminTest(TestCase):
|
3587 | 3609 | self.assertEqual(response.status_code, 200) |
3588 | 3610 | self.assertContains(response, 'dismissAddAnotherPopup') |
3589 | 3611 | |
| 3612 | data = { |
| 3613 | 'username': 'newuser2', |
| 3614 | 'password1': 'newpassword', |
| 3615 | 'password2': 'newpassword', |
| 3616 | IS_POPUP_VAR: '1', |
| 3617 | '_save': '1', |
| 3618 | } |
| 3619 | response = self.client.post('/test_admin/admin/auth/user/add/?%s=1' % IS_POPUP_VAR, data, follow=True) |
| 3620 | self.assertEqual(response.status_code, 200) |
| 3621 | self.assertContains(response, 'dismissAddAnotherPopup') |
| 3622 | |
| 3623 | |
3590 | 3624 | def test_save_add_another_button(self): |
3591 | 3625 | user_count = User.objects.count() |
3592 | 3626 | response = self.client.post('/test_admin/admin/auth/user/add/', { |