Sfoglia il codice sorgente

Add __all__ to models module of overridable apps

Since the recommended way to override models within an app is to add
‘from oscar.apps.order.models import *’ we need to limit what is 
exported otherwise subtle bugs may occur in the users code.

Simply defining __all__ [‘Model1’, ‘Model2’] doesn’t work since Django
will raise an AppRegistryNotReady exception for all models listed in
the __all__ list but are not available. Dynamically building the list
solves this.
master
Michael van Tellingen 11 anni fa
parent
commit
4d871d98e2

+ 6
- 0
oscar/apps/address/models.py Vedi File

@@ -2,12 +2,18 @@ from oscar.core.loading import is_model_registered
2 2
 from oscar.apps.address.abstract_models import (
3 3
     AbstractUserAddress, AbstractCountry)
4 4
 
5
+__all__ = []
6
+
5 7
 
6 8
 if not is_model_registered('address', 'UserAddress'):
7 9
     class UserAddress(AbstractUserAddress):
8 10
         pass
9 11
 
12
+    __all__.append('UserAddress')
13
+
10 14
 
11 15
 if not is_model_registered('address', 'Country'):
12 16
     class Country(AbstractCountry):
13 17
         pass
18
+
19
+    __all__.append('Country')

+ 10
- 0
oscar/apps/analytics/models.py Vedi File

@@ -5,26 +5,36 @@ from oscar.apps.analytics.abstract_models import (
5 5
     AbstractProductRecord, AbstractUserRecord,
6 6
     AbstractUserProductView, AbstractUserSearch)
7 7
 
8
+__all__ = []
9
+
8 10
 
9 11
 if not is_model_registered('analytics', 'ProductRecord'):
10 12
     class ProductRecord(AbstractProductRecord):
11 13
         pass
12 14
 
15
+    __all__.append('ProductRecord')
16
+
13 17
 
14 18
 if not is_model_registered('analytics', 'UserRecord'):
15 19
     class UserRecord(AbstractUserRecord):
16 20
         pass
17 21
 
22
+    __all__.append('UserRecord')
23
+
18 24
 
19 25
 if not is_model_registered('analytics', 'UserProductView'):
20 26
     class UserProductView(AbstractUserProductView):
21 27
         pass
22 28
 
29
+    __all__.append('UserProductView')
30
+
23 31
 
24 32
 if not is_model_registered('analytics', 'UserSearch'):
25 33
     class UserSearch(AbstractUserSearch):
26 34
         pass
27 35
 
36
+    __all__.append('UserSearch')
37
+
28 38
 
29 39
 if django.VERSION < (1, 7):
30 40
     from . import receivers  # noqa

+ 10
- 0
oscar/apps/basket/models.py Vedi File

@@ -2,6 +2,10 @@ from oscar.core.loading import is_model_registered
2 2
 from oscar.apps.basket.abstract_models import (
3 3
     AbstractBasket, AbstractLine, AbstractLineAttribute)
4 4
 
5
+__all__ = [
6
+    'InvalidBasketLineError',
7
+]
8
+
5 9
 
6 10
 class InvalidBasketLineError(Exception):
7 11
     pass
@@ -11,12 +15,18 @@ if not is_model_registered('basket', 'Basket'):
11 15
     class Basket(AbstractBasket):
12 16
         pass
13 17
 
18
+    __all__.append('Basket')
19
+
14 20
 
15 21
 if not is_model_registered('basket', 'Line'):
16 22
     class Line(AbstractLine):
17 23
         pass
18 24
 
25
+    __all__.append('Line')
26
+
19 27
 
20 28
 if not is_model_registered('basket', 'LineAttribute'):
21 29
     class LineAttribute(AbstractLineAttribute):
22 30
         pass
31
+
32
+    __all__.append('LineAttribute')

+ 24
- 0
oscar/apps/catalogue/models.py Vedi File

@@ -6,61 +6,85 @@ Vanilla product models
6 6
 from oscar.core.loading import is_model_registered
7 7
 from oscar.apps.catalogue.abstract_models import *  # noqa
8 8
 
9
+__all__ = []
10
+
9 11
 
10 12
 if not is_model_registered('catalogue', 'ProductClass'):
