Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored October 29, 2010
24  django/contrib/admin/options.py
@@ -648,17 +648,17 @@ def response_add(self, request, obj, post_url_continue='../%s/'):
648 648
         msg = _('The %(name)s "%(obj)s" was added successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj)}
649 649
         # Here, we distinguish between different save types by checking for
650 650
         # the presence of keys in request.POST.
651  
-        if request.POST.has_key("_continue"):
  651
+        if "_continue" in request.POST:
652 652
             self.message_user(request, msg + ' ' + _("You may edit it again below."))
653  
-            if request.POST.has_key("_popup"):
  653
+            if "_popup" in request.POST:
654 654
                 post_url_continue += "?_popup=1"
655 655
             return HttpResponseRedirect(post_url_continue % pk_value)
656 656
 
657  
-        if request.POST.has_key("_popup"):
  657
+        if "_popup" in request.POST:
658 658
             return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' % \
659 659
                 # escape() calls force_unicode.
660 660
                 (escape(pk_value), escape(obj)))
661  
-        elif request.POST.has_key("_addanother"):
  661
+        elif "_addanother" in request.POST:
662 662
             self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name)))
663 663
             return HttpResponseRedirect(request.path)
664 664
         else:
@@ -681,17 +681,17 @@ def response_change(self, request, obj):
681 681
         pk_value = obj._get_pk_val()
682 682
 
683 683
         msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(opts.verbose_name), 'obj': force_unicode(obj)}
684  
-        if request.POST.has_key("_continue"):
  684
+        if "_continue" in request.POST:
685 685
             self.message_user(request, msg + ' ' + _("You may edit it again below."))
686  
-            if request.REQUEST.has_key('_popup'):
  686
+            if "_popup" in request.REQUEST:
687 687
                 return HttpResponseRedirect(request.path + "?_popup=1")
688 688
             else:
689 689
                 return HttpResponseRedirect(request.path)
690  
-        elif request.POST.has_key("_saveasnew"):
  690
+        elif "_saveasnew" in request.POST:
691 691
             msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % {'name': force_unicode(opts.verbose_name), 'obj': obj}
692 692
             self.message_user(request, msg)
693 693
             return HttpResponseRedirect("../%s/" % pk_value)
694  
-        elif request.POST.has_key("_addanother"):
  694
+        elif "_addanother" in request.POST:
695 695
             self.message_user(request, msg + ' ' + (_("You may add another %s below.") % force_unicode(opts.verbose_name)))
696 696
             return HttpResponseRedirect("../add/")
697 697
         else:
@@ -793,7 +793,7 @@ def add_view(self, request, form_url='', extra_context=None):
793 793
                     prefix = "%s-%s" % (prefix, prefixes[prefix])
794 794
                 formset = FormSet(data=request.POST, files=request.FILES,
795 795
                                   instance=new_object,
796  
-                                  save_as_new=request.POST.has_key("_saveasnew"),
  796
+                                  save_as_new="_saveasnew" in request.POST,
797 797
                                   prefix=prefix, queryset=inline.queryset(request))
798 798
                 formsets.append(formset)
799 799
             if all_valid(formsets) and form_validated:
@@ -844,7 +844,7 @@ def add_view(self, request, form_url='', extra_context=None):
844 844
         context = {
845 845
             'title': _('Add %s') % force_unicode(opts.verbose_name),
846 846
             'adminform': adminForm,
847  
-            'is_popup': request.REQUEST.has_key('_popup'),
  847
+            'is_popup': "_popup" in request.REQUEST,
848 848
             'show_delete': False,
849 849
             'media': mark_safe(media),
850 850
             'inline_admin_formsets': inline_admin_formsets,
@@ -870,7 +870,7 @@ def change_view(self, request, object_id, extra_context=None):
870 870
         if obj is None:
871 871
             raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)})
872 872
 
873  
-        if request.method == 'POST' and request.POST.has_key("_saveasnew"):
  873
+        if request.method == 'POST' and "_saveasnew" in request.POST:
874 874
             return self.add_view(request, form_url='../add/')
875 875
 
876 876
         ModelForm = self.get_form(request, obj)
@@ -937,7 +937,7 @@ def change_view(self, request, object_id, extra_context=None):
937 937
             'adminform': adminForm,
938 938
             'object_id': object_id,
939 939
             'original': obj,
940  
-            'is_popup': request.REQUEST.has_key('_popup'),
  940
+            'is_popup': "_popup" in request.REQUEST,
941 941
             'media': mark_safe(media),
942 942
             'inline_admin_formsets': inline_admin_formsets,
943 943
             'errors': helpers.AdminErrorList(form, formsets),
2  django/contrib/admin/sites.py
@@ -303,7 +303,7 @@ def login(self, request):
303 303
         from django.contrib.auth.models import User
304 304
 
305 305
         # If this isn't already the login page, display it.
306  
-        if not request.POST.has_key(LOGIN_FORM_KEY):
  306
+        if LOGIN_FORM_KEY not in request.POST:
307 307
             if request.POST:
308 308
                 message = _("Please log in again, because your session has expired.")
309 309
             else:
2  django/contrib/admin/widgets.py
@@ -111,7 +111,7 @@ def render(self, name, value, attrs=None):
111 111
             url = '?' + '&amp;'.join(['%s=%s' % (k, v) for k, v in params.items()])
112 112
         else:
113 113
             url = ''
114  
-        if not attrs.has_key('class'):
  114
+        if "class" not in attrs:
115 115
             attrs['class'] = 'vForeignKeyRawIdAdminField' # The JavaScript looks for this hook.
116 116
         output = [super(ForeignKeyRawIdWidget, self).render(name, value, attrs)]
117 117
         # TODO: "id_" is hard-coded here. This should instead use the correct
4  django/db/models/query.py
@@ -864,9 +864,9 @@ def _setup_query(self):
864 864
                     # we inspect the full extra_select list since we might
865 865
                     # be adding back an extra select item that we hadn't
866 866
                     # had selected previously.
867  
-                    if self.query.extra.has_key(f):
  867
+                    if f in self.query.extra:
868 868
                         self.extra_names.append(f)
869  
-                    elif self.query.aggregate_select.has_key(f):
  869
+                    elif f in self.query.aggregate_select:
870 870
                         self.aggregate_names.append(f)
871 871
                     else:
872 872
                         self.field_names.append(f)

0 notes on commit c38a174

Please sign in to comment.
Something went wrong with that request. Please try again.