Parcourir la source

Python 3: Handle dict-like objects

Calls to items() and values() return an iterator in Python 3. This
commit converts the result to a list if necessary. In some instances,
using the six helpers was not necessary and has been removed.

See also:
https://docs.djangoproject.com/en/dev/topics/python3/#dict-and-dict-like-classes
master
Maik Hoepfel il y a 11 ans
Parent
révision
ba0bb76254

+ 1
- 1
oscar/apps/basket/views.py Voir le fichier

@@ -121,7 +121,7 @@ class BasketView(ModelFormSetView):
121 121
 
122 122
     def get_upsell_messages(self, basket):
123 123
         offers = Applicator().get_offers(self.request, basket)
124
-        applied_offers = basket.offer_applications.offers.values()
124
+        applied_offers = list(basket.offer_applications.offers.values())
125 125
         msgs = []
126 126
         for offer in offers:
127 127
             if offer.is_condition_partially_satisfied(basket) \

+ 1
- 1
oscar/apps/catalogue/abstract_models.py Voir le fichier

@@ -655,7 +655,7 @@ class ProductAttributesContainer(object):
655 655
 
656 656
     def __getattr__(self, name):
657 657
         if not name.startswith('_') and not self.initialised:
658
-            values = list(self.get_values().select_related('attribute'))
658
+            values = self.get_values().select_related('attribute')
659 659
             for v in values:
660 660
                 setattr(self, v.attribute.code, v.value)
661 661
             self.initialised = True

+ 1
- 1
oscar/apps/customer/forms.py Voir le fichier

@@ -310,7 +310,7 @@ if Profile:
310 310
             super(UserAndProfileForm, self).__init__(*args, **kwargs)
311 311
 
312 312
             # Get profile field names to help with ordering later
313
-            profile_field_names = self.fields.keys()
313
+            profile_field_names = list(self.fields.keys())
314 314
 
315 315
             # Get user field names (we look for core user fields first)
316 316
             core_field_names = set([f.name for f in User._meta.fields])

+ 2
- 4
oscar/apps/dashboard/catalogue/views.py Voir le fichier

@@ -1,5 +1,3 @@
1
-import six
2
-
3 1
 from django.core.exceptions import ObjectDoesNotExist
4 2
 from django.views import generic
5 3
 from django.db.models import Q
@@ -233,7 +231,7 @@ class ProductCreateUpdateView(generic.UpdateView):
233 231
         ctx = super(ProductCreateUpdateView, self).get_context_data(**kwargs)
234 232
         ctx['product_class'] = self.product_class
235 233
 
236
-        for ctx_name, formset_class in six.iteritems(self.formsets):
234
+        for ctx_name, formset_class in self.formsets.items():
237 235
             if ctx_name not in ctx:
238 236
                 ctx[ctx_name] = formset_class(self.product_class,
239 237
                                               self.request.user,
@@ -261,7 +259,7 @@ class ProductCreateUpdateView(generic.UpdateView):
261 259
             self.object = form.save()
262 260
 
263 261
         formsets = {}
264
-        for ctx_name, formset_class in six.iteritems(self.formsets):
262
+        for ctx_name, formset_class in self.formsets.items():
265 263
             formsets[ctx_name] = formset_class(self.product_class,
266 264
                                                self.request.user,
267 265
                                                self.request.POST,

+ 1
- 0
oscar/apps/offer/custom.py Voir le fichier

@@ -36,6 +36,7 @@ def create_range(range_class):
36 36
     except Range.DoesNotExist:
37 37
         obj = Range(**values)
38 38
     else:
39
+        # Using iteritems because the range could potentially be rather big
39 40
         for key, value in six.iteritems(values):
40 41
             setattr(obj, key, value)
41 42
     obj.save()

+ 2
- 2
oscar/apps/order/abstract_models.py Voir le fichier

@@ -97,7 +97,7 @@ class AbstractOrder(models.Model):
97 97
         """
98 98
         Return all possible statuses for an order
99 99
         """
100
-        return cls.pipeline.keys()
100
+        return list(cls.pipeline.keys())
101 101
 
102 102
     def available_statuses(self):
103 103
         """
@@ -497,7 +497,7 @@ class AbstractLine(models.Model):
497 497
         """
498 498
         Return all possible statuses for an order line
499 499
         """
500
-        return cls.pipeline.keys()
500
+        return list(cls.pipeline.keys())
501 501
 
502 502
     def available_statuses(self):
503 503
         """

+ 1
- 3
oscar/core/application.py Voir le fichier

@@ -1,5 +1,3 @@
1
-import six
2
-
3 1
 from oscar.core.loading import feature_hidden
4 2
 from oscar.views.decorators import permissions_required
5 3
 
@@ -26,7 +24,7 @@ class Application(object):
26 24
     def __init__(self, app_name=None, **kwargs):
27 25
         self.app_name = app_name
28 26
         # Set all kwargs as object attributes
29
-        for key, value in six.iteritems(kwargs):
27
+        for key, value in kwargs.items():
30 28
             setattr(self, key, value)
31 29
 
32 30
     def get_urls(self):

+ 2
- 2
oscar/forms/widgets.py Voir le fichier

@@ -73,7 +73,7 @@ def datetime_format_to_js_date_format(format):
73 73
         '%d': 'dd',
74 74
         '%H:%M': '',
75 75
     }
76
-    for search, replace in six.iteritems(replacements):
76
+    for search, replace in replacements.items():
77 77
         converted = converted.replace(search, replace)
78 78
     return converted.strip()
79 79
 
@@ -91,7 +91,7 @@ def datetime_format_to_js_time_format(format):
91 91
         '%H': 'HH',
92 92
         '%M': 'mm',
93 93
     }
94
-    for search, replace in six.iteritems(replacements):
94
+    for search, replace in replacements.items():
95 95
         converted = converted.replace(search, replace)
96 96
 
97 97
     converted = re.sub('[-/][^%]', '', converted)

+ 1
- 3
oscar/templatetags/image_tags.py Voir le fichier

@@ -1,5 +1,3 @@
1
-import six
2
-
3 1
 from django import template
4 2
 from django.conf import settings
5 3
 from django.db.models.fields.files import ImageFieldFile
@@ -50,7 +48,7 @@ class DynamicImageNode(template.Node):
50 48
             ext = path[path.rfind('.') + 1:]
51 49
             ext_changed = False
52 50
 
53
-            for key, v in six.iteritems(self.params):
51
+            for key, v in self.params.items():
54 52
                 value = v.resolve(context)
55 53
                 if key == u'format':
56 54
                     ext = value

Chargement…
Annuler
Enregistrer