You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings.py 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. import os
  2. import environ
  3. import oscar
  4. env = environ.Env()
  5. # Path helper
  6. location = lambda x: os.path.join(
  7. os.path.dirname(os.path.realpath(__file__)), x)
  8. DEBUG = env.bool('DEBUG', default=True)
  9. ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=['localhost', '127.0.0.1'])
  10. EMAIL_SUBJECT_PREFIX = '[Oscar sandbox] '
  11. EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
  12. # Use a Sqlite database by default
  13. DATABASES = {
  14. 'default': {
  15. 'ENGINE': os.environ.get('DATABASE_ENGINE', 'django.db.backends.sqlite3'),
  16. 'NAME': os.environ.get('DATABASE_NAME', location('db.sqlite')),
  17. 'USER': os.environ.get('DATABASE_USER', None),
  18. 'PASSWORD': os.environ.get('DATABASE_PASSWORD', None),
  19. 'HOST': os.environ.get('DATABASE_HOST', None),
  20. 'PORT': os.environ.get('DATABASE_PORT', None),
  21. 'ATOMIC_REQUESTS': True
  22. }
  23. }
  24. CACHES = {
  25. 'default': env.cache(default='locmemcache://'),
  26. }
  27. # Local time zone for this installation. Choices can be found here:
  28. # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  29. # although not all choices may be available on all operating systems.
  30. # On Unix systems, a value of None will cause Django to use the same
  31. # timezone as the operating system.
  32. USE_TZ = True
  33. TIME_ZONE = 'Europe/London'
  34. TEST_RUNNER = 'django.test.runner.DiscoverRunner'
  35. # Language code for this installation. All choices can be found here:
  36. # http://www.i18nguy.com/unicode/language-identifiers.html
  37. LANGUAGE_CODE = 'en-gb'
  38. # Includes all languages that have >50% coverage in Transifex
  39. # Taken from Django's default setting for LANGUAGES
  40. gettext_noop = lambda s: s
  41. LANGUAGES = (
  42. ('ar', gettext_noop('Arabic')),
  43. ('ca', gettext_noop('Catalan')),
  44. ('cs', gettext_noop('Czech')),
  45. ('da', gettext_noop('Danish')),
  46. ('de', gettext_noop('German')),
  47. ('en-gb', gettext_noop('British English')),
  48. ('el', gettext_noop('Greek')),
  49. ('es', gettext_noop('Spanish')),
  50. ('fi', gettext_noop('Finnish')),
  51. ('fr', gettext_noop('French')),
  52. ('it', gettext_noop('Italian')),
  53. ('ko', gettext_noop('Korean')),
  54. ('nl', gettext_noop('Dutch')),
  55. ('pl', gettext_noop('Polish')),
  56. ('pt', gettext_noop('Portuguese')),
  57. ('pt-br', gettext_noop('Brazilian Portuguese')),
  58. ('ro', gettext_noop('Romanian')),
  59. ('ru', gettext_noop('Russian')),
  60. ('sk', gettext_noop('Slovak')),
  61. ('uk', gettext_noop('Ukrainian')),
  62. ('zh-cn', gettext_noop('Simplified Chinese')),
  63. )
  64. SITE_ID = 1
  65. # If you set this to False, Django will make some optimizations so as not
  66. # to load the internationalization machinery.
  67. USE_I18N = True
  68. # If you set this to False, Django will not format dates, numbers and
  69. # calendars according to the current locale
  70. USE_L10N = True
  71. # Absolute path to the directory that holds media.
  72. # Example: "/home/media/media.lawrence.com/"
  73. MEDIA_ROOT = location("public/media")
  74. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  75. # trailing slash if there is a path component (optional in other cases).
  76. # Examples: "http://media.lawrence.com", "http://example.com/media/"
  77. MEDIA_URL = '/media/'
  78. STATIC_URL = '/static/'
  79. STATIC_ROOT = location('public/static')
  80. STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  81. STATICFILES_DIRS = (
  82. location('static/'),
  83. )
  84. STATICFILES_FINDERS = (
  85. 'django.contrib.staticfiles.finders.FileSystemFinder',
  86. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  87. )
  88. # Default primary key field type
  89. # https://docs.djangoproject.com/en/dev/ref/settings/#default-auto-field
  90. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  91. # Make this unique, and don't share it with anybody.
  92. SECRET_KEY = env.str('SECRET_KEY', default='UajFCuyjDKmWHe29neauXzHi9eZoRXr6RMbT5JyAdPiACBP6Cra2')
  93. TEMPLATES = [
  94. {
  95. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  96. 'DIRS': [
  97. location('templates'),
  98. ],
  99. 'OPTIONS': {
  100. 'loaders': [
  101. 'django.template.loaders.filesystem.Loader',
  102. 'django.template.loaders.app_directories.Loader',
  103. ],
  104. 'context_processors': [
  105. 'django.contrib.auth.context_processors.auth',
  106. 'django.template.context_processors.request',
  107. 'django.template.context_processors.debug',
  108. 'django.template.context_processors.i18n',
  109. 'django.template.context_processors.media',
  110. 'django.template.context_processors.static',
  111. 'django.contrib.messages.context_processors.messages',
  112. # Oscar specific
  113. 'oscar.apps.search.context_processors.search_form',
  114. 'oscar.apps.communication.notifications.context_processors.notifications',
  115. 'oscar.apps.checkout.context_processors.checkout',
  116. 'oscar.core.context_processors.metadata',
  117. ],
  118. 'debug': DEBUG,
  119. }
  120. }
  121. ]
  122. MIDDLEWARE = [
  123. 'debug_toolbar.middleware.DebugToolbarMiddleware',
  124. 'django.middleware.security.SecurityMiddleware',
  125. 'whitenoise.middleware.WhiteNoiseMiddleware',
  126. 'django.contrib.sessions.middleware.SessionMiddleware',
  127. 'django.middleware.csrf.CsrfViewMiddleware',
  128. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  129. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  130. 'django.contrib.messages.middleware.MessageMiddleware',
  131. 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
  132. # Allow languages to be selected
  133. 'django.middleware.locale.LocaleMiddleware',
  134. 'django.middleware.http.ConditionalGetMiddleware',
  135. 'django.middleware.common.CommonMiddleware',
  136. # Ensure a valid basket is added to the request instance for every request
  137. 'oscar.apps.basket.middleware.BasketMiddleware',
  138. ]
  139. ROOT_URLCONF = 'urls'
  140. # A sample logging configuration. The only tangible logging
  141. # performed by this configuration is to send an email to
  142. # the site admins on every HTTP 500 error.
  143. # See http://docs.djangoproject.com/en/dev/topics/logging for
  144. # more details on how to customize your logging configuration.
  145. LOGGING = {
  146. 'version': 1,
  147. 'disable_existing_loggers': True,
  148. 'formatters': {
  149. 'verbose': {
  150. 'format': '%(levelname)s %(asctime)s %(module)s %(message)s',
  151. },
  152. 'simple': {
  153. 'format': '[%(asctime)s] %(message)s'
  154. },
  155. },
  156. 'root': {
  157. 'level': 'DEBUG',
  158. 'handlers': ['console'],
  159. },
  160. 'handlers': {
  161. 'null': {
  162. 'level': 'DEBUG',
  163. 'class': 'logging.NullHandler',
  164. },
  165. 'console': {
  166. 'level': 'DEBUG',
  167. 'class': 'logging.StreamHandler',
  168. 'formatter': 'simple'
  169. },
  170. },
  171. 'loggers': {
  172. 'oscar': {
  173. 'level': 'DEBUG',
  174. 'propagate': True,
  175. },
  176. 'oscar.catalogue.import': {
  177. 'handlers': ['console'],
  178. 'level': 'INFO',
  179. 'propagate': False,
  180. },
  181. 'oscar.alerts': {
  182. 'handlers': ['null'],
  183. 'level': 'INFO',
  184. 'propagate': False,
  185. },
  186. # Django loggers
  187. 'django': {
  188. 'handlers': ['null'],
  189. 'propagate': True,
  190. 'level': 'INFO',
  191. },
  192. 'django.request': {
  193. 'handlers': ['console'],
  194. 'level': 'ERROR',
  195. 'propagate': True,
  196. },
  197. 'django.db.backends': {
  198. 'level': 'WARNING',
  199. 'propagate': True,
  200. },
  201. 'django.security.DisallowedHost': {
  202. 'handlers': ['null'],
  203. 'propagate': False,
  204. },
  205. # Third party
  206. 'raven': {
  207. 'level': 'DEBUG',
  208. 'handlers': ['console'],
  209. 'propagate': False,
  210. },
  211. 'sorl.thumbnail': {
  212. 'handlers': ['console'],
  213. 'propagate': True,
  214. 'level': 'INFO',
  215. },
  216. }
  217. }
  218. INSTALLED_APPS = [
  219. 'django.contrib.admin',
  220. 'django.contrib.auth',
  221. 'django.contrib.contenttypes',
  222. 'django.contrib.sessions',
  223. 'django.contrib.messages',
  224. 'django.contrib.staticfiles',
  225. 'django.contrib.sites',
  226. 'django.contrib.flatpages',
  227. 'oscar.config.Shop',
  228. 'oscar.apps.analytics.apps.AnalyticsConfig',
  229. 'oscar.apps.checkout.apps.CheckoutConfig',
  230. 'oscar.apps.address.apps.AddressConfig',
  231. 'oscar.apps.shipping.apps.ShippingConfig',
  232. 'oscar.apps.catalogue.apps.CatalogueConfig',
  233. 'oscar.apps.catalogue.reviews.apps.CatalogueReviewsConfig',
  234. 'oscar.apps.communication.apps.CommunicationConfig',
  235. 'oscar.apps.partner.apps.PartnerConfig',
  236. 'oscar.apps.basket.apps.BasketConfig',
  237. 'oscar.apps.payment.apps.PaymentConfig',
  238. 'oscar.apps.offer.apps.OfferConfig',
  239. 'oscar.apps.order.apps.OrderConfig',
  240. 'oscar.apps.customer.apps.CustomerConfig',
  241. 'oscar.apps.search.apps.SearchConfig',
  242. 'oscar.apps.voucher.apps.VoucherConfig',
  243. 'oscar.apps.wishlists.apps.WishlistsConfig',
  244. 'oscar.apps.dashboard.apps.DashboardConfig',
  245. 'oscar.apps.dashboard.reports.apps.ReportsDashboardConfig',
  246. 'oscar.apps.dashboard.users.apps.UsersDashboardConfig',
  247. 'oscar.apps.dashboard.orders.apps.OrdersDashboardConfig',
  248. 'oscar.apps.dashboard.catalogue.apps.CatalogueDashboardConfig',
  249. 'oscar.apps.dashboard.offers.apps.OffersDashboardConfig',
  250. 'oscar.apps.dashboard.partners.apps.PartnersDashboardConfig',
  251. 'oscar.apps.dashboard.pages.apps.PagesDashboardConfig',
  252. 'oscar.apps.dashboard.ranges.apps.RangesDashboardConfig',
  253. 'oscar.apps.dashboard.reviews.apps.ReviewsDashboardConfig',
  254. 'oscar.apps.dashboard.vouchers.apps.VouchersDashboardConfig',
  255. 'oscar.apps.dashboard.communications.apps.CommunicationsDashboardConfig',
  256. 'oscar.apps.dashboard.shipping.apps.ShippingDashboardConfig',
  257. # 3rd-party apps that Oscar depends on
  258. 'widget_tweaks',
  259. 'haystack',
  260. 'treebeard',
  261. 'sorl.thumbnail',
  262. 'easy_thumbnails',
  263. 'django_tables2',
  264. # Django apps that the sandbox depends on
  265. 'django.contrib.sitemaps',
  266. # 3rd-party apps that the sandbox depends on
  267. 'django_extensions',
  268. 'debug_toolbar',
  269. ]
  270. # Add Oscar's custom auth backend so users can sign in using their email
  271. # address.
  272. AUTHENTICATION_BACKENDS = (
  273. 'oscar.apps.customer.auth_backends.EmailBackend',
  274. 'django.contrib.auth.backends.ModelBackend',
  275. )
  276. AUTH_PASSWORD_VALIDATORS = [
  277. {
  278. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  279. 'OPTIONS': {
  280. 'min_length': 9,
  281. }
  282. },
  283. {
  284. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  285. },
  286. ]
  287. LOGIN_REDIRECT_URL = '/'
  288. APPEND_SLASH = True
  289. # ====================
  290. # Messages contrib app
  291. # ====================
  292. from django.contrib.messages import constants as messages
  293. MESSAGE_TAGS = {
  294. messages.ERROR: 'danger'
  295. }
  296. HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
  297. # Woosh settings
  298. HAYSTACK_CONNECTIONS = {
  299. 'default': {
  300. 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
  301. 'PATH': location('whoosh_index'),
  302. 'INCLUDE_SPELLING': True,
  303. },
  304. }
  305. # Here's a sample Haystack config for Solr 6.x (which is recommended)
  306. # HAYSTACK_CONNECTIONS = {
  307. # 'default': {
  308. # 'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
  309. # 'URL': 'http://127.0.0.1:8983/solr/sandbox',
  310. # 'ADMIN_URL': 'http://127.0.0.1:8983/solr/admin/cores',
  311. # 'INCLUDE_SPELLING': True,
  312. # }
  313. # }
  314. # =============
  315. # Debug Toolbar
  316. # =============
  317. INTERNAL_IPS = ['127.0.0.1', '::1']
  318. # ==============
  319. # Oscar settings
  320. # ==============
  321. from oscar.defaults import *
  322. # Meta
  323. # ====
  324. OSCAR_SHOP_TAGLINE = 'Sandbox'
  325. OSCAR_RECENTLY_VIEWED_PRODUCTS = 20
  326. OSCAR_ALLOW_ANON_CHECKOUT = True
  327. # Order processing
  328. # ================
  329. # Sample order/line status settings. This is quite simplistic. It's like you'll
  330. # want to override the set_status method on the order object to do more
  331. # sophisticated things.
  332. OSCAR_INITIAL_ORDER_STATUS = 'Pending'
  333. OSCAR_INITIAL_LINE_STATUS = 'Pending'
  334. # This dict defines the new order statuses than an order can move to
  335. OSCAR_ORDER_STATUS_PIPELINE = {
  336. 'Pending': ('Being processed', 'Cancelled',),
  337. 'Being processed': ('Complete', 'Cancelled',),
  338. 'Cancelled': (),
  339. 'Complete': (),
  340. }
  341. # This dict defines the line statuses that will be set when an order's status
  342. # is changed
  343. OSCAR_ORDER_STATUS_CASCADE = {
  344. 'Being processed': 'Being processed',
  345. 'Cancelled': 'Cancelled',
  346. 'Complete': 'Shipped',
  347. }
  348. # Sorl
  349. # ====
  350. THUMBNAIL_DEBUG = DEBUG
  351. THUMBNAIL_KEY_PREFIX = 'oscar-sandbox'
  352. THUMBNAIL_KVSTORE = env(
  353. 'THUMBNAIL_KVSTORE',
  354. default='sorl.thumbnail.kvstores.cached_db_kvstore.KVStore')
  355. THUMBNAIL_REDIS_URL = env('THUMBNAIL_REDIS_URL', default=None)
  356. # Django 1.6 has switched to JSON serializing for security reasons, but it does not
  357. # serialize Models. We should resolve this by extending the
  358. # django/core/serializers/json.Serializer to have the `dumps` function. Also
  359. # in tests/config.py
  360. SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
  361. # Security
  362. SECURE_SSL_REDIRECT = env.bool('SECURE_SSL_REDIRECT', default=False)
  363. SECURE_HSTS_SECONDS = env.int('SECURE_HSTS_SECONDS', default=0)
  364. SECURE_CONTENT_TYPE_NOSNIFF = True
  365. SECURE_BROWSER_XSS_FILTER = True
  366. # Try and import local settings which can be used to override any of the above.
  367. try:
  368. from settings_local import *
  369. except ImportError:
  370. pass