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

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