您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

settings.py 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. # If running in a Windows environment this must be set to the same as your
  33. # system time zone.
  34. USE_TZ = True
  35. TIME_ZONE = 'Europe/London'
  36. TEST_RUNNER = 'django.test.runner.DiscoverRunner'
  37. # Language code for this installation. All choices can be found here:
  38. # http://www.i18nguy.com/unicode/language-identifiers.html
  39. LANGUAGE_CODE = 'en-gb'
  40. # Includes all languages that have >50% coverage in Transifex
  41. # Taken from Django's default setting for LANGUAGES
  42. gettext_noop = lambda s: s
  43. LANGUAGES = (
  44. ('ar', gettext_noop('Arabic')),
  45. ('ca', gettext_noop('Catalan')),
  46. ('cs', gettext_noop('Czech')),
  47. ('da', gettext_noop('Danish')),
  48. ('de', gettext_noop('German')),
  49. ('en-gb', gettext_noop('British English')),
  50. ('el', gettext_noop('Greek')),
  51. ('es', gettext_noop('Spanish')),
  52. ('fi', gettext_noop('Finnish')),
  53. ('fr', gettext_noop('French')),
  54. ('it', gettext_noop('Italian')),
  55. ('ko', gettext_noop('Korean')),
  56. ('nl', gettext_noop('Dutch')),
  57. ('pl', gettext_noop('Polish')),
  58. ('pt', gettext_noop('Portuguese')),
  59. ('pt-br', gettext_noop('Brazilian Portuguese')),
  60. ('ro', gettext_noop('Romanian')),
  61. ('ru', gettext_noop('Russian')),
  62. ('sk', gettext_noop('Slovak')),
  63. ('uk', gettext_noop('Ukrainian')),
  64. ('zh-cn', gettext_noop('Simplified Chinese')),
  65. )
  66. SITE_ID = 1
  67. # If you set this to False, Django will make some optimizations so as not
  68. # to load the internationalization machinery.
  69. USE_I18N = True
  70. # If you set this to False, Django will not format dates, numbers and
  71. # calendars according to the current locale
  72. USE_L10N = True
  73. # Absolute path to the directory that holds media.
  74. # Example: "/home/media/media.lawrence.com/"
  75. MEDIA_ROOT = location("public/media")
  76. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  77. # trailing slash if there is a path component (optional in other cases).
  78. # Examples: "http://media.lawrence.com", "http://example.com/media/"
  79. MEDIA_URL = '/media/'
  80. STATIC_URL = '/static/'
  81. STATIC_ROOT = location('public/static')
  82. STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  83. STATICFILES_DIRS = (
  84. location('static/'),
  85. )
  86. STATICFILES_FINDERS = (
  87. 'django.contrib.staticfiles.finders.FileSystemFinder',
  88. 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
  89. )
  90. # Make this unique, and don't share it with anybody.
  91. SECRET_KEY = env.str('SECRET_KEY', default='UajFCuyjDKmWHe29neauXzHi9eZoRXr6RMbT5JyAdPiACBP6Cra2')
  92. TEMPLATES = [
  93. {
  94. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  95. 'DIRS': [
  96. location('templates'),
  97. ],
  98. 'OPTIONS': {
  99. 'loaders': [
  100. 'django.template.loaders.filesystem.Loader',
  101. 'django.template.loaders.app_directories.Loader',
  102. ],
  103. 'context_processors': [
  104. 'django.contrib.auth.context_processors.auth',
  105. 'django.template.context_processors.request',
  106. 'django.template.context_processors.debug',
  107. 'django.template.context_processors.i18n',
  108. 'django.template.context_processors.media',
  109. 'django.template.context_processors.static',
  110. 'django.contrib.messages.context_processors.messages',
  111. # Oscar specific
  112. 'oscar.apps.search.context_processors.search_form',
  113. 'oscar.apps.customer.notifications.context_processors.notifications',
  114. 'oscar.apps.checkout.context_processors.checkout',
  115. 'oscar.core.context_processors.metadata',
  116. ],
  117. 'debug': DEBUG,
  118. }
  119. }
  120. ]
  121. MIDDLEWARE = [
  122. 'debug_toolbar.middleware.DebugToolbarMiddleware',
  123. 'django.middleware.security.SecurityMiddleware',
  124. 'whitenoise.middleware.WhiteNoiseMiddleware',
  125. 'django.contrib.sessions.middleware.SessionMiddleware',
  126. 'django.middleware.csrf.CsrfViewMiddleware',
  127. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  128. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  129. 'django.contrib.messages.middleware.MessageMiddleware',
  130. 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
  131. # Allow languages to be selected
  132. 'django.middleware.locale.LocaleMiddleware',
  133. 'django.middleware.http.ConditionalGetMiddleware',
  134. 'django.middleware.common.CommonMiddleware',
  135. # Ensure a valid basket is added to the request instance for every request
  136. 'oscar.apps.basket.middleware.BasketMiddleware',
  137. ]
  138. ROOT_URLCONF = 'urls'
  139. # A sample logging configuration. The only tangible logging
  140. # performed by this configuration is to send an email to
  141. # the site admins on every HTTP 500 error.
  142. # See http://docs.djangoproject.com/en/dev/topics/logging for
  143. # more details on how to customize your logging configuration.
  144. LOGGING = {
  145. 'version': 1,
  146. 'disable_existing_loggers': True,
  147. 'formatters': {
  148. 'verbose': {
  149. 'format': '%(levelname)s %(asctime)s %(module)s %(message)s',
  150. },
  151. 'simple': {
  152. 'format': '[%(asctime)s] %(message)s'
  153. },
  154. },
  155. 'root': {
  156. 'level': 'DEBUG',
  157. 'handlers': ['console'],
  158. },
  159. 'handlers': {
  160. 'null': {
  161. 'level': 'DEBUG',
  162. 'class': 'logging.NullHandler',
  163. },
  164. 'console': {
  165. 'level': 'DEBUG',
  166. 'class': 'logging.StreamHandler',
  167. 'formatter': 'simple'
  168. },
  169. },
  170. 'loggers': {
  171. 'oscar': {
  172. 'level': 'DEBUG',
  173. 'propagate': True,
  174. },
  175. 'oscar.catalogue.import': {
  176. 'handlers': ['console'],
  177. 'level': 'INFO',
  178. 'propagate': False,
  179. },
  180. 'oscar.alerts': {
  181. 'handlers': ['null'],
  182. 'level': 'INFO',
  183. 'propagate': False,
  184. },
  185. # Django loggers
  186. 'django': {
  187. 'handlers': ['null'],
  188. 'propagate': True,
  189. 'level': 'INFO',
  190. },
  191. 'django.request': {
  192. 'handlers': ['console'],
  193. 'level': 'ERROR',
  194. 'propagate': True,
  195. },
  196. 'django.db.backends': {
  197. 'level': 'WARNING',
  198. 'propagate': True,
  199. },
  200. 'django.security.DisallowedHost': {
  201. 'handlers': ['null'],
  202. 'propagate': False,
  203. },
  204. # Third party
  205. 'raven': {
  206. 'level': 'DEBUG',
  207. 'handlers': ['console'],
  208. 'propagate': False,
  209. },
  210. 'sorl.thumbnail': {
  211. 'handlers': ['console'],
  212. 'propagate': True,
  213. 'level': 'INFO',
  214. },
  215. }
  216. }
  217. INSTALLED_APPS = [
  218. 'django.contrib.admin',
  219. 'django.contrib.auth',
  220. 'django.contrib.contenttypes',
  221. 'django.contrib.sessions',
  222. 'django.contrib.messages',
  223. 'django.contrib.staticfiles',
  224. 'django.contrib.sites',
  225. 'django.contrib.flatpages',
  226. 'oscar',
  227. 'oscar.apps.analytics',
  228. 'oscar.apps.checkout',
  229. 'oscar.apps.address',
  230. 'oscar.apps.shipping',
  231. 'oscar.apps.catalogue',
  232. 'oscar.apps.catalogue.reviews',
  233. 'oscar.apps.partner',
  234. 'oscar.apps.basket',
  235. 'oscar.apps.payment',
  236. 'oscar.apps.offer',
  237. 'oscar.apps.order',
  238. 'oscar.apps.customer',
  239. 'oscar.apps.search',
  240. 'oscar.apps.voucher',
  241. 'oscar.apps.wishlists',
  242. 'oscar.apps.dashboard',
  243. 'oscar.apps.dashboard.reports',
  244. 'oscar.apps.dashboard.users',
  245. 'oscar.apps.dashboard.orders',
  246. 'oscar.apps.dashboard.catalogue',
  247. 'oscar.apps.dashboard.offers',
  248. 'oscar.apps.dashboard.partners',
  249. 'oscar.apps.dashboard.pages',
  250. 'oscar.apps.dashboard.ranges',
  251. 'oscar.apps.dashboard.reviews',
  252. 'oscar.apps.dashboard.vouchers',
  253. 'oscar.apps.dashboard.communications',
  254. 'oscar.apps.dashboard.shipping',
  255. # 3rd-party apps that Oscar depends on
  256. 'widget_tweaks',
  257. 'haystack',
  258. 'treebeard',
  259. 'sorl.thumbnail',
  260. 'easy_thumbnails',
  261. 'django_tables2',
  262. # Django apps that the sandbox depends on
  263. 'django.contrib.sitemaps',
  264. # 3rd-party apps that the sandbox depends on
  265. 'django_extensions',
  266. 'debug_toolbar',
  267. # For allowing dashboard access
  268. 'apps.gateway',
  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 settings
  297. HAYSTACK_CONNECTIONS = {
  298. 'default': {
  299. 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
  300. 'PATH': location('whoosh_index'),
  301. },
  302. }
  303. # Here's a sample Haystack config if using Solr (which is recommended)
  304. #HAYSTACK_CONNECTIONS = {
  305. # 'default': {
  306. # 'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
  307. # 'URL': 'http://127.0.0.1:8983/solr/oscar_latest/',
  308. # 'INCLUDE_SPELLING': True
  309. # },
  310. #}
  311. # =============
  312. # Debug Toolbar
  313. # =============
  314. INTERNAL_IPS = ['127.0.0.1', '::1']
  315. # ==============
  316. # Oscar settings
  317. # ==============
  318. from oscar.defaults import *
  319. # Meta
  320. # ====
  321. OSCAR_SHOP_TAGLINE = 'Sandbox'
  322. OSCAR_RECENTLY_VIEWED_PRODUCTS = 20
  323. OSCAR_ALLOW_ANON_CHECKOUT = True
  324. # Order processing
  325. # ================
  326. # Sample order/line status settings. This is quite simplistic. It's like you'll
  327. # want to override the set_status method on the order object to do more
  328. # sophisticated things.
  329. OSCAR_INITIAL_ORDER_STATUS = 'Pending'
  330. OSCAR_INITIAL_LINE_STATUS = 'Pending'
  331. # This dict defines the new order statuses than an order can move to
  332. OSCAR_ORDER_STATUS_PIPELINE = {
  333. 'Pending': ('Being processed', 'Cancelled',),
  334. 'Being processed': ('Complete', 'Cancelled',),
  335. 'Cancelled': (),
  336. 'Complete': (),
  337. }
  338. # This dict defines the line statuses that will be set when an order's status
  339. # is changed
  340. OSCAR_ORDER_STATUS_CASCADE = {
  341. 'Being processed': 'Being processed',
  342. 'Cancelled': 'Cancelled',
  343. 'Complete': 'Shipped',
  344. }
  345. # LESS/CSS
  346. # ========
  347. # We default to using CSS files, rather than the LESS files that generate them.
  348. # If you want to develop Oscar's CSS, then set OSCAR_USE_LESS=True to enable the
  349. # on-the-fly less processor.
  350. OSCAR_USE_LESS = False
  351. # Sorl
  352. # ====
  353. THUMBNAIL_DEBUG = DEBUG
  354. THUMBNAIL_KEY_PREFIX = 'oscar-sandbox'
  355. THUMBNAIL_KVSTORE = env(
  356. 'THUMBNAIL_KVSTORE',
  357. default='sorl.thumbnail.kvstores.cached_db_kvstore.KVStore')
  358. THUMBNAIL_REDIS_URL = env('THUMBNAIL_REDIS_URL', default=None)
  359. # Django 1.6 has switched to JSON serializing for security reasons, but it does not
  360. # serialize Models. We should resolve this by extending the
  361. # django/core/serializers/json.Serializer to have the `dumps` function. Also
  362. # in tests/config.py
  363. SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
  364. # Security
  365. SECURE_SSL_REDIRECT = env.bool('SECURE_SSL_REDIRECT', default=False)
  366. SECURE_HSTS_SECONDS = env.int('SECURE_HSTS_SECONDS', default=0)
  367. SECURE_CONTENT_TYPE_NOSNIFF = True
  368. SECURE_BROWSER_XSS_FILTER = True
  369. # Try and import local settings which can be used to override any of the above.
  370. try:
  371. from settings_local import *
  372. except ImportError:
  373. pass