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 12KB

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