11 13
     class ProductClass(AbstractProductClass):
12 14
         pass
13 15
 
16
+    __all__.append('ProductClass')
17
+
14 18
 
15 19
 if not is_model_registered('catalogue', 'Category'):
16 20
     class Category(AbstractCategory):
17 21
         pass
18 22
 
23
+    __all__.append('Category')
24
+
19 25
 
20 26
 if not is_model_registered('catalogue', 'ProductCategory'):
21 27
     class ProductCategory(AbstractProductCategory):
22 28
         pass
23 29
 
30
+    __all__.append('ProductCategory')
31
+
24 32
 
25 33
 if not is_model_registered('catalogue', 'Product'):
26 34
     class Product(AbstractProduct):
27 35
         pass
28 36
 
37
+    __all__.append('Product')
38
+
29 39
 
30 40
 if not is_model_registered('catalogue', 'ProductRecommendation'):
31 41
     class ProductRecommendation(AbstractProductRecommendation):
32 42
         pass
33 43
 
44
+    __all__.append('ProductRecommendation')
45
+
34 46
 
35 47
 if not is_model_registered('catalogue', 'ProductAttribute'):
36 48
     class ProductAttribute(AbstractProductAttribute):
37 49
         pass
38 50
 
51
+    __all__.append('ProductAttribute')
52
+
39 53
 
40 54
 if not is_model_registered('catalogue', 'ProductAttributeValue'):
41 55
     class ProductAttributeValue(AbstractProductAttributeValue):
42 56
         pass
43 57
 
58
+    __all__.append('ProductAttributeValue')
59
+
44 60
 
45 61
 if not is_model_registered('catalogue', 'AttributeOptionGroup'):
46 62
     class AttributeOptionGroup(AbstractAttributeOptionGroup):
47 63
         pass
48 64
 
65
+    __all__.append('AttributeOptionGroup')
66
+
49 67
 
50 68
 if not is_model_registered('catalogue', 'AttributeOption'):
51 69
     class AttributeOption(AbstractAttributeOption):
52 70
         pass
53 71
 
72
+    __all__.append('AttributeOption')
73
+
54 74
 
55 75
 if not is_model_registered('catalogue', 'Option'):
56 76
     class Option(AbstractOption):
57 77
         pass
58 78
 
79
+    __all__.append('Option')
80
+
59 81
 
60 82
 if not is_model_registered('catalogue', 'ProductImage'):
61 83
     class ProductImage(AbstractProductImage):
62 84
         pass
63 85
 
86
+    __all__.append('ProductImage')
87
+
64 88
 
65 89
 if django.VERSION < (1, 7):
66 90
     from . import receivers  # noqa

+ 10
- 0
oscar/apps/customer/models.py Vedi File

@@ -3,27 +3,37 @@ import django
3 3
 from oscar.core.loading import is_model_registered
4 4
 from oscar.apps.customer import abstract_models
5 5
 
6
+__all__ = []
7
+
6 8
 
7 9
 if not is_model_registered('customer', 'Email'):
8 10
     class Email(abstract_models.AbstractEmail):
9 11
         pass
10 12
 
13
+    __all__.append('Email')
14
+
11 15
 
12 16
 if not is_model_registered('customer', 'CommunicationEventType'):
13 17
     class CommunicationEventType(
14 18
             abstract_models.AbstractCommunicationEventType):
15 19
         pass
16 20
 
21
+    __all__.append('CommunicationEventType')
22
+
17 23
 
18 24
 if not is_model_registered('customer', 'Notification'):
19 25
     class Notification(abstract_models.AbstractNotification):
20 26
         pass
21 27
 
28
+    __all__.append('Notification')
29
+
22 30
 
23 31
 if not is_model_registered('customer', 'ProductAlert'):
24 32
     class ProductAlert(abstract_models.AbstractProductAlert):
25 33
         pass
26 34
 
35
+    __all__.append('ProductAlert')
36
+
27 37
 
28 38
 if django.VERSION < (1, 7):
29 39
     from .receivers import *  # noqa

+ 29
- 0
oscar/apps/order/models.py Vedi File

@@ -3,66 +3,95 @@ from oscar.apps.order.abstract_models import *  # noqa
3 3
 from oscar.apps.address.abstract_models import (AbstractShippingAddress,
4 4
                                                 AbstractBillingAddress)
