forked from awesto/django-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf.py
290 lines (240 loc) · 11.7 KB
/
conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
class DefaultSettings(object):
def _setting(self, name, default=None):
from django.conf import settings
return getattr(settings, name, default)
@property
def SHOP_APP_LABEL(self):
"""
The name of the project implementing the shop, for instance ``myshop``.
This is required to assign the abstract shop models to a project. There is no default.
"""
from django.core.exceptions import ImproperlyConfigured
result = self._setting('SHOP_APP_LABEL')
if not result:
raise ImproperlyConfigured("SHOP_APP_LABEL setting must be set")
return result
@property
def SHOP_DEFAULT_CURRENCY(self):
"""
The default currency this shop is working with. The default is ``EUR``.
.. note:: All model- and form input fields can be specified for any other currency, this
setting is only used if the supplied currency is missing.
"""
return self._setting('SHOP_DEFAULT_CURRENCY', 'EUR')
@property
def SHOP_VENDOR_EMAIL(self):
"""
The vendor's email addresses, unless specified through the ``Order`` object.
"""
try:
default_email = self._setting('ADMINS')[0][1]
except IndexError:
default_email = None
return self._setting('SHOP_VENDOR_EMAIL', default_email)
@property
def SHOP_MONEY_FORMAT(self):
"""
When rendering an amount of type Money, use this format.
Possible placeholders are:
* ``{symbol}``: This is replaced by €, $, £, etc.
* ``{currency}``: This is replaced by Euro, US Dollar, Pound Sterling, etc.
* ``{code}``: This is replaced by EUR, USD, GBP, etc.
* ``{amount}``: The localized amount.
* ``{minus}``: Only for negative amounts, where to put the ``-`` sign.
For further information about formatting currency amounts, please refer to
https://docs.microsoft.com/en-us/globalization/locale/currency-formatting
"""
return self._setting('SHOP_MONEY_FORMAT', '{minus}{symbol} {amount}')
@property
def SHOP_DECIMAL_PLACES(self):
"""
Number of decimal places for the internal representation of a price.
This is purely used by the Django admin and is not the number of digits
visible by the customer.
Defaults to 2.
"""
return self._setting('SHOP_DECIMAL_PLACES', 2)
@property
def SHOP_CUSTOMER_SERIALIZER(self):
"""
Depending on the materialized customer model, use this directive to configure the
customer serializer.
Defaults to :class:`shop.serializers.defaults.customer.CustomerSerializer`.
"""
from django.core.exceptions import ImproperlyConfigured
from django.utils.module_loading import import_string
from shop.serializers.bases import BaseCustomerSerializer
s = self._setting('SHOP_CUSTOMER_SERIALIZER', 'shop.serializers.defaults.customer.CustomerSerializer')
CustomerSerializer = import_string(s)
if not issubclass(CustomerSerializer, BaseCustomerSerializer):
raise ImproperlyConfigured(
"Serializer class must inherit from 'BaseCustomerSerializer'.")
return CustomerSerializer
@property
def SHOP_PRODUCT_SUMMARY_SERIALIZER(self):
"""
Serialize the smallest common denominator of all Product models available in this shop.
This serialized data then is used for Catalog List Views, Cart List Views and Order List
Views.
Defaults to :class:`shop.serializers.defaults.product_summary.ProductSummarySerializer`.
"""
from django.core.exceptions import ImproperlyConfigured
from django.utils.module_loading import import_string
from shop.serializers.bases import ProductSerializer
s = self._setting('SHOP_PRODUCT_SUMMARY_SERIALIZER',
'shop.serializers.defaults.product_summary.ProductSummarySerializer')
ProductSummarySerializer = import_string(s)
if not issubclass(ProductSummarySerializer, ProductSerializer):
msg = "class {} specified in SHOP_PRODUCT_SUMMARY_SERIALIZER must inherit from 'ProductSerializer'."
raise ImproperlyConfigured(msg.format(s))
return ProductSummarySerializer
@property
def SHOP_PRODUCT_SELECT_SERIALIZER(self):
"""
This serializer is only used by the plugin editors, when selecting a product using a
drop down menu with auto-completion.
Defaults to :class:`shop.serializers.defaults.ProductSelectSerializer`.
"""
from django.utils.module_loading import import_string
s = self._setting('SHOP_PRODUCT_SELECT_SERIALIZER',
'shop.serializers.defaults.product_select.ProductSelectSerializer')
ProductSelectSerializer = import_string(s)
return ProductSelectSerializer
@property
def SHOP_LINK_TO_EMPTY_CART(self):
"""
If ``True`` the link on the cart-icon pointing to the cart is enabled, even if there are no
items are in the cart.
"""
return self._setting('SHOP_LINK_TO_EMPTY_CART', True)
@property
def SHOP_ORDER_ITEM_SERIALIZER(self):
"""
Depending on the materialized OrderItem model, use this directive to configure the
serializer.
Defaults to :class:`shop.serializers.defaults.OrderItemSerializer`.
"""
from django.core.exceptions import ImproperlyConfigured
from django.utils.module_loading import import_string
from shop.serializers.bases import BaseOrderItemSerializer
s = self._setting('SHOP_ORDER_ITEM_SERIALIZER',
'shop.serializers.defaults.order_item.OrderItemSerializer')
OrderItemSerializer = import_string(s)
if not issubclass(OrderItemSerializer, BaseOrderItemSerializer):
raise ImproperlyConfigured(
"Serializer class must inherit from 'BaseOrderItemSerializer'.")
return OrderItemSerializer
@property
def SHOP_CART_MODIFIERS(self):
"""
Specifies the list of :ref:`reference/cart-modifiers`. They are are applied on each cart item and the
cart final sums.
This list typically starts with ``'shop.modifiers.defaults.DefaultCartModifier'`` as its first entry,
followed by other cart modifiers.
"""
from django.utils.module_loading import import_string
cart_modifiers = self._setting('SHOP_CART_MODIFIERS', ['shop.modifiers.defaults.DefaultCartModifier'])
return [import_string(mc) for mc in cart_modifiers]
@property
def SHOP_VALUE_ADDED_TAX(self):
"""
Use this convenience settings if you can apply the same tax rate for all products
and you use one of the default tax modifiers :class:`shop.modifiers.taxes.CartIncludeTaxModifier`
or :class:`shop.modifiers.taxes.CartExcludedTaxModifier`.
If your products require individual tax rates or you ship into states with different tax rates,
then you must provide your own tax modifier.
"""
from decimal import Decimal
return self._setting('SHOP_VALUE_ADDED_TAX', Decimal('20'))
@property
def SHOP_ORDER_WORKFLOWS(self):
"""
Specifies a list of :ref:`reference/order-workflows`. Order workflows are applied after
an order has been created and conduct the vendor through the steps of receiving the payments
until fulfilling the shipment.
"""
from django.utils.module_loading import import_string
order_workflows = self._setting('SHOP_ORDER_WORKFLOWS', [])
return [import_string(mc) for mc in order_workflows]
@property
def SHOP_ADD2CART_NG_MODEL_OPTIONS(self):
"""
Used to configure the update behavior when changing the quantity of a product, in the product's
detail view after adding it to the cart. For more information refer to the documentation of the
NgModelOptions_ directive in the AngularJS reference.
.. _NgModelOptions: https://code.angularjs.org/1.5.9/docs/api/ng/directive/ngModelOptions
"""
return self._setting('SHOP_ADD2CART_NG_MODEL_OPTIONS',
"{updateOn: 'default blur', debounce: {'default': 500, 'blur': 0}}")
@property
def SHOP_EDITCART_NG_MODEL_OPTIONS(self):
"""
Used to configure the update behavior when changing the quantity of a cart item, in the cart's
edit view. For more information refer to the documentation of the
NgModelOptions_ directive in the AngularJS reference.
"""
return self._setting('SHOP_EDITCART_NG_MODEL_OPTIONS',
"{updateOn: 'default blur', debounce: {'default': 500, 'blur': 0}}")
@property
def SHOP_GUEST_IS_ACTIVE_USER(self):
"""
If this directive is ``True``, customers which declared themselves as guests, may request
a password reset, so that they can log into their account at a later time. Then it also
makes sense to set the ``email`` field in model ``email_auth.User`` as unique.
The default is ``False``.
"""
return self._setting('SHOP_GUEST_IS_ACTIVE_USER', False)
@property
def SHOP_OVERRIDE_SHIPPING_METHOD(self):
"""
If this directive is ``True``, the merchant is allowed to override the shipping method the
customer has chosen while performing the checkout.
Note that if alternative shipping is more expensive, usually the merchant has to come up
for the additional costs.
The default is ``False``.
"""
return self._setting('SHOP_OVERRIDE_SHIPPING_METHOD', False)
@property
def SHOP_CACHE_DURATIONS(self):
"""
In the product's list views, HTML snippets are created for the summary representation of
each product.
By default these snippet are cached for one day.
"""
result = self._setting('SHOP_CACHE_DURATIONS') or {}
result.setdefault('product_html_snippet', 86400)
return result
@property
def SHOP_DIALOG_FORMS(self):
"""
Specify a list of dialog forms available in our :class:`shop.views.checkout.CheckoutViewSet`.
This allows the usage of the endpoint ``resolve('shop:checkout-upload')`` in a generic way.
If Cascade plugins are used for the forms in the checkout view, this list can be empty.
"""
return self._setting('SHOP_DIALOG_FORMS', [])
@property
def SHOP_CASCADE_FORMS(self):
"""
Specify a map of Django Form classes to be used by the Cascade plugins used for the
checkout view. Override this map, if the Cascade plugins shall use a Form other than the
ones provided.
"""
cascade_forms = {
'CustomerForm': 'shop.forms.checkout.CustomerForm',
'GuestForm': 'shop.forms.checkout.GuestForm',
'ShippingAddressForm': 'shop.forms.checkout.ShippingAddressForm',
'BillingAddressForm': 'shop.forms.checkout.BillingAddressForm',
'PaymentMethodForm': 'shop.forms.checkout.PaymentMethodForm',
'ShippingMethodForm': 'shop.forms.checkout.ShippingMethodForm',
'ExtraAnnotationForm': 'shop.forms.checkout.ExtraAnnotationForm',
'AcceptConditionForm': 'shop.forms.checkout.AcceptConditionForm',
}
cascade_forms.update(self._setting('SHOP_CASCADE_FORMS', {}))
return cascade_forms
def __getattr__(self, key):
if not key.startswith('SHOP_'):
key = 'SHOP_' + key
return self.__getattribute__(key)
app_settings = DefaultSettings()