Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove several uses of the deprecated dict.has_key in favor of the in…

… operator. This is faster, has less code, and is in every single way better.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14392 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c38a174f7c3d2dc5a1adab746ca44f0afd0d966c 1 parent cb17f7c
Alex Gaynor alex authored
24 django/contrib/admin/options.py
View
@@ -648,17 +648,17 @@ def response_add(self, request, obj, post_url_continue='../%s/'):
msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj)}
# Here, we distinguish between different save types by checking for
# the presence of keys in request.POST.
- if request.POST.has_key("_continue"):
+ if "_continue" in request.POST:
self.message_user(request, msg + ' ' + _("You may edit it again below."))
- if request.POST.has_key("_popup"):
+ if "_popup" in request.POST:
post_url_continue += "?_popup=1"
return HttpResponseRedirect(post_url_continue % pk_value)
- if request.POST.has_key("_popup"):
+ if "_popup" in request.POST:
return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' % \
# escape() calls force_unicode.
(escape(pk_value), escape(obj)))
- elif request.POST.has_key("_addanother"):
+ elif "_addanother" in request.POST:
self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name)))
return HttpResponseRedirect(request.path)
else:
@@ -681,17 +681,17 @@ def response_change(self, request, obj):
pk_value = obj._get_pk_val()
msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj)}
- if request.POST.has_key("_continue"):
+ if "_continue" in request.POST:
self.message_user(request, msg + ' ' + _("You may edit it again below."))
- if request.REQUEST.has_key('_popup'):
+ if "_popup" in request.REQUEST:
return HttpResponseRedirect(request.path + "?_popup=1")
else:
return HttpResponseRedirect(request.path)
- elif request.POST.has_key("_saveasnew"):
+ elif "_saveasnew" in request.POST:
msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(opts.verbose_name), 'obj': obj}
self.message_user(request, msg)
return HttpResponseRedirect("../%s/" % pk_value)
- elif request.POST.has_key("_addanother"):
+ elif "_addanother" in request.POST:
self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name)))
return HttpResponseRedirect("../add/")
else:
@@ -793,7 +793,7 @@ def add_view(self, request, form_url='', extra_context=None):
prefix = "%s-%s" % (prefix, prefixes[prefix])
formset = FormSet(data=request.POST, files=request.FILES,
instance=new_object,
- save_as_new=request.POST.has_key("_saveasnew"),
+ save_as_new="_saveasnew" in request.POST,
prefix=prefix, queryset=inline.queryset(request))
formsets.append(formset)
if all_valid(formsets) and form_validated:
@@ -844,7 +844,7 @@ def add_view(self, request, form_url='', extra_context=None):
context = {
'title': _('Add %s') % force_unicode(opts.verbose_name),
'adminform': adminForm,
- 'is_popup': request.REQUEST.has_key('_popup'),
+ 'is_popup': "_popup" in request.REQUEST,
'show_delete': False,
'media': mark_safe(media),
'inline_admin_formsets': inline_admin_formsets,
@@ -870,7 +870,7 @@ def change_view(self, request, object_id, extra_context=None):
if obj is None:
raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)})
- if request.method == 'POST' and request.POST.has_key("_saveasnew"):
+ if request.method == 'POST' and "_saveasnew" in request.POST:
return self.add_view(request, form_url='../add/')
ModelForm = self.get_form(request, obj)
@@ -937,7 +937,7 @@ def change_view(self, request, object_id, extra_context=None):
'adminform': adminForm,
'object_id': object_id,
'original': obj,
- 'is_popup': request.REQUEST.has_key('_popup'),
+ 'is_popup': "_popup" in request.REQUEST,
'media': mark_safe(media),
'inline_admin_formsets': inline_admin_formsets,
'errors': helpers.AdminErrorList(form, formsets),
2  django/contrib/admin/sites.py
View
@@ -303,7 +303,7 @@ def login(self, request):
from django.contrib.auth.models import User
# If this isn't already the login page, display it.
- if not request.POST.has_key(LOGIN_FORM_KEY):
+ if LOGIN_FORM_KEY not in request.POST:
if request.POST:
message = _("Please log in again, because your session has expired.")
else:
2  django/contrib/admin/widgets.py
View
@@ -111,7 +111,7 @@ def render(self, name, value, attrs=None):
url = '?' + '&amp;'.join(['%s=%s' % (k, v) for k, v in params.items()])
else:
url = ''
- if not attrs.has_key('class'):
+ if "class" not in attrs:
attrs['class'] = 'vForeignKeyRawIdAdminField' # The JavaScript looks for this hook.
output = [super(ForeignKeyRawIdWidget, self).render(name, value, attrs)]
# TODO: "id_" is hard-coded here. This should instead use the correct
4 django/db/models/query.py
View
@@ -864,9 +864,9 @@ def _setup_query(self):
# we inspect the full extra_select list since we might
# be adding back an extra select item that we hadn't
# had selected previously.
- if self.query.extra.has_key(f):
+ if f in self.query.extra:
self.extra_names.append(f)
- elif self.query.aggregate_select.has_key(f):
+ elif f in self.query.aggregate_select:
self.aggregate_names.append(f)
else:
self.field_names.append(f)
Please sign in to comment.
Something went wrong with that request. Please try again.