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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. import os
  2. import sys
  3. # Path helper
  4. PROJECT_DIR = os.path.dirname(__file__)
  5. location = lambda x: os.path.join(
  6. os.path.dirname(os.path.realpath(__file__)), x)
  7. PY3 = sys.version_info >= (3, 0)
  8. USE_TZ = True
  9. DEBUG = True
  10. TEMPLATE_DEBUG = True
  11. SQL_DEBUG = True
  12. ALLOWED_HOSTS = ['latest.oscarcommerce.com',
  13. 'sandbox.oscar.tangentlabs.co.uk',
  14. 'master.oscarcommerce.com']
  15. ADMINS = (
  16. ('David Winterbottom', 'david.winterbottom@tangentlabs.co.uk'),
  17. )
  18. EMAIL_SUBJECT_PREFIX = '[Oscar sandbox] '
  19. EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
  20. MANAGERS = ADMINS
  21. # Use a Sqlite database by default
  22. DATABASES = {
  23. 'default': {
  24. 'ENGINE': 'django.db.backends.sqlite3',
  25. 'NAME': os.path.join(os.path.dirname(__file__), 'db.sqlite'),
  26. 'USER': '',
  27. 'PASSWORD': '',
  28. 'HOST': '',
  29. 'PORT': '',
  30. 'ATOMIC_REQUESTS': True
  31. }
  32. }
  33. CACHES = {
  34. 'default': {
  35. 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
  36. }
  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. TIME_ZONE = 'Europe/London'
  46. # Language code for this installation. All choices can be found here:
  47. # http://www.i18nguy.com/unicode/language-identifiers.html
  48. LANGUAGE_CODE = 'en-gb'
  49. # This should match the locale folders in oscar/locale
  50. LANGUAGES = (
  51. ('en-gb', 'English'),
  52. ('da', 'Danish'),
  53. ('de', 'German'),
  54. ('el', 'Greek'),
  55. ('en', 'English'),
  56. ('es', 'Spanish'),
  57. ('fr', 'French'),
  58. ('it', 'Italian'),
  59. ('ja', 'Japanese'),
  60. ('pl', 'Polish'),
  61. ('pt', 'Portugese'),
  62. ('ru', 'Russian'),
  63. ('sk', 'Slovakian'),
  64. )
  65. ROSETTA_STORAGE_CLASS = 'rosetta.storage.SessionRosettaStorage'
  66. ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS = True
  67. ROSETTA_REQUIRES_AUTH = False
  68. SITE_ID = 1
  69. # If you set this to False, Django will make some optimizations so as not
  70. # to load the internationalization machinery.
  71. USE_I18N = True
  72. # If you set this to False, Django will not format dates, numbers and
  73. # calendars according to the current locale
  74. USE_L10N = True
  75. # Absolute path to the directory that holds media.
  76. # Example: "/home/media/media.lawrence.com/"
  77. MEDIA_ROOT = location("public/media")
  78. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  79. # trailing slash if there is a path component (optional in other cases).
  80. # Examples: "http://media.lawrence.com", "http://example.com/media/"
  81. MEDIA_URL = '/media/'
  82. # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
  83. # trailing slash.
  84. # Examples: "http://foo.com/media/", "/media/".
  85. #ADMIN_MEDIA_PREFIX = '/media/admin/'
  86. STATIC_URL = '/static/'
  87. STATIC_ROOT = location('public/static')
  88. STATICFILES_DIRS = (
  89. location('static/'),
  90. )
  91. STATICFILES_FINDERS = (
  92. 'django.contrib.staticfiles.finders.FileSystemFinder',
  93. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  94. 'compressor.finders.CompressorFinder',
  95. )
  96. # Make this unique, and don't share it with anybody.
  97. SECRET_KEY = '$)a7n&o80u!6y5t-+jrd3)3!%vh&shg$wqpjpxc!ar&p#!)n1a'
  98. # List of callables that know how to import templates from various sources.
  99. TEMPLATE_LOADERS = (
  100. 'django.template.loaders.filesystem.Loader',
  101. 'django.template.loaders.app_directories.Loader',
  102. # needed by django-treebeard for admin (and potentially other libs)
  103. 'django.template.loaders.eggs.Loader',
  104. )
  105. TEMPLATE_CONTEXT_PROCESSORS = (
  106. "django.contrib.auth.context_processors.auth",
  107. "django.core.context_processors.request",
  108. "django.core.context_processors.debug",
  109. "django.core.context_processors.i18n",
  110. "django.core.context_processors.media",
  111. "django.core.context_processors.static",
  112. "django.contrib.messages.context_processors.messages",
  113. # Oscar specific
  114. 'oscar.apps.search.context_processors.search_form',
  115. 'oscar.apps.promotions.context_processors.promotions',
  116. 'oscar.apps.checkout.context_processors.checkout',
  117. 'oscar.core.context_processors.metadata',
  118. 'oscar.apps.customer.notifications.context_processors.notifications',
  119. )
  120. MIDDLEWARE_CLASSES = (
  121. 'debug_toolbar.middleware.DebugToolbarMiddleware',
  122. 'django.contrib.sessions.middleware.SessionMiddleware',
  123. 'django.middleware.csrf.CsrfViewMiddleware',
  124. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  125. 'django.contrib.messages.middleware.MessageMiddleware',
  126. 'django.middleware.transaction.TransactionMiddleware',
  127. 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
  128. # Allow languages to be selected
  129. 'django.middleware.locale.LocaleMiddleware',
  130. 'django.middleware.common.CommonMiddleware',
  131. # Ensure a valid basket is added to the request instance for every request
  132. 'oscar.apps.basket.middleware.BasketMiddleware',
  133. # Enable the ProfileMiddleware, then add ?cprofile to any
  134. # URL path to print out profile details
  135. #'oscar.profiling.middleware.ProfileMiddleware',
  136. )
  137. ROOT_URLCONF = 'urls'
  138. # Add another path to Oscar's templates. This allows templates to be
  139. # customised easily.
  140. from oscar import OSCAR_MAIN_TEMPLATE_DIR
  141. TEMPLATE_DIRS = (
  142. location('templates'),
  143. OSCAR_MAIN_TEMPLATE_DIR,
  144. )
  145. # A sample logging configuration. The only tangible logging
  146. # performed by this configuration is to send an email to
  147. # the site admins on every HTTP 500 error.
  148. # See http://docs.djangoproject.com/en/dev/topics/logging for
  149. # more details on how to customize your logging configuration.
  150. LOGGING = {
  151. 'version': 1,
  152. 'disable_existing_loggers': True,
  153. 'formatters': {
  154. 'verbose': {
  155. 'format': '%(levelname)s %(asctime)s %(module)s %(message)s',
  156. },
  157. 'simple': {
  158. 'format': '[%(asctime)s] %(message)s'
  159. },
  160. },
  161. 'filters': {
  162. 'require_debug_false': {
  163. '()': 'django.utils.log.RequireDebugFalse'
  164. }
  165. },
  166. 'handlers': {
  167. 'null': {
  168. 'level': 'DEBUG',
  169. 'class': 'django.utils.log.NullHandler',
  170. },
  171. 'console': {
  172. 'level': 'DEBUG',
  173. 'class': 'logging.StreamHandler',
  174. 'formatter': 'verbose'
  175. },
  176. 'checkout_file': {
  177. 'level': 'INFO',
  178. 'class': 'oscar.core.logging.handlers.EnvFileHandler',
  179. 'filename': 'checkout.log',
  180. 'formatter': 'verbose'
  181. },
  182. 'gateway_file': {
  183. 'level': 'INFO',
  184. 'class': 'oscar.core.logging.handlers.EnvFileHandler',
  185. 'filename': 'gateway.log',
  186. 'formatter': 'simple'
  187. },
  188. 'error_file': {
  189. 'level': 'INFO',
  190. 'class': 'oscar.core.logging.handlers.EnvFileHandler',
  191. 'filename': 'errors.log',
  192. 'formatter': 'verbose'
  193. },
  194. 'sorl_file': {
  195. 'level': 'INFO',
  196. 'class': 'oscar.core.logging.handlers.EnvFileHandler',
  197. 'filename': 'sorl.log',
  198. 'formatter': 'verbose'
  199. },
  200. 'mail_admins': {
  201. 'level': 'ERROR',
  202. 'class': 'django.utils.log.AdminEmailHandler',
  203. 'filters': ['require_debug_false'],
  204. },
  205. },
  206. 'loggers': {
  207. # Django loggers
  208. 'django': {
  209. 'handlers': ['null'],
  210. 'propagate': True,
  211. 'level': 'INFO',
  212. },
  213. 'django.request': {
  214. 'handlers': ['mail_admins', 'error_file'],
  215. 'level': 'ERROR',
  216. 'propagate': False,
  217. },
  218. 'django.db.backends': {
  219. 'handlers': ['null'],
  220. 'propagate': False,
  221. 'level': 'DEBUG',
  222. },
  223. # Oscar core loggers
  224. 'oscar.checkout': {
  225. 'handlers': ['console', 'checkout_file'],
  226. 'propagate': False,
  227. 'level': 'INFO',
  228. },
  229. 'oscar.catalogue.import': {
  230. 'handlers': ['console'],
  231. 'propagate': False,
  232. 'level': 'INFO',
  233. },
  234. 'oscar.alerts': {
  235. 'handlers': ['null'],
  236. 'propagate': False,
  237. 'level': 'INFO',
  238. },
  239. # Sandbox logging
  240. 'gateway': {
  241. 'handlers': ['gateway_file'],
  242. 'propagate': True,
  243. 'level': 'INFO',
  244. },
  245. # Third party
  246. 'south': {
  247. 'handlers': ['null'],
  248. 'propagate': True,
  249. 'level': 'INFO',
  250. },
  251. 'sorl.thumbnail': {
  252. 'handlers': ['sorl_file'],
  253. 'propagate': True,
  254. 'level': 'INFO',
  255. },
  256. # Suppress output of this debug toolbar panel
  257. 'template_timings_panel': {
  258. 'handlers': ['null'],
  259. 'level': 'DEBUG',
  260. 'propagate': False,
  261. }
  262. }
  263. }
  264. INSTALLED_APPS = [
  265. 'django.contrib.auth',
  266. 'django.contrib.contenttypes',
  267. 'django.contrib.sessions',
  268. 'django.contrib.sites',
  269. 'django.contrib.messages',
  270. 'django.contrib.admin',
  271. 'django.contrib.flatpages',
  272. 'django.contrib.staticfiles',
  273. 'django_extensions',
  274. # Debug toolbar + extensions
  275. 'debug_toolbar',
  276. 'template_timings_panel',
  277. 'south',
  278. 'rosetta', # For i18n testing
  279. 'compressor',
  280. 'apps.gateway', # For allowing dashboard access
  281. ]
  282. from oscar import get_core_apps
  283. INSTALLED_APPS = INSTALLED_APPS + get_core_apps()
  284. # Add Oscar's custom auth backend so users can sign in using their email
  285. # address.
  286. AUTHENTICATION_BACKENDS = (
  287. 'oscar.apps.customer.auth_backends.Emailbackend',
  288. 'django.contrib.auth.backends.ModelBackend',
  289. )
  290. LOGIN_REDIRECT_URL = '/'
  291. APPEND_SLASH = True
  292. # Haystack settings
  293. HAYSTACK_CONNECTIONS = {
  294. 'default': {
  295. 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
  296. 'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
  297. },
  298. }
  299. # =============
  300. # Debug Toolbar
  301. # =============
  302. # Implicit setup can often lead to problems with circular imports, so we
  303. # explicitly wire up the toolbar
  304. DEBUG_TOOLBAR_PATCH_SETTINGS = False
  305. DEBUG_TOOLBAR_PANELS = [
  306. 'debug_toolbar.panels.versions.VersionsPanel',
  307. 'debug_toolbar.panels.timer.TimerPanel',
  308. 'debug_toolbar.panels.settings.SettingsPanel',
  309. 'debug_toolbar.panels.headers.HeadersPanel',
  310. 'debug_toolbar.panels.request.RequestPanel',
  311. 'debug_toolbar.panels.sql.SQLPanel',
  312. 'debug_toolbar.panels.staticfiles.StaticFilesPanel',
  313. 'debug_toolbar.panels.templates.TemplatesPanel',
  314. 'template_timings_panel.panels.TemplateTimings.TemplateTimings',
  315. 'debug_toolbar.panels.cache.CachePanel',
  316. 'debug_toolbar.panels.signals.SignalsPanel',
  317. 'debug_toolbar.panels.logging.LoggingPanel',
  318. 'debug_toolbar.panels.redirects.RedirectsPanel',
  319. ]
  320. INTERNAL_IPS = ['127.0.0.1', '::1']
  321. if PY3:
  322. # Template timings panel doesn't work with Python 3 atm
  323. # https://github.com/orf/django-debug-toolbar-template-timings/issues/18
  324. INSTALLED_APPS.remove('template_timings_panel')
  325. DEBUG_TOOLBAR_PANELS.remove(
  326. 'template_timings_panel.panels.TemplateTimings.TemplateTimings')
  327. # ==============
  328. # Oscar settings
  329. # ==============
  330. from oscar.defaults import *
  331. # Meta
  332. # ====
  333. OSCAR_SHOP_TAGLINE = 'Sandbox'
  334. OSCAR_RECENTLY_VIEWED_PRODUCTS = 20
  335. OSCAR_ALLOW_ANON_CHECKOUT = True
  336. # This is added to each template context by the core context processor. It is
  337. # useful for test/stage/qa sites where you want to show the version of the site
  338. # in the page title.
  339. DISPLAY_VERSION = False
  340. # Order processing
  341. # ================
  342. # Some sample order/line status settings
  343. OSCAR_INITIAL_ORDER_STATUS = 'Pending'
  344. OSCAR_INITIAL_LINE_STATUS = 'Pending'
  345. OSCAR_ORDER_STATUS_PIPELINE = {
  346. 'Pending': ('Being processed', 'Cancelled',),
  347. 'Being processed': ('Processed', 'Cancelled',),
  348. 'Cancelled': (),
  349. 'Processed': (),
  350. }
  351. # LESS/CSS/statics
  352. # ================
  353. # We default to using CSS files, rather than the LESS files that generate them.
  354. # If you want to develop Oscar's CSS, then set USE_LESS=True and
  355. # COMPRESS_ENABLED=False in your settings_local module and ensure you have
  356. # 'lessc' installed. You can do this by running:
  357. #
  358. # pip install -r requirements_less.txt
  359. #
  360. # which will install node.js and less in your virtualenv.
  361. USE_LESS = False
  362. COMPRESS_ENABLED = True
  363. COMPRESS_PRECOMPILERS = (
  364. ('text/less', 'lessc {infile} {outfile}'),
  365. )
  366. COMPRESS_OFFLINE_CONTEXT = {
  367. 'STATIC_URL': 'STATIC_URL',
  368. 'use_less': USE_LESS,
  369. }
  370. # We do this to work around an issue in compressor where the LESS files are
  371. # compiled but compression isn't enabled. When this happens, the relative URL
  372. # is wrong between the generated CSS file and other assets:
  373. # https://github.com/jezdez/django_compressor/issues/226
  374. COMPRESS_OUTPUT_DIR = 'oscar'
  375. # Logging
  376. # =======
  377. LOG_ROOT = location('logs')
  378. # Ensure log root exists
  379. if not os.path.exists(LOG_ROOT):
  380. os.mkdir(LOG_ROOT)
  381. # Sorl
  382. # ====
  383. THUMBNAIL_DEBUG = True
  384. THUMBNAIL_KEY_PREFIX = 'oscar-sandbox'
  385. # Use a custom KV store to handle integrity error
  386. THUMBNAIL_KVSTORE = 'oscar.sorl_kvstore.ConcurrentKVStore'
  387. # Django 1.6 has switched to JSON serializing for security reasons, but it does not
  388. # serialize Models. We should resolve this by extending the
  389. # django/core/serializers/json.Serializer to have the `dumps` function. Also
  390. # in tests/config.py
  391. SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
  392. # Try and import local settings which can be used to override any of the above.
  393. try:
  394. from settings_local import *
  395. except ImportError:
  396. pass