Преглед на файлове

Remove further Django 1.6 code paths

The changes should be obvious and non-controversial. Under Django 1.7+,
the AppConfig is used to register signal receivers instead of just
registering then when models are registered.
master
Maik Hoepfel преди 10 години
родител
ревизия
e0e6fb1eeb

+ 2
- 22
src/oscar/app.py Целия файл

@@ -1,12 +1,10 @@
1 1
 # flake8: noqa, because URL syntax is more readable with long lines
2 2
 
3
-import django
4 3
 from django.conf.urls import url, include
5 4
 from django.contrib.auth import views as auth_views
6 5
 from django.core.urlresolvers import reverse_lazy
7 6
 
8 7
 from oscar.core.application import Application
9
-from oscar.apps.customer import forms
10 8
 from oscar.core.loading import get_class
11 9
 from oscar.views.decorators import login_forbidden
12 10
 
@@ -46,32 +44,14 @@ class Shop(Application):
46 44
                 name='password-reset'),
47 45
             url(r'^password-reset/done/$',
48 46
                 login_forbidden(auth_views.password_reset_done),
49
-                name='password-reset-done')]
50
-
51
-        # Django <=1.5: uses uidb36 to encode the user's primary key (support
52
-        #               has been removed)
53
-        # Django 1.6:   uses uidb64 to encode the user's primary key, but
54
-        #               supports legacy links
55
-        # Django > 1.7: used uidb64 to encode the user's primary key
56
-        # see https://docs.djangoproject.com/en/dev/releases/1.6/#django-contrib-auth-password-reset-uses-base-64-encoding-of-user-pk
57
-        urls.append(
47
+                name='password-reset-done'),
58 48
             url(r'^password-reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
59 49
                 login_forbidden(auth_views.password_reset_confirm),
60 50
                 {
61 51
                     'post_reset_redirect': reverse_lazy('password-reset-complete'),
62 52
                     'set_password_form': self.set_password_form,
63 53
                 },
64
-                name='password-reset-confirm'))
65
-        if django.VERSION < (1, 7):
66
-            urls.append(
67
-                url(r'^password-reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
68
-                    login_forbidden(auth_views.password_reset_confirm_uidb36),
69
-                    {
70
-                        'post_reset_redirect': reverse_lazy('password-reset-complete'),
71
-                        'set_password_form': self.set_password_form,
72
-                    }))
73
-
74
-        urls += [
54
+                name='password-reset-confirm'),
75 55
             url(r'^password-reset/complete/$',
76 56
                 login_forbidden(auth_views.password_reset_complete),
77 57
                 name='password-reset-complete'),

+ 0
- 6
src/oscar/apps/analytics/models.py Целия файл

@@ -1,5 +1,3 @@
1
-import django
2
-
3 1
 from oscar.core.loading import is_model_registered