5 5
 
6
+__all__ = []
7
+
8
+
6 9
 if not is_model_registered('order', 'Order'):
7 10
     class Order(AbstractOrder):
8 11
         pass
9 12
 
13
+    __all__.append('Order')
14
+
10 15
 
11 16
 if not is_model_registered('order', 'OrderNote'):
12 17
     class OrderNote(AbstractOrderNote):
13 18
         pass
14 19
 
20
+    __all__.append('OrderNote')
21
+
15 22
 
16 23
 if not is_model_registered('order', 'CommunicationEvent'):
17 24
     class CommunicationEvent(AbstractCommunicationEvent):
18 25
         pass
19 26
 
27
+    __all__.append('CommunicationEvent')
28
+
20 29
 
21 30
 if not is_model_registered('order', 'ShippingAddress'):
22 31
     class ShippingAddress(AbstractShippingAddress):
23 32
         pass
24 33
 
34
+    __all__.append('ShippingAddress')
35
+
25 36
 
26 37
 if not is_model_registered('order', 'BillingAddress'):
27 38
     class BillingAddress(AbstractBillingAddress):
28 39
         pass
29 40
 
41
+    __all__.append('BillingAddress')
42
+
30 43
 
31 44
 if not is_model_registered('order', 'Line'):
32 45
     class Line(AbstractLine):
33 46
         pass
34 47
 
48
+    __all__.append('Line')
49
+
35 50
 
36 51
 if not is_model_registered('order', 'LinePrice'):
37 52
     class LinePrice(AbstractLinePrice):
38 53
         pass
39 54
 
55
+    __all__.append('LinePrice')
56
+
40 57
 
41 58
 if not is_model_registered('order', 'LineAttribute'):
42 59
     class LineAttribute(AbstractLineAttribute):
43 60
         pass
44 61
 
62
+    __all__.append('LineAttribute')
63
+
45 64
 
46 65
 if not is_model_registered('order', 'ShippingEvent'):
47 66
     class ShippingEvent(AbstractShippingEvent):
48 67
         pass
49 68
 
69
+    __all__.append('ShippingEvent')
70
+
50 71
 
51 72
 if not is_model_registered('order', 'ShippingEventType'):
52 73
     class ShippingEventType(AbstractShippingEventType):
53 74
         pass
54 75
 
76
+    __all__.append('ShippingEventType')
77
+
55 78
 
56 79
 if not is_model_registered('order', 'PaymentEvent'):
57 80
     class PaymentEvent(AbstractPaymentEvent):
58 81
         pass
59 82
 
83
+    __all__.append('PaymentEvent')
84
+
60 85
 
61 86
 if not is_model_registered('order', 'PaymentEventType'):
62 87
     class PaymentEventType(AbstractPaymentEventType):
63 88
         pass
64 89
 
90
+    __all__.append('PaymentEventType')
91
+
65 92
 
66 93
 if not is_model_registered('order', 'OrderDiscount'):
67 94
     class OrderDiscount(AbstractOrderDiscount):
68 95
         pass
96
+
97
+    __all__.append('OrderDiscount')

+ 10
- 0
oscar/apps/partner/models.py Vedi File

@@ -5,26 +5,36 @@ from oscar.apps.address.abstract_models import AbstractPartnerAddress
5 5
 from oscar.apps.partner.abstract_models import (
6 6
     AbstractPartner, AbstractStockRecord, AbstractStockAlert)
7 7
 
8
+__all__ = []
9
+
8 10
 
9 11
 if not is_model_registered('partner', 'Partner'):
10 12
     class Partner(AbstractPartner):
11 13
         pass
12 14
 
15
+    __all__.append('PartnerAddress')
16
+
13 17
 
14 18
 if not is_model_registered('partner', 'PartnerAddress'):
15 19
     class PartnerAddress(AbstractPartnerAddress):
16 20
         pass
17 21
 
22
+    __all__.append('PartnerAddress')
23
+
18 24
 
19 25
 if not is_model_registered('partner', 'StockRecord'):
20 26
     class StockRecord(AbstractStockRecord):
21 27
         pass
22 28
 
