diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index b35f100..53b1d2c 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -821,6 +821,7 @@ class ModelAdmin(BaseModelAdmin): """ Determines the HttpResponse for the add_view stage. """ + from django.contrib.admin.views.main import IS_POPUP_VAR opts = obj._meta pk_value = obj._get_pk_val() @@ -835,11 +836,11 @@ class ModelAdmin(BaseModelAdmin): (opts.app_label, opts.model_name), args=(pk_value,), current_app=self.admin_site.name) - if "_popup" in request.POST: - post_url_continue += "?_popup=1" + if "_popup" in request.POST or IS_POPUP_VAR in request.POST: + post_url_continue += "?%s=1" % IS_POPUP_VAR return HttpResponseRedirect(post_url_continue) - if "_popup" in request.POST: + if "_popup" in request.POST or IS_POPUP_VAR in request.POST: return HttpResponse( '' '' % \ @@ -858,6 +859,7 @@ class ModelAdmin(BaseModelAdmin): """ Determines the HttpResponse for the change_view stage. """ + from django.contrib.admin.views.main import IS_POPUP_VAR opts = self.model._meta pk_value = obj._get_pk_val() @@ -866,8 +868,8 @@ class ModelAdmin(BaseModelAdmin): if "_continue" in request.POST: msg = _('The %(name)s "%(obj)s" was changed successfully. You may edit it again below.') % msg_dict self.message_user(request, msg, messages.SUCCESS) - if "_popup" in request.REQUEST: - return HttpResponseRedirect(request.path + "?_popup=1") + if "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST: + return HttpResponseRedirect(request.path + ("?%s=1" % IS_POPUP_VAR)) else: return HttpResponseRedirect(request.path) elif "_saveasnew" in request.POST: @@ -1060,10 +1062,11 @@ class ModelAdmin(BaseModelAdmin): inline_admin_formsets.append(inline_admin_formset) media = media + inline_admin_formset.media + from django.contrib.admin.views.main import IS_POPUP_VAR context = { 'title': _('Add %s') % force_text(opts.verbose_name), 'adminform': adminForm, - 'is_popup': "_popup" in request.REQUEST, + 'is_popup': "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST, 'media': media, 'inline_admin_formsets': inline_admin_formsets, 'errors': helpers.AdminErrorList(form, formsets), @@ -1150,12 +1153,13 @@ class ModelAdmin(BaseModelAdmin): inline_admin_formsets.append(inline_admin_formset) media = media + inline_admin_formset.media + from django.contrib.admin.views.main import IS_POPUP_VAR context = { 'title': _('Change %s') % force_text(opts.verbose_name), 'adminform': adminForm, 'object_id': object_id, 'original': obj, - 'is_popup': "_popup" in request.REQUEST, + 'is_popup': "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST, 'media': media, 'inline_admin_formsets': inline_admin_formsets, '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/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js +++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js @@ -57,9 +57,9 @@ function showAddAnotherPopup(triggeringLink) { name = id_to_windowname(name); href = triggeringLink.href if (href.indexOf('?') == -1) { - href += '?_popup=1'; + href += '?pop=1'; } else { - href += '&_popup=1'; + href += '&pop=1'; } var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes'); 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/django/contrib/admin/templates/admin/auth/user/change_password.html +++ b/django/contrib/admin/templates/admin/auth/user/change_password.html @@ -1,6 +1,7 @@ {% extends "admin/base_site.html" %} {% load i18n admin_static %} {% load admin_urls %} +{% load admin_popup_var %} {% block extrahead %}{{ block.super }} @@ -21,7 +22,7 @@ {% block content %}
{% csrf_token %}{% block form_top %}{% endblock %}
-{% if is_popup %}{% endif %} +{% if is_popup %}{% get_popup_var as popup_var %}{% endif %} {% if form.errors %}

{% 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/django/contrib/admin/templates/admin/change_form.html +++ b/django/contrib/admin/templates/admin/change_form.html @@ -1,6 +1,7 @@ {% extends "admin/base_site.html" %} {% load i18n admin_static admin_modify %} {% load admin_urls %} +{% load admin_popup_var %} {% block extrahead %}{{ block.super }} @@ -37,7 +38,7 @@ {% endblock %} {% csrf_token %}{% block form_top %}{% endblock %}

-{% if is_popup %}{% endif %} +{% if is_popup %}{% get_popup_var as popup_var %}{% endif %} {% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %} {% if errors %}

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/django/contrib/admin/templates/admin/change_list.html +++ b/django/contrib/admin/templates/admin/change_list.html @@ -1,6 +1,7 @@ {% extends "admin/base_site.html" %} {% load i18n admin_static admin_list %} {% load admin_urls %} +{% load admin_popup_var %} {% block extrastyle %} {{ block.super }} @@ -54,7 +55,7 @@

    {% block object-tools-items %}
  • - + {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
  • 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/django/contrib/admin/templates/admin/search_form.html +++ b/django/contrib/admin/templates/admin/search_form.html @@ -1,4 +1,4 @@ -{% load i18n admin_static %} +{% load i18n admin_static admin_popup_var %} {% if cl.search_fields %}
    @@ -6,7 +6,7 @@ {% if show_result_count %} - {% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} ({% blocktrans with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktrans %}) +{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} ({% blocktrans with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktrans %}) {% endif %} {% for pair in cl.params.items %} {% ifnotequal pair.0 search_var %}{% 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/django/contrib/admin/templatetags/admin_popup_var.py +++ b/django/contrib/admin/templatetags/admin_popup_var.py @@ -0,0 +1,9 @@ +from django import template +from django.contrib.admin.views.main import IS_POPUP_VAR + +register = template.Library() + +@register.assignment_tag +def get_popup_var(): + return IS_POPUP_VAR + diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py index 409078f..5aff535 100644 --- a/django/contrib/auth/admin.py +++ b/django/contrib/auth/admin.py @@ -138,12 +138,13 @@ class UserAdmin(admin.ModelAdmin): fieldsets = [(None, {'fields': list(form.base_fields)})] adminForm = admin.helpers.AdminForm(form, fieldsets, {}) + from django.contrib.admin.views.main import IS_POPUP_VAR context = { 'title': _('Change password: %s') % escape(user.get_username()), 'adminForm': adminForm, 'form_url': form_url, 'form': form, - 'is_popup': '_popup' in request.REQUEST, + 'is_popup': '_popup' in request.REQUEST or IS_POPUP_VAR in request.REQUEST, 'add': True, 'change': False, 'has_delete_permission': False, @@ -170,7 +171,9 @@ class UserAdmin(admin.ModelAdmin): # button except in two scenarios: # * The user has pressed the 'Save and add another' button # * We are adding a user in a popup - if '_addanother' not in request.POST and '_popup' not in request.POST: + from django.contrib.admin.views.main import IS_POPUP_VAR + if ('_addanother' not in request.POST and '_popup' not in request.POST and + IS_POPUP_VAR not in request.POST): request.POST['_continue'] = 1 return super(UserAdmin, self).response_add(request, obj, post_url_continue) diff --git a/tests/admin_custom_urls/tests.py b/tests/admin_custom_urls/tests.py index 31c9341..dc24355 100644 --- a/tests/admin_custom_urls/tests.py +++ b/tests/admin_custom_urls/tests.py @@ -49,13 +49,25 @@ class AdminCustomUrlsTest(TestCase): """ post_data = { '_popup': '1', - "name": 'Action added through a popup', + "name": 'Action added through a _popup', "description": "Description of added action", } response = self.client.post('/custom_urls/admin/admin_custom_urls/action/!add/', post_data) self.assertEqual(response.status_code, 200) self.assertContains(response, 'dismissAddAnotherPopup') - self.assertContains(response, 'Action added through a popup') + self.assertContains(response, 'Action added through a _popup') + + from django.contrib.admin.views.main import IS_POPUP_VAR + post_data = { + IS_POPUP_VAR: '1', + "name": 'Action added through a IS_POPUP_VAR', + "description": "Another description of added action", + } + response = self.client.post('/custom_urls/admin/admin_custom_urls/action/!add/', post_data) + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'dismissAddAnotherPopup') + self.assertContains(response, 'Action added through a IS_POPUP_VAR') + def testAdminUrlsNoClash(self): """ diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index e0000ff..0246a3d 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -159,6 +159,7 @@ class AdminViewBasicTest(TestCase): """ Ensure http response from a popup is properly escaped. """ + # _popup for backwards compatibility post_data = { '_popup': '1', 'title': 'title with a new\nline', @@ -171,6 +172,19 @@ class AdminViewBasicTest(TestCase): self.assertContains(response, 'dismissAddAnotherPopup') self.assertContains(response, 'title with a new\\u000Aline') + post_data = { + IS_POPUP_VAR: '1', + 'title': 'title with a new\nline', + 'content': 'some content', + 'date_0': '2010-09-10', + 'date_1': '14:55:39', + } + response = self.client.post('/test_admin/%s/admin_views/article/add/' % self.urlbit, post_data) + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'dismissAddAnotherPopup') + self.assertContains(response, 'title with a new\\u000Aline') + + # Post data for edit inline inline_post_data = { "name": "Test section", @@ -3572,10 +3586,18 @@ class UserAdminTest(TestCase): self.assertEqual(response.status_code, 200) self.assertContains(response, '/test_admin/admin/auth/user/add') self.assertContains(response, 'class="add-another" id="add_id_owner" onclick="return showAddAnotherPopup(this);"') + # _popup for backwards compatibility response = self.client.get('/test_admin/admin/auth/user/add/?_popup=1') self.assertEqual(response.status_code, 200) self.assertNotContains(response, 'name="_continue"') self.assertNotContains(response, 'name="_addanother"') + + response = self.client.get('/test_admin/admin/auth/user/add/?%s=1' % IS_POPUP_VAR) + self.assertEqual(response.status_code, 200) + self.assertNotContains(response, 'name="_continue"') + self.assertNotContains(response, 'name="_addanother"') + + # _popup for backwards compatibility data = { 'username': 'newuser', 'password1': 'newpassword', @@ -3587,6 +3609,18 @@ class UserAdminTest(TestCase): self.assertEqual(response.status_code, 200) self.assertContains(response, 'dismissAddAnotherPopup') + data = { + 'username': 'newuser2', + 'password1': 'newpassword', + 'password2': 'newpassword', + IS_POPUP_VAR: '1', + '_save': '1', + } + response = self.client.post('/test_admin/admin/auth/user/add/?%s=1' % IS_POPUP_VAR, data, follow=True) + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'dismissAddAnotherPopup') + + def test_save_add_another_button(self): user_count = User.objects.count() response = self.client.post('/test_admin/admin/auth/user/add/', {