Pārlūkot izejas kodu

Changes around six usage

Discussion around #1200 highlighted that we must be aware of differences
between the versions of six that Django ships and the one we use.

In general, the external version of six is the best choice for Oscar,
because it allows to depend on a specific version of six. The multiple
Django versions we support each come with different versions of six,
which makes it unattractive to depend on them.

When interfacing directly with Django, it should be decided on a
case-by-case basis if it's more appropriate to use Django's supplied
version of six or the external one.

In the case of the UppercaseCharField, Django clearly documents what
needs to be done to get it to work with both Python 2 and 3 in
https://docs.djangoproject.com/en/1.6/howto/custom-model-fields/#the-subfieldbase-metaclass
Those instructions are the same for all versions of Django we support.
Hence it's been decided that it's best to switch to Django's recommended
way of declaring the metaclass, and using Django's version of six for
it.
master
Maik Hoepfel 12 gadus atpakaļ
vecāks
revīzija
5a36d49b77
3 mainītis faili ar 13 papildinājumiem un 7 dzēšanām
  1. 2
    2
      oscar/core/compat.py
  2. 7
    4
      oscar/models/fields.py
  3. 4
    1
      setup.py

+ 2
- 2
oscar/core/compat.py Parādīt failu

@@ -1,10 +1,10 @@
1
+import six
2
+from six.moves import map
1 3
 from django.conf import settings
2 4
 from django.contrib.auth.models import User
3 5
 from django.core.exceptions import ImproperlyConfigured
4
-from django.utils import six
5 6
 from django.utils.html import conditional_escape
6 7
 from django.utils.safestring import mark_safe
7
-from six.moves import map
8 8
 
9 9
 
10 10
 def get_user_model():

+ 7
- 4
oscar/models/fields.py Parādīt failu

@@ -1,7 +1,9 @@
1
+import six
2
+
1 3
 from django.core.exceptions import ImproperlyConfigured
2 4
 from django.db.models.fields import CharField, DecimalField, Field
3 5
 from django.db.models import SubfieldBase
4
-from django.utils import six
6
+from django.utils import six as django_six
5 7
 from django.utils.translation import ugettext_lazy as _
6 8
 from django.core.validators import MaxLengthValidator
7 9
 
@@ -62,12 +64,13 @@ class PositiveDecimalField(DecimalField):
62 64
         return super(PositiveDecimalField, self).formfield(min_value=0)
63 65
 
64 66
 
65
-# necessary for to_python to be called
66
-@six.add_metaclass(SubfieldBase)
67
-class UppercaseCharField(CharField):
67
+class UppercaseCharField(django_six.with_metaclass(SubfieldBase, CharField)):
68 68
     """
69 69
     A simple subclass of ``django.db.models.fields.CharField`` that
70 70
     restricts all text to be uppercase.
71
+
72
+    Defined with the with_metaclass helper so that to_python is called
73
+    https://docs.djangoproject.com/en/1.6/howto/custom-model-fields/#the-subfieldbase-metaclass  # NOQA
71 74
     """
72 75
 
73 76
     def to_python(self, value):

+ 4
- 1
setup.py Parādīt failu

@@ -43,6 +43,7 @@ setup(name='django-oscar',
43 43
           # We use the ModelFormSetView from django-extra-views for the basket
44 44
           # page
45 45
           'django-extra-views>=0.2,<0.7',
46
+          # Search support
46 47
           'django-haystack>=2.1.0',
47 48
           # Treebeard is used for categories
48 49
           'django-treebeard==2.0b2',
@@ -58,7 +59,9 @@ setup(name='django-oscar',
58 59
           # For manipulating search URLs
59 60
           'purl>=0.7',
60 61
           # For phone number field
61
-          'phonenumbers==5.9.2'
62
+          'phonenumbers==5.9.2',
63
+          # Python 2 & 3 compatibility helper
64
+          'six>=1.5.2',
62 65
       ],
63 66
       # tarballs for unreleased packages
64 67
       dependency_links = [

Notiek ielāde…
Atcelt
Saglabāt