production.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import os
  2. import dj_database_url
  3. from .base import *
  4. # Do not set SECRET_KEY, Postgres or LDAP password or any other sensitive data here.
  5. # Instead, use environment variables or create a local.py file on the server.
  6. # Disable debug mode
  7. DEBUG = False
  8. TEMPLATES[0]['OPTIONS']['debug'] = False
  9. # Compress static files offline and minify CSS
  10. # http://django-compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
  11. COMPRESS_OFFLINE = True
  12. COMPRESS_CSS_FILTERS = [
  13. 'compressor.filters.css_default.CssAbsoluteFilter',
  14. 'compressor.filters.cssmin.CSSMinFilter',
  15. ]
  16. COMPRESS_CSS_HASHING_METHOD = 'content'
  17. # Configuration from environment variables
  18. # Alternatively, you can set these in a local.py file on the server
  19. env = os.environ.copy()
  20. # On Torchbox servers, many environment variables are prefixed with "CFG_"
  21. for key, value in os.environ.items():
  22. if key.startswith('CFG_'):
  23. env[key[4:]] = value
  24. # Basic configuration
  25. APP_NAME = env.get('APP_NAME', 'bakerydemo')
  26. if 'SECRET_KEY' in env:
  27. SECRET_KEY = env['SECRET_KEY']
  28. if 'ALLOWED_HOSTS' in env:
  29. ALLOWED_HOSTS = env['ALLOWED_HOSTS'].split(',')
  30. if 'PRIMARY_HOST' in env:
  31. BASE_URL = 'http://%s/' % env['PRIMARY_HOST']
  32. if 'SERVER_EMAIL' in env:
  33. SERVER_EMAIL = env['SERVER_EMAIL']
  34. if 'CACHE_PURGE_URL' in env:
  35. INSTALLED_APPS += ( 'wagtail.contrib.wagtailfrontendcache', )
  36. WAGTAILFRONTENDCACHE = {
  37. 'default': {
  38. 'BACKEND': 'wagtail.contrib.wagtailfrontendcache.backends.HTTPBackend',
  39. 'LOCATION': env['CACHE_PURGE_URL'],
  40. },
  41. }
  42. if 'STATIC_URL' in env:
  43. STATIC_URL = env['STATIC_URL']
  44. if 'STATIC_DIR' in env:
  45. STATIC_ROOT = env['STATIC_DIR']
  46. if 'MEDIA_URL' in env:
  47. MEDIA_URL = env['MEDIA_URL']
  48. if 'MEDIA_DIR' in env:
  49. MEDIA_ROOT = env['MEDIA_DIR']
  50. # Database
  51. if 'DATABASE_URL' in os.environ:
  52. DATABASES = {'default': dj_database_url.config()}
  53. else:
  54. DATABASES = {
  55. 'default': {
  56. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  57. 'NAME': env.get('PGDATABASE', APP_NAME),
  58. 'CONN_MAX_AGE': 600, # number of seconds database connections should persist for
  59. # User, host and port can be configured by the PGUSER, PGHOST and
  60. # PGPORT environment variables (these get picked up by libpq).
  61. }
  62. }
  63. # Elasticsearch
  64. if 'ELASTICSEARCH_URL' in env:
  65. WAGTAILSEARCH_BACKENDS = {
  66. 'default': {
  67. 'BACKEND': 'wagtail.wagtailsearch.backends.elasticsearch.ElasticSearch',
  68. 'URLS': [env['ELASTICSEARCH_URL']],
  69. 'INDEX': APP_NAME,
  70. 'ATOMIC_REBUILD': True,
  71. },
  72. }
  73. # Logging
  74. LOGGING = {
  75. 'version': 1,
  76. 'disable_existing_loggers': False,
  77. 'handlers': {
  78. 'mail_admins': {
  79. 'level': 'ERROR',
  80. 'class': 'django.utils.log.AdminEmailHandler',
  81. },
  82. },
  83. 'formatters': {
  84. 'default': {
  85. 'verbose': '[%(asctime)s] (%(process)d/%(thread)d) %(name)s %(levelname)s: %(message)s'
  86. }
  87. },
  88. 'loggers': {
  89. 'bakerydemo': {
  90. 'handlers': [],
  91. 'level': 'INFO',
  92. 'propagate': False,
  93. 'formatter': 'verbose',
  94. },
  95. 'wagtail': {
  96. 'handlers': [],
  97. 'level': 'INFO',
  98. 'propagate': False,
  99. 'formatter': 'verbose',
  100. },
  101. 'django.request': {
  102. 'handlers': ['mail_admins'],
  103. 'level': 'ERROR',
  104. 'propagate': False,
  105. 'formatter': 'verbose',
  106. },
  107. 'django.security': {
  108. 'handlers': ['mail_admins'],
  109. 'level': 'ERROR',
  110. 'propagate': False,
  111. 'formatter': 'verbose',
  112. },
  113. },
  114. }
  115. if 'LOG_DIR' in env:
  116. # bakerydemo log
  117. LOGGING['handlers']['bakerydemo_file'] = {
  118. 'level': 'INFO',
  119. 'class': 'cloghandler.ConcurrentRotatingFileHandler',
  120. 'filename': os.path.join(env['LOG_DIR'], 'bakerydemo.log'),
  121. 'maxBytes': 5242880, # 5MB
  122. 'backupCount': 5
  123. }
  124. LOGGING['loggers']['wagtail']['handlers'].append('bakerydemo_file')
  125. # Wagtail log
  126. LOGGING['handlers']['wagtail_file'] = {
  127. 'level': 'INFO',
  128. 'class': 'cloghandler.ConcurrentRotatingFileHandler',
  129. 'filename': os.path.join(env['LOG_DIR'], 'wagtail.log'),
  130. 'maxBytes': 5242880, # 5MB
  131. 'backupCount': 5
  132. }
  133. LOGGING['loggers']['wagtail']['handlers'].append('wagtail_file')
  134. # Error log
  135. LOGGING['handlers']['errors_file'] = {
  136. 'level': 'ERROR',
  137. 'class': 'cloghandler.ConcurrentRotatingFileHandler',
  138. 'filename': os.path.join(env['LOG_DIR'], 'error.log'),
  139. 'maxBytes': 5242880, # 5MB
  140. 'backupCount': 5
  141. }
  142. LOGGING['loggers']['django.request']['handlers'].append('errors_file')
  143. LOGGING['loggers']['django.security']['handlers'].append('errors_file')
  144. try:
  145. from .local import *
  146. except ImportError:
  147. pass