base.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. """
  2. Django settings for temp project.
  3. Generated by 'django-admin startproject' using Django 1.10.5.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/3.2/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/3.2/ref/settings/
  8. """
  9. import os
  10. import dj_database_url
  11. # Build paths inside the project like this: os.path.join(PROJECT_DIR, ...)
  12. PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  13. BASE_DIR = os.path.dirname(PROJECT_DIR)
  14. # Quick-start development settings - unsuitable for production
  15. # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
  16. # SECURITY WARNING: keep the secret key used in production secret!
  17. SECRET_KEY = "c6u0-9c!7nilj_ysatsda0(f@e_2mws2f!6m0n^o*4#*q#kzp)"
  18. # SECURITY WARNING: don't run with debug turned on in production!
  19. DEBUG = True
  20. ALLOWED_HOSTS = []
  21. # Uncomment this (and adjust as appropriate) to enable django-debug-toolbar
  22. # INTERNAL_IPS = [
  23. # '127.0.0.1',
  24. # ]
  25. # Application definition
  26. INSTALLED_APPS = [
  27. "bakerydemo.base",
  28. "bakerydemo.blog",
  29. "bakerydemo.breads",
  30. "bakerydemo.locations",
  31. "bakerydemo.recipes",
  32. "bakerydemo.search",
  33. "wagtail.embeds",
  34. "wagtail.sites",
  35. "wagtail.users",
  36. "wagtail.snippets",
  37. "wagtail.documents",
  38. "wagtail.images",
  39. "wagtail.search",
  40. "wagtail.admin",
  41. "wagtail.api.v2",
  42. "wagtail.locales",
  43. "wagtail.contrib.forms",
  44. "wagtail.contrib.redirects",
  45. "wagtail.contrib.routable_page",
  46. "wagtail.contrib.table_block",
  47. "wagtail.contrib.typed_table_block",
  48. "wagtail.contrib.search_promotions",
  49. "wagtail.contrib.settings",
  50. "wagtail.contrib.simple_translation",
  51. "wagtail.contrib.styleguide",
  52. "wagtail",
  53. "rest_framework",
  54. "modelcluster",
  55. "taggit",
  56. "wagtailfontawesomesvg",
  57. "debug_toolbar",
  58. "django_extensions",
  59. "django.contrib.admin",
  60. "django.contrib.auth",
  61. "django.contrib.contenttypes",
  62. "django.contrib.sessions",
  63. "django.contrib.messages",
  64. "django.contrib.staticfiles",
  65. "django.contrib.sitemaps",
  66. ]
  67. MIDDLEWARE = [
  68. "debug_toolbar.middleware.DebugToolbarMiddleware",
  69. "django.middleware.security.SecurityMiddleware",
  70. "django.contrib.sessions.middleware.SessionMiddleware",
  71. "django.middleware.common.CommonMiddleware",
  72. "django.middleware.csrf.CsrfViewMiddleware",
  73. "django.contrib.auth.middleware.AuthenticationMiddleware",
  74. "django.contrib.messages.middleware.MessageMiddleware",
  75. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  76. "wagtail.contrib.redirects.middleware.RedirectMiddleware",
  77. ]
  78. DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
  79. ROOT_URLCONF = "bakerydemo.urls"
  80. TEMPLATES = [
  81. {
  82. "BACKEND": "django.template.backends.django.DjangoTemplates",
  83. "DIRS": [
  84. "bakerydemo/templates",
  85. ],
  86. "APP_DIRS": True,
  87. "OPTIONS": {
  88. "context_processors": [
  89. "django.template.context_processors.debug",
  90. "django.template.context_processors.request",
  91. "django.contrib.auth.context_processors.auth",
  92. "django.contrib.messages.context_processors.messages",
  93. "wagtail.contrib.settings.context_processors.settings",
  94. ],
  95. },
  96. },
  97. {
  98. "BACKEND": "django.template.backends.jinja2.Jinja2",
  99. "DIRS": [
  100. "bakerydemo/jinja2",
  101. ],
  102. "APP_DIRS": True,
  103. "OPTIONS": {
  104. "extensions": [
  105. "wagtail.jinja2tags.core",
  106. "wagtail.admin.jinja2tags.userbar",
  107. "wagtail.images.jinja2tags.images",
  108. "wagtail.contrib.settings.jinja2tags.settings",
  109. "jinja2.ext.do",
  110. "jinja2.ext.i18n",
  111. "jinja2.ext.loopcontrols",
  112. "bakerydemo.base.jinja2tags.base",
  113. ],
  114. },
  115. },
  116. ]
  117. WSGI_APPLICATION = "bakerydemo.wsgi.application"
  118. # Database
  119. # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
  120. if "DATABASE_URL" in os.environ:
  121. DATABASES = {"default": dj_database_url.config(conn_max_age=500)}
  122. else:
  123. DATABASES = {
  124. "default": {
  125. "ENGINE": "django.db.backends.sqlite3",
  126. "NAME": os.path.join(BASE_DIR, "bakerydemodb"),
  127. }
  128. }
  129. # Password validation
  130. # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
  131. AUTH_PASSWORD_VALIDATORS = [
  132. {
  133. "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
  134. },
  135. {
  136. "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
  137. },
  138. {
  139. "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
  140. },
  141. {
  142. "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
  143. },
  144. ]
  145. # Internationalization
  146. # https://docs.djangoproject.com/en/3.2/topics/i18n/
  147. LANGUAGE_CODE = "en-us"
  148. TIME_ZONE = "UTC"
  149. USE_I18N = True
  150. USE_L10N = True
  151. USE_TZ = True
  152. # Static files (CSS, JavaScript, Images)
  153. # https://docs.djangoproject.com/en/3.2/howto/static-files/
  154. STATICFILES_FINDERS = [
  155. "django.contrib.staticfiles.finders.FileSystemFinder",
  156. "django.contrib.staticfiles.finders.AppDirectoriesFinder",
  157. ]
  158. STATICFILES_DIRS = [
  159. os.path.join(PROJECT_DIR, "static"),
  160. ]
  161. STATIC_ROOT = os.path.join(PROJECT_DIR, "collect_static")
  162. STATIC_URL = "/static/"
  163. MEDIA_ROOT = os.path.join(PROJECT_DIR, "media")
  164. MEDIA_URL = "/media/"
  165. # Override in local settings or replace with your own key. Please don't use our demo key in production!
  166. GOOGLE_MAP_API_KEY = "AIzaSyD31CT9P9KxvNUJOwDq2kcFEIG8ADgaFgw"
  167. # Use Elasticsearch as the search backend for extra performance and better search results
  168. WAGTAILSEARCH_BACKENDS = {
  169. "default": {
  170. "BACKEND": "wagtail.search.backends.database",
  171. "INDEX": "bakerydemo",
  172. },
  173. }
  174. # Wagtail settings
  175. WAGTAIL_SITE_NAME = "bakerydemo"
  176. WAGTAIL_I18N_ENABLED = True
  177. WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [
  178. ("en", "English"),
  179. ("de", "Deutsch"),
  180. ("ar", "العربيّة"),
  181. ]
  182. ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "changeme")
  183. # Content Security policy settings
  184. # http://django-csp.readthedocs.io/en/latest/configuration.html
  185. # Only enable CSP when enabled through environment variables.
  186. if "CSP_DEFAULT_SRC" in os.environ:
  187. MIDDLEWARE.append("csp.middleware.CSPMiddleware")
  188. # Only report violations, don't enforce policy
  189. CSP_REPORT_ONLY = True
  190. # The “special” source values of 'self', 'unsafe-inline', 'unsafe-eval', and 'none' must be quoted!
  191. # e.g.: CSP_DEFAULT_SRC = "'self'" Without quotes they will not work as intended.
  192. CSP_DEFAULT_SRC = os.environ.get("CSP_DEFAULT_SRC").split(",")
  193. if "CSP_SCRIPT_SRC" in os.environ:
  194. CSP_SCRIPT_SRC = os.environ.get("CSP_SCRIPT_SRC").split(",")
  195. if "CSP_STYLE_SRC" in os.environ:
  196. CSP_STYLE_SRC = os.environ.get("CSP_STYLE_SRC").split(",")
  197. if "CSP_IMG_SRC" in os.environ:
  198. CSP_IMG_SRC = os.environ.get("CSP_IMG_SRC").split(",")
  199. if "CSP_CONNECT_SRC" in os.environ:
  200. CSP_CONNECT_SRC = os.environ.get("CSP_CONNECT_SRC").split(",")
  201. if "CSP_FONT_SRC" in os.environ:
  202. CSP_FONT_SRC = os.environ.get("CSP_FONT_SRC").split(",")
  203. if "CSP_BASE_URI" in os.environ:
  204. CSP_BASE_URI = os.environ.get("CSP_BASE_URI").split(",")
  205. if "CSP_OBJECT_SRC" in os.environ:
  206. CSP_OBJECT_SRC = os.environ.get("CSP_OBJECT_SRC").split(",")