Fixed #20288 -- Fixed inconsistency in the naming of the popup GET parameter.
Thanks to Keryn Knight for the initial report and reviews, and to tomask for the original patch.
This commit is contained in:
parent
ffcf24c9ce
commit
7462a78c1b
|
@ -40,6 +40,8 @@ from django.utils.translation import ugettext as _
|
|||
from django.utils.translation import ungettext
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
IS_POPUP_VAR = '_popup'
|
||||
|
||||
HORIZONTAL, VERTICAL = 1, 2
|
||||
# returns the <ul> class for a given radio_admin field
|
||||
get_ul_class = lambda x: 'radiolist%s' % (' inline' if x == HORIZONTAL else '')
|
||||
|
@ -660,8 +662,8 @@ class ModelAdmin(BaseModelAdmin):
|
|||
"""
|
||||
# If self.actions is explicitly set to None that means that we don't
|
||||
# want *any* actions enabled on this page.
|
||||
from django.contrib.admin.views.main import IS_POPUP_VAR
|
||||
if self.actions is None or IS_POPUP_VAR in request.GET:
|
||||
from django.contrib.admin.views.main import _is_changelist_popup
|
||||
if self.actions is None or _is_changelist_popup(request):
|
||||
return SortedDict()
|
||||
|
||||
actions = []
|
||||
|
@ -908,7 +910,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||
msg_dict = {'name': force_text(opts.verbose_name), 'obj': force_text(obj)}
|
||||
# Here, we distinguish between different save types by checking for
|
||||
# the presence of keys in request.POST.
|
||||
if "_popup" in request.POST:
|
||||
if IS_POPUP_VAR in request.POST:
|
||||
return HttpResponse(
|
||||
'<!DOCTYPE html><html><head><title></title></head><body>'
|
||||
'<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script></body></html>' % \
|
||||
|
@ -1158,7 +1160,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||
context = {
|
||||
'title': _('Add %s') % force_text(opts.verbose_name),
|
||||
'adminform': adminForm,
|
||||
'is_popup': "_popup" in request.REQUEST,
|
||||
'is_popup': IS_POPUP_VAR in request.REQUEST,
|
||||
'media': media,
|
||||
'inline_admin_formsets': inline_admin_formsets,
|
||||
'errors': helpers.AdminErrorList(form, formsets),
|
||||
|
@ -1251,7 +1253,7 @@ class ModelAdmin(BaseModelAdmin):
|
|||
'adminform': adminForm,
|
||||
'object_id': object_id,
|
||||
'original': obj,
|
||||
'is_popup': "_popup" in request.REQUEST,
|
||||
'is_popup': IS_POPUP_VAR in request.REQUEST,
|
||||
'media': media,
|
||||
'inline_admin_formsets': inline_admin_formsets,
|
||||
'errors': helpers.AdminErrorList(form, formsets),
|
||||
|
|
|
@ -32,9 +32,9 @@ function showRelatedObjectLookupPopup(triggeringLink) {
|
|||
name = id_to_windowname(name);
|
||||
var href;
|
||||
if (triggeringLink.href.search(/\?/) >= 0) {
|
||||
href = triggeringLink.href + '&pop=1';
|
||||
href = triggeringLink.href + '&_popup=1';
|
||||
} else {
|
||||
href = triggeringLink.href + '?pop=1';
|
||||
href = triggeringLink.href + '?_popup=1';
|
||||
}
|
||||
var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
|
||||
win.focus();
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<input type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" />
|
||||
<input type="submit" value="{% trans 'Search' %}" />
|
||||
{% if show_result_count %}
|
||||
<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>
|
||||
<span class="small quiet">{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} (<a href="?{% if cl.is_popup %}_popup=1{% endif %}">{% blocktrans with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktrans %}</a>)</span>
|
||||
{% endif %}
|
||||
{% for pair in cl.params.items %}
|
||||
{% ifnotequal pair.0 search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endifnotequal %}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
from django.utils.http import urlencode
|
||||
|
||||
try:
|
||||
from urllib.parse import parse_qsl, urlparse, urlunparse
|
||||
except ImportError:
|
||||
|
@ -8,6 +6,7 @@ except ImportError:
|
|||
from django import template
|
||||
from django.contrib.admin.util import quote
|
||||
from django.core.urlresolvers import resolve, Resolver404
|
||||
from django.utils.http import urlencode
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
@ -47,7 +46,8 @@ def add_preserved_filters(context, url, popup=False):
|
|||
merged_qs.update(preserved_filters)
|
||||
|
||||
if popup:
|
||||
merged_qs['_popup'] = 1
|
||||
from django.contrib.admin.options import IS_POPUP_VAR
|
||||
merged_qs[IS_POPUP_VAR] = 1
|
||||
|
||||
merged_qs.update(parsed_qs)
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.utils.http import urlencode
|
|||
|
||||
from django.contrib.admin import FieldListFilter
|
||||
from django.contrib.admin.exceptions import DisallowedModelAdminLookup
|
||||
from django.contrib.admin.options import IncorrectLookupParameters
|
||||
from django.contrib.admin.options import IncorrectLookupParameters, IS_POPUP_VAR
|
||||
from django.contrib.admin.util import (quote, get_fields_from_path,
|
||||
lookup_needs_distinct, prepare_lookup_value)
|
||||
|
||||
|
@ -26,7 +26,6 @@ ORDER_TYPE_VAR = 'ot'
|
|||
PAGE_VAR = 'p'
|
||||
SEARCH_VAR = 'q'
|
||||
TO_FIELD_VAR = 't'
|
||||
IS_POPUP_VAR = 'pop'
|
||||
ERROR_FLAG = 'e'
|
||||
|
||||
IGNORED_PARAMS = (
|
||||
|
@ -36,6 +35,29 @@ IGNORED_PARAMS = (
|
|||
EMPTY_CHANGELIST_VALUE = ugettext_lazy('(None)')
|
||||
|
||||
|
||||
def _is_changelist_popup(request):
|
||||
"""
|
||||
Returns True if the popup GET parameter is set.
|
||||
|
||||
This function is introduced to facilitate deprecating the legacy
|
||||
value for IS_POPUP_VAR and should be removed at the end of the
|
||||
deprecation cycle.
|
||||
"""
|
||||
|
||||
if IS_POPUP_VAR in request.GET:
|
||||
return True
|
||||
|
||||
IS_LEGACY_POPUP_VAR = 'pop'
|
||||
if IS_LEGACY_POPUP_VAR in request.GET:
|
||||
warnings.warn(
|
||||
"The `%s` GET parameter has been renamed to `%s`." %
|
||||
(IS_LEGACY_POPUP_VAR, IS_POPUP_VAR),
|
||||
PendingDeprecationWarning, 2)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class RenameChangeListMethods(RenameMethodsBase):
|
||||
renamed_methods = (
|
||||
('get_query_set', 'get_queryset', PendingDeprecationWarning),
|
||||
|
@ -67,7 +89,7 @@ class ChangeList(six.with_metaclass(RenameChangeListMethods)):
|
|||
except ValueError:
|
||||
self.page_num = 0
|
||||
self.show_all = ALL_VAR in request.GET
|
||||
self.is_popup = IS_POPUP_VAR in request.GET
|
||||
self.is_popup = _is_changelist_popup(request)
|
||||
self.to_field = request.GET.get(TO_FIELD_VAR)
|
||||
self.params = dict(request.GET.items())
|
||||
if PAGE_VAR in self.params:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.db import transaction
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin.options import IS_POPUP_VAR
|
||||
from django.contrib.auth.forms import (UserCreationForm, UserChangeForm,
|
||||
AdminPasswordChangeForm)
|
||||
from django.contrib.auth.models import User, Group
|
||||
|
@ -143,7 +144,7 @@ class UserAdmin(admin.ModelAdmin):
|
|||
'adminForm': adminForm,
|
||||
'form_url': form_url,
|
||||
'form': form,
|
||||
'is_popup': '_popup' in request.REQUEST,
|
||||
'is_popup': IS_POPUP_VAR in request.REQUEST,
|
||||
'add': True,
|
||||
'change': False,
|
||||
'has_delete_permission': False,
|
||||
|
@ -170,7 +171,7 @@ 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:
|
||||
if '_addanother' 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)
|
||||
|
|
|
@ -725,6 +725,12 @@ Miscellaneous
|
|||
returned ``False`` for blank passwords. This has been corrected in this
|
||||
release: blank passwords are now valid.
|
||||
|
||||
* The admin :attr:`~django.contrib.admin.ModelAdmin.changelist_view` previously
|
||||
accepted a ``pop`` GET parameter to signify it was to be displayed in a popup.
|
||||
This parameter has been renamed to ``_popup`` to be consistent with the rest
|
||||
of the admin views. You should update your custom templates if they use the
|
||||
previous parameter name.
|
||||
|
||||
Features deprecated in 1.6
|
||||
==========================
|
||||
|
||||
|
|
Loading…
Reference in New Issue