Ticket #20288: ticket_20288.diff

File ticket_20288.diff, 15.5 KB (added by tomask, 2 years ago)
  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index b35f100..53b1d2c 100644
    a b class ModelAdmin(BaseModelAdmin): 
    821821        """
    822822        Determines the HttpResponse for the add_view stage.
    823823        """
     824        from django.contrib.admin.views.main import IS_POPUP_VAR
    824825        opts = obj._meta
    825826        pk_value = obj._get_pk_val()
    826827
    class ModelAdmin(BaseModelAdmin): 
    835836                                            (opts.app_label, opts.model_name),
    836837                                            args=(pk_value,),
    837838                                            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
    840841            return HttpResponseRedirect(post_url_continue)
    841842
    842         if "_popup" in request.POST:
     843        if "_popup" in request.POST or IS_POPUP_VAR in request.POST:
    843844            return HttpResponse(
    844845                '<!DOCTYPE html><html><head><title></title></head><body>'
    845846                '<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script></body></html>' % \
    class ModelAdmin(BaseModelAdmin): 
    858859        """
    859860        Determines the HttpResponse for the change_view stage.
    860861        """
     862        from django.contrib.admin.views.main import IS_POPUP_VAR
    861863        opts = self.model._meta
    862864
    863865        pk_value = obj._get_pk_val()
    class ModelAdmin(BaseModelAdmin): 
    866868        if "_continue" in request.POST:
    867869            msg = _('The %(name)s "%(obj)s" was changed successfully. You may edit it again below.') % msg_dict
    868870            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))
    871873            else:
    872874                return HttpResponseRedirect(request.path)
    873875        elif "_saveasnew" in request.POST:
    class ModelAdmin(BaseModelAdmin): 
    10601062            inline_admin_formsets.append(inline_admin_formset)
    10611063            media = media + inline_admin_formset.media
    10621064
     1065        from django.contrib.admin.views.main import IS_POPUP_VAR
    10631066        context = {
    10641067            'title': _('Add %s') % force_text(opts.verbose_name),
    10651068            'adminform': adminForm,
    1066             'is_popup': "_popup" in request.REQUEST,
     1069            'is_popup': "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST,
    10671070            'media': media,
    10681071            'inline_admin_formsets': inline_admin_formsets,
    10691072            'errors': helpers.AdminErrorList(form, formsets),
    class ModelAdmin(BaseModelAdmin): 
    11501153            inline_admin_formsets.append(inline_admin_formset)
    11511154            media = media + inline_admin_formset.media
    11521155
     1156        from django.contrib.admin.views.main import IS_POPUP_VAR
    11531157        context = {
    11541158            'title': _('Change %s') % force_text(opts.verbose_name),
    11551159            'adminform': adminForm,
    11561160            'object_id': object_id,
    11571161            'original': obj,
    1158             'is_popup': "_popup" in request.REQUEST,
     1162            'is_popup': "_popup" in request.REQUEST or IS_POPUP_VAR in request.REQUEST,
    11591163            'media': media,
    11601164            'inline_admin_formsets': inline_admin_formsets,
    11611165            'errors': helpers.AdminErrorList(form, formsets),
  • django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js

    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) { 
    5757    name = id_to_windowname(name);
    5858    href = triggeringLink.href
    5959    if (href.indexOf('?') == -1) {
    60         href += '?_popup=1';
     60        href += '?pop=1';
    6161    } else {
    62         href  += '&_popup=1';
     62        href  += '&pop=1';
    6363    }
    6464    var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
    6565    win.focus();
  • django/contrib/admin/templates/admin/auth/user/change_password.html

    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  
    11{% extends "admin/base_site.html" %}
    22{% load i18n admin_static %}
    33{% load admin_urls %}
     4{% load admin_popup_var %}
    45
    56{% block extrahead %}{{ block.super }}
    67<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
     
    2122{% block content %}<div id="content-main">
    2223<form action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
    2324<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 %}
    2526{% if form.errors %}
    2627    <p class="errornote">
    2728    {% blocktrans count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
  • django/contrib/admin/templates/admin/change_form.html

    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  
    11{% extends "admin/base_site.html" %}
    22{% load i18n admin_static admin_modify %}
    33{% load admin_urls %}
     4{% load admin_popup_var %}
    45
    56{% block extrahead %}{{ block.super }}
    67<script type="text/javascript" src="{% url 'admin:jsi18n' %}"></script>
     
    3738{% endblock %}
    3839<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 %}
    3940<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 %}
    4142{% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %}
    4243{% if errors %}
    4344    <p class="errornote">
  • django/contrib/admin/templates/admin/change_list.html

    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  
    11{% extends "admin/base_site.html" %}
    22{% load i18n admin_static admin_list %}
    33{% load admin_urls %}
     4{% load admin_popup_var %}
    45
    56{% block extrastyle %}
    67  {{ block.super }}
     
    5455        <ul class="object-tools">
    5556          {% block object-tools-items %}
    5657            <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">
    5859                {% blocktrans with cl.opts.verbose_name as name %}Add {{ name }}{% endblocktrans %}
    5960              </a>
    6061            </li>
  • django/contrib/admin/templates/admin/search_form.html

    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 %}
    22{% if cl.search_fields %}
    33<div id="toolbar"><form id="changelist-search" action="" method="get">
    44<div><!-- DIV needed for valid HTML -->
     
    66<input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" />
    77<input type="submit" value="{% trans 'Search' %}" />
    88{% 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>
    1010{% endif %}
    1111{% for pair in cl.params.items %}
    1212    {% ifnotequal pair.0 search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endifnotequal %}
  • django/contrib/admin/templatetags/admin_popup_var.py

    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  
     1from django import template
     2from django.contrib.admin.views.main import IS_POPUP_VAR
     3
     4register = template.Library()
     5
     6@register.assignment_tag
     7def get_popup_var():
     8    return IS_POPUP_VAR
     9
  • django/contrib/auth/admin.py

    diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
    index 409078f..5aff535 100644
    a b class UserAdmin(admin.ModelAdmin): 
    138138        fieldsets = [(None, {'fields': list(form.base_fields)})]
    139139        adminForm = admin.helpers.AdminForm(form, fieldsets, {})
    140140
     141        from django.contrib.admin.views.main import IS_POPUP_VAR
    141142        context = {
    142143            'title': _('Change password: %s') % escape(user.get_username()),
    143144            'adminForm': adminForm,
    144145            'form_url': form_url,
    145146            'form': form,
    146             'is_popup': '_popup' in request.REQUEST,
     147            'is_popup': '_popup' in request.REQUEST or IS_POPUP_VAR in request.REQUEST,
    147148            'add': True,
    148149            'change': False,
    149150            'has_delete_permission': False,
    class UserAdmin(admin.ModelAdmin): 
    170171        # button except in two scenarios:
    171172        # * The user has pressed the 'Save and add another' button
    172173        # * 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):
    174177            request.POST['_continue'] = 1
    175178        return super(UserAdmin, self).response_add(request, obj,
    176179                                                   post_url_continue)
  • tests/admin_custom_urls/tests.py

    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): 
    4949        """
    5050        post_data = {
    5151            '_popup': '1',
    52             "name": 'Action added through a popup',
     52            "name": 'Action added through a _popup',
    5353            "description": "Description of added action",
    5454        }
    5555        response = self.client.post('/custom_urls/admin/admin_custom_urls/action/!add/', post_data)
    5656        self.assertEqual(response.status_code, 200)
    5757        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
    5971
    6072    def testAdminUrlsNoClash(self):
    6173        """
  • tests/admin_views/tests.py

    diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
    index e0000ff..0246a3d 100644
    a b class AdminViewBasicTest(TestCase): 
    159159        """
    160160        Ensure http response from a popup is properly escaped.
    161161        """
     162        # _popup for backwards compatibility
    162163        post_data = {
    163164            '_popup': '1',
    164165            'title': 'title with a new\nline',
    class AdminViewBasicTest(TestCase): 
    171172        self.assertContains(response, 'dismissAddAnotherPopup')
    172173        self.assertContains(response, 'title with a new\\u000Aline')
    173174
     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
    174188    # Post data for edit inline
    175189    inline_post_data = {
    176190        "name": "Test section",
    class UserAdminTest(TestCase): 
    35723586        self.assertEqual(response.status_code, 200)
    35733587        self.assertContains(response, '/test_admin/admin/auth/user/add')
    35743588        self.assertContains(response, 'class="add-another" id="add_id_owner" onclick="return showAddAnotherPopup(this);"')
     3589        # _popup for backwards compatibility
    35753590        response = self.client.get('/test_admin/admin/auth/user/add/?_popup=1')
    35763591        self.assertEqual(response.status_code, 200)
    35773592        self.assertNotContains(response, 'name="_continue"')
    35783593        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
    35793601        data = {
    35803602            'username': 'newuser',
    35813603            'password1': 'newpassword',
    class UserAdminTest(TestCase): 
    35873609        self.assertEqual(response.status_code, 200)
    35883610        self.assertContains(response, 'dismissAddAnotherPopup')
    35893611
     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
    35903624    def test_save_add_another_button(self):
    35913625        user_count = User.objects.count()
    35923626        response = self.client.post('/test_admin/admin/auth/user/add/', {
Back to Top