Procházet zdrojové kódy

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 před 11 roky
rodič
revize
4d871d98e2

+ 6
- 0
oscar/apps/address/models.py Zobrazit soubor

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

+ 10
- 0
oscar/apps/analytics/models.py Zobrazit soubor

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

+ 10
- 0
oscar/apps/basket/models.py Zobrazit soubor

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

+ 24
- 0
oscar/apps/catalogue/models.py Zobrazit soubor

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

+ 10
- 0
oscar/apps/customer/models.py Zobrazit soubor

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

+ 29
- 0
oscar/apps/order/models.py Zobrazit soubor

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

+ 10
- 0
oscar/apps/partner/models.py Zobrazit soubor

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

+ 10
- 0
oscar/apps/payment/models.py Zobrazit soubor

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

+ 8
- 0
oscar/apps/shipping/models.py Zobrazit soubor

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

+ 6
- 0
oscar/apps/voucher/models.py Zobrazit soubor

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

+ 6
- 0
oscar/apps/wishlists/models.py Zobrazit soubor

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

Načítá se…
Zrušit
Uložit