4 2
 from oscar.apps.analytics.abstract_models import (
5 3
     AbstractProductRecord, AbstractUserRecord,
@@ -34,7 +32,3 @@ if not is_model_registered('analytics', 'UserSearch'):
34 32
         pass
35 33
 
36 34
     __all__.append('UserSearch')
37
-
38
-
39
-if django.VERSION < (1, 7):
40
-    from . import receivers  # noqa

+ 0
- 6
src/oscar/apps/catalogue/models.py Целия файл

@@ -1,5 +1,3 @@
1
-import django
2
-
3 1
 """
4 2
 Vanilla product models
5 3
 """
@@ -84,7 +82,3 @@ if not is_model_registered('catalogue', 'ProductImage'):
84 82
         pass
85 83
 
86 84
     __all__.append('ProductImage')
87
-
88
-
89
-if django.VERSION < (1, 7):
90
-    from . import receivers  # noqa

+ 2
- 8
src/oscar/apps/customer/history.py Целия файл

@@ -1,11 +1,10 @@
1 1
 import json
2 2
 
3 3
 from django.conf import settings
4
-from oscar.core.loading import get_model
5
-
6
-from oscar.core.loading import get_class
4
+from oscar.core.loading import get_model, get_class
7 5
 
8 6
 product_viewed = get_class('catalogue.signals', 'product_viewed')
7
+Product = get_model('catalogue', 'Product')
9 8
 
10 9
 
11 10
 def get(request):
@@ -14,11 +13,6 @@ def get(request):
14 13
     """
15 14
     ids = extract(request)
16 15
 
17
-    # Needs to live in local scope because receivers in this module get
18
-    # registered during model initialisation
19
-    # TODO Move this back to global scope once Django < 1.7 support is removed
20
-    Product = get_model('catalogue', 'Product')
21
-
22 16
     # Reordering as the ID order gets messed up in the query
23 17
     product_dict = Product.browsable.in_bulk(ids)
24 18
     ids.reverse()

+ 0
- 7
src/oscar/apps/customer/models.py Целия файл

@@ -1,5 +1,3 @@
1
-import django
2
-
3 1
 from oscar.core.loading import is_model_registered
4 2
 from oscar.apps.customer import abstract_models
5 3
 
@@ -33,8 +31,3 @@ if not is_model_registered('customer', 'ProductAlert'):
33 31
         pass
34 32
 
35 33
     __all__.append('ProductAlert')
36
-
37
-
38
-if django.VERSION < (1, 7):
39
-    from .receivers import *  # noqa
40
-    from .alerts import receivers  # noqa

+ 0
- 6
src/oscar/apps/partner/models.py Целия файл

@@ -1,5 +1,3 @@
1
-import django
2
-
3 1
 from oscar.core.loading import is_model_registered
4 2
 from oscar.apps.address.abstract_models import AbstractPartnerAddress
5 3
 from oscar.apps.partner.abstract_models import (
@@ -34,7 +32,3 @@ if not is_model_registered('partner', 'StockAlert'):
34 32
         pass
35 33
 
36 34
     __all__.append('StockAlert')
37
-
38
-
39
-if django.VERSION < (1, 7):
40
-    from . import receivers  # noqa

+ 0
- 6
src/oscar/apps/voucher/models.py Целия файл

@@ -1,5 +1,3 @@
1
-import django
2
-
3 1
 from oscar.core.loading import is_model_registered
4 2
 from oscar.apps.voucher.abstract_models import (
5 3
     AbstractVoucher, AbstractVoucherApplication)
@@ -19,7 +17,3 @@ if not is_model_registered('voucher', 'VoucherApplication'):
19 17
         pass
20 18
 
21 19
     __all__.append('VoucherApplication')
22
-
23
-
24
-if django.VERSION < (1, 7):
25
-    from . import receivers  # noqa

+ 0
- 9
src/oscar/core/phonenumber.py Целия файл

@@ -68,15 +68,6 @@ class PhoneNumber(phonenumbers.phonenumber.PhoneNumber):
68 68
             return self.format_as(fmt)
69 69
         return self.raw_input
70 70
 
71
-    def __unicode__(self):
72
-        # Django calls force_text on PhoneNumber instances when populating
73
-        # a model form. Django 1.6's force_text implementation unfortunately
74
-        # checks for __unicode__ first, which is defined in the base class.
75
-        # As we're using the python_2_unicode_compatible decorator, in Python 2
76
-        # __unicode__ is already overwritten by the decorator.
77
-        # In Python 3, we can safely return __str__ because it returns unicode.
78
-        return self.__str__()
79
-
80 71
     def is_valid(self):
81 72
         """
82 73
         checks whether the number supplied is actually valid

+ 0
- 1
tests/_site/myauth/models.py Целия файл

@@ -1,6 +1,5 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-# Code will only work with Django >= 1.5. See tests/config.py
4 3
 import re
5 4
 
6 5
 from django.utils.translation import ugettext_lazy as _

+ 3
- 4
tests/config.py Целия файл

@@ -1,8 +1,7 @@
1 1
 #!/usr/bin/env python
2 2
 import os
3
-import django
4 3
 
5
-from django.conf import settings, global_settings
4
+from django.conf import settings
6 5
 import oscar
7 6
 
8 7
 
@@ -120,11 +119,11 @@ def configure():
120 119
 
121 120
 if __name__ == '__main__':
122 121
     import sys
122
+    import django
123 123
     from django.core.management import call_command
124 124
     args = sys.argv[1:]
125 125
 
126 126
     if args:
127 127
         configure()  # configure Django settings
128
-        if hasattr(django, 'setup'):
129
-            django.setup()  # initialise app registry for Django 1.7+
128
+        django.setup()  # initialise app registry for Django 1.7+
130 129
         call_command(*args)

+ 0
- 5
tests/unit/core/compat_tests.py Целия файл

@@ -2,9 +2,7 @@
2 2
 import datetime
3 3
 from django.utils import six
4 4
 from django.utils.six.moves import cStringIO
5
-import unittest
6 5
 
7
-import django
8 6
 from django.test import TestCase
9 7
 
10 8
 from oscar.core.compat import UnicodeCSVWriter, existing_user_fields
@@ -33,9 +31,6 @@ class TestUnicodeCSVWriter(TestCase):
33 31
 
34 32
 class TestPython3Compatibility(TestCase):
35 33
 
36
-    @unittest.skipIf(
37
-        django.VERSION < (1, 7),
38
-        "Oscar only supports Python 3 with Django 1.7+")
39 34
     def test_models_define_python_3_compatible_representation(self):
40 35
         """
41 36
         In Python 2, models can define __unicode__ to get a text representation,

+ 0
- 3
tests/unit/core/loading_tests.py Целия файл

@@ -1,7 +1,5 @@
1 1
 from os.path import dirname
2
-import unittest
3 2
 
4
-import django
5 3
 from django.test import TestCase
6 4
 from django.conf import settings
7 5
 from django.test.utils import override_settings
@@ -138,7 +136,6 @@ class TestOverridingCoreApps(TestCase):
138 136
                           klass.__module__)
139 137
 
140 138
 
141
-@unittest.skipIf(django.VERSION < (1, 7), "Django 1.7 introduced app registry")
142 139
 class TestAppLabelsForModels(TestCase):
143 140
 
144 141
     def test_all_oscar_models_have_app_labels(self):

Loading…
Отказ
Запис