29
+    __all__.append('StockRecord')
30
+
23 31
 
24 32
 if not is_model_registered('partner', 'StockAlert'):
25 33
     class StockAlert(AbstractStockAlert):
26 34
         pass
27 35
 
36
+    __all__.append('StockAlert')
37
+
28 38
 
29 39
 if django.VERSION < (1, 7):
30 40
     from . import receivers  # noqa

+ 10
- 0
oscar/apps/payment/models.py Vedi File

@@ -2,22 +2,32 @@ from oscar.core.loading import is_model_registered
2 2
 
3 3
 from . import abstract_models
4 4
 
5
+__all__ = []
6
+
5 7
 
6 8
 if not is_model_registered('payment', 'Transaction'):
7 9
     class Transaction(abstract_models.AbstractTransaction):
8 10
         pass
9 11
 
12
+    __all__.append('Transaction')
13
+
10 14
 
11 15
 if not is_model_registered('payment', 'Source'):
12 16
     class Source(abstract_models.AbstractSource):
13 17
         pass
14 18
 
19
+    __all__.append('Source')
20
+
15 21
 
16 22
 if not is_model_registered('payment', 'SourceType'):
17 23
     class SourceType(abstract_models.AbstractSourceType):
18 24
         pass
19 25
 
26
+    __all__.append('SourceType')
27
+
20 28
 
21 29
 if not is_model_registered('payment', 'Bankcard'):
22 30
     class Bankcard(abstract_models.AbstractBankcard):
23 31
         pass
32
+
33
+    __all__.append('Bankcard')

+ 8
- 0
oscar/apps/shipping/models.py Vedi File

@@ -1,17 +1,25 @@
1 1
 from oscar.core.loading import is_model_registered
2 2
 from oscar.apps.shipping import abstract_models
3 3
 
4
+__all__ = []
5
+
4 6
 
5 7
 if not is_model_registered('shipping', 'OrderAndItemCharges'):
6 8
     class OrderAndItemCharges(abstract_models.AbstractOrderAndItemCharges):
7 9
         pass
8 10
 
11
+    __all__.append('OrderAndItemCharges')
12
+
9 13
 
10 14
 if not is_model_registered('shipping', 'WeightBased'):
11 15
     class WeightBased(abstract_models.AbstractWeightBased):
12 16
         pass
13 17
 
18
+    __all__.append('WeightBased')
19
+
14 20
 
15 21
 if not is_model_registered('shipping', 'WeightBand'):
16 22
     class WeightBand(abstract_models.AbstractWeightBand):
17 23
         pass
24
+
25
+    __all__.append('WeightBand')

+ 6
- 0
oscar/apps/voucher/models.py Vedi File

@@ -4,16 +4,22 @@ from oscar.core.loading import is_model_registered
4 4
 from oscar.apps.voucher.abstract_models import (
5 5
     AbstractVoucher, AbstractVoucherApplication)
6 6
 
7
+__all__ = []
8
+
7 9
 
8 10
 if not is_model_registered('voucher', 'Voucher'):
9 11
     class Voucher(AbstractVoucher):
10 12
         pass
11 13
 
14
+    __all__.append('Voucher')
15
+
12 16
 
13 17
 if not is_model_registered('voucher', 'VoucherApplication'):
14 18
     class VoucherApplication(AbstractVoucherApplication):
15 19
         pass
16 20
 
21
+    __all__.append('VoucherApplication')
22
+
17 23
 
18 24
 if django.VERSION < (1, 7):
19 25
     from . import receivers  # noqa

+ 6
- 0
oscar/apps/wishlists/models.py Vedi File

@@ -3,12 +3,18 @@ from oscar.core.loading import is_model_registered
3 3
 
4 4
 from .abstract_models import *  # noqa
5 5
 
6
+__all__ = []
7
+
6 8
 
7 9
 if not is_model_registered('wishlists', 'WishList'):
8 10
     class WishList(AbstractWishList):
9 11
         pass
10 12
 
13
+    __all__.append('WishList')
14
+
11 15
 
12 16
 if not is_model_registered('wishlists', 'Line'):
13 17
     class Line(AbstractLine):
14 18
         pass
19
+
20
+    __all__.append('Line')

Loading…
Annulla
Salva