Coverage for healthy_meals / settings.py: 100%

46 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-03-10 14:10 +0000

1from pathlib import Path 

2from decouple import config 

3 

4# Build paths inside the project like this: BASE_DIR / 'subdir'. 

5BASE_DIR = Path(__file__).resolve().parent.parent 

6 

7 

8# Quick-start development settings - unsuitable for production 

9# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/ 

10 

11# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key 

12# SECURITY WARNING: keep the secret key used in production secret! 

13SECRET_KEY = config('SECRET_KEY') 

14 

15# https://docs.djangoproject.com/en/dev/ref/settings/#debug 

16# SECURITY WARNING: don't run with debug turned on in production! 

17DEBUG = config('DEBUG', default=False, cast=bool) 

18 

19# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts 

20ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1", "tayloredwebsites.github.io"] 

21 

22X_FRAME_OPTIONS = 'SAMEORIGIN' 

23 

24# https://www.digitalocean.com/community/tutorials/how-to-secure-your-django-application-with-a-content-security-policy 

25# to allow for github pages to be included into website 

26CSP_FRAME_SRC = ("'self'", 'https://tayloredwebsites.github.io') 

27 

28# Application definition 

29# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps 

30INSTALLED_APPS = [ 

31 "django.contrib.admin", 

32 "django.contrib.auth", 

33 "django.contrib.contenttypes", 

34 "django.contrib.sessions", 

35 "django.contrib.messages", 

36 "whitenoise.runserver_nostatic", 

37 "django.contrib.staticfiles", 

38 "django.contrib.sites", 

39 # Third-party 

40 "allauth", 

41 "allauth.account", 

42 "crispy_forms", 

43 "crispy_bootstrap5", 

44 "debug_toolbar", 

45 "safedelete", 

46 "compressor", # https://www.accordbox.com/blog/how-use-scss-sass-your-django-project-python-way/ 

47 "auditlog", # https://django-auditlog.readthedocs.io/en/latest/installation.html 

48 # Local 

49 "accounts", 

50 "pages", 

51] 

52 

53# https://docs.djangoproject.com/en/dev/ref/settings/#middleware 

54MIDDLEWARE = [ 

55 "django.middleware.security.SecurityMiddleware", 

56 "whitenoise.middleware.WhiteNoiseMiddleware", # WhiteNoise 

57 "django.contrib.sessions.middleware.SessionMiddleware", 

58 "django.middleware.locale.LocaleMiddleware", 

59 "django.middleware.common.CommonMiddleware", 

60 "debug_toolbar.middleware.DebugToolbarMiddleware", # Django Debug Toolbar 

61 "django.middleware.csrf.CsrfViewMiddleware", 

62 "django.contrib.auth.middleware.AuthenticationMiddleware", 

63 "django.contrib.messages.middleware.MessageMiddleware", 

64 # "django.middleware.clickjacking.XFrameOptionsMiddleware", 

65 "allauth.account.middleware.AccountMiddleware", # django-allauth 

66 # all Request altering middleware need to be registered above/before auditlog middleware, e.g., Django's default middleware classes 

67 "auditlog.middleware.AuditlogMiddleware", # https://django-auditlog.readthedocs.io/en/latest/installation.html 

68] 

69 

70# https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf 

71ROOT_URLCONF = "healthy_meals.urls" 

72 

73# https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application 

74WSGI_APPLICATION = "healthy_meals.wsgi.application" 

75 

76# https://docs.djangoproject.com/en/dev/ref/settings/#templates 

77TEMPLATES = [ 

78 { 

79 "BACKEND": "django.template.backends.django.DjangoTemplates", 

80 "DIRS": [BASE_DIR / "templates"], 

81 "APP_DIRS": True, 

82 "OPTIONS": { 

83 "context_processors": [ 

84 "django.template.context_processors.debug", 

85 "django.template.context_processors.request", 

86 "django.contrib.auth.context_processors.auth", 

87 "django.contrib.messages.context_processors.messages", 

88 ], 

89 "debug": True, # needed for https://github.com/nedbat/django_coverage_plugin 

90 }, 

91 }, 

92] 

93 

94# # https://docs.djangoproject.com/en/dev/ref/settings/#databases 

95# DATABASES = { 

96# "default": { 

97# "ENGINE": "django.db.backends.sqlite3", 

98# "NAME": BASE_DIR / "db.sqlite3", 

99# } 

100# } 

101 

102# For Docker/PostgreSQL usage uncomment this and comment the DATABASES config above 

103DATABASES = { 

104 "default": { 

105 "ENGINE": "django.db.backends.postgresql", 

106 "NAME": config('DATABASE_NAME'), 

107 "USER": config('DATABASE_USER'), 

108 "PASSWORD": config('DATABASE_PASSWORD'), 

109 "HOST": config('DATABASE_HOST'), # "db", # set in docker-compose.yml 

110 "PORT": config('DATABASE_PORT'), # 5432, # default postgres port 

111 "TEST": { 

112 "NAME": config('TEST_DATABASE_NAME'),# Documentation Purposes and allowing for override 

113 } 

114 } 

115} 

116 

117# Password validation 

118# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators 

119AUTH_PASSWORD_VALIDATORS = [ 

120 { 

121 "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", 

122 }, 

123 { 

124 "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", 

125 }, 

126 { 

127 "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", 

128 }, 

129 { 

130 "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", 

131 }, 

132] 

133 

134 

135# Internationalization 

136# https://docs.djangoproject.com/en/dev/topics/i18n/ 

137# https://docs.djangoproject.com/en/dev/ref/settings/#language-code 

138LANGUAGE_CODE = "en-us" 

139 

140LANGUAGES = [ 

141 ('en', 'English'), 

142] 

143 

144LOCALE_PATHS = ((BASE_DIR / 'locale'), ) 

145 

146# https://docs.djangoproject.com/en/dev/ref/settings/#time-zone 

147TIME_ZONE = "UTC" 

148 

149# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-USE_I18N 

150USE_I18N = True 

151 

152# https://docs.djangoproject.com/en/dev/ref/settings/#use-tz 

153USE_TZ = True 

154 

155# https://docs.djangoproject.com/en/dev/ref/settings/#locale-paths 

156LOCALE_PATHS = [BASE_DIR / "locale"] 

157 

158# Static files (CSS, JavaScript, Images) 

159# https://docs.djangoproject.com/en/5.0/howto/static-files/ 

160 

161# https://docs.djangoproject.com/en/dev/ref/settings/#static-root 

162STATIC_ROOT = BASE_DIR / "staticfiles" 

163 

164# https://docs.djangoproject.com/en/dev/ref/settings/#static-url 

165STATIC_URL = "/static/" 

166 

167# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS 

168STATICFILES_DIRS = [BASE_DIR / "static"] 

169 

170# https://www.accordbox.com/blog/how-use-scss-sass-your-django-project-python-way/ 

171# https://forum.djangoproject.com/t/getting-this-error-on-run-server-locally-compressor-exceptions-uncompressablefileerror-css-style-css-could-not-be-found-in-the-compress-root-users-khushmeeet-dev-codex-staticfiles-or-with-staticfiles/8503/6 

172STATICFILES_FINDERS = [ 

173 'django.contrib.staticfiles.finders.FileSystemFinder', 

174 'django.contrib.staticfiles.finders.AppDirectoriesFinder', 

175 'compressor.finders.CompressorFinder', 

176] 

177 

178COMPRESS_PRECOMPILERS = ( 

179 # deprecated libsass removed from here - using installed dart-sass 

180) 

181 

182# https://whitenoise.readthedocs.io/en/latest/django.html 

183STORAGES = { 

184 "default": { 

185 "BACKEND": "django.core.files.storage.FileSystemStorage", 

186 }, 

187 "staticfiles": { 

188 "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", 

189 }, 

190} 

191 

192# Default primary key field type 

193# https://docs.djangoproject.com/en/stable/ref/settings/#default-auto-field 

194DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" 

195 

196# django-crispy-forms 

197# https://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs 

198CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" 

199CRISPY_TEMPLATE_PACK = "bootstrap5" 

200 

201# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend 

202EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" 

203 

204# https://docs.djangoproject.com/en/dev/ref/settings/#default-from-email 

205DEFAULT_FROM_EMAIL = "root@localhost" 

206 

207# django-debug-toolbar 

208# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html 

209# https://docs.djangoproject.com/en/dev/ref/settings/#internal-ips 

210INTERNAL_IPS = ["127.0.0.1"] 

211 

212# https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model 

213AUTH_USER_MODEL = "accounts.CustomUser" 

214 

215# django-allauth config 

216# https://docs.djangoproject.com/en/dev/ref/settings/#site-id 

217SITE_ID = 1 

218 

219# https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url 

220LOGIN_REDIRECT_URL = "home" 

221 

222# https://django-allauth.readthedocs.io/en/latest/views.html#logout-account-logout 

223ACCOUNT_LOGOUT_REDIRECT_URL = "home" 

224 

225# https://django-allauth.readthedocs.io/en/latest/installation.html?highlight=backends 

226AUTHENTICATION_BACKENDS = ( 

227 "django.contrib.auth.backends.ModelBackend", 

228 "allauth.account.auth_backends.AuthenticationBackend", 

229) 

230# https://django-allauth.readthedocs.io/en/latest/configuration.html 

231ACCOUNT_SESSION_REMEMBER = True 

232ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False 

233ACCOUNT_USERNAME_REQUIRED = False 

234ACCOUNT_AUTHENTICATION_METHOD = "email" 

235ACCOUNT_EMAIL_REQUIRED = True 

236ACCOUNT_UNIQUE_EMAIL = True # does not work at database level 

237 

238# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-trusted-origins 

239CSRF_TRUSTED_ORIGINS = [ 

240 "http://localhost:8000", # Default Django dev server 

241 "http://127.0.0.1:8000", # Alternative local address 

242] 

243 

244# # https://github.com/wsvincent/lithium/blob/main/README.md#docker 

245# # django-debug-toolbar 

246# ### do we need these from the lithium starter app? 

247# import socket 

248# hostname, _, ips = socket.gethostbyname_ex(socket.gethostname()) 

249# INTERNAL_IPS = [ip[:-1] + "1" for ip in ips]