Coverage for django_demo/settings.py: 100%

33 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-16 10:58 +0000

1""" 

2Django settings for django_demo project. 

3 

4Generated by 'django-admin startproject' using Django 5.0.6. 

5 

6For more information on this file, see 

7https://docs.djangoproject.com/en/5.0/topics/settings/ 

8 

9For the full list of settings and their values, see 

10https://docs.djangoproject.com/en/5.0/ref/settings/ 

11""" 

12 

13import os 

14import json 

15import logging.config 

16 

17from pathlib import Path 

18 

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

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

21 

22 

23# Quick-start development settings - unsuitable for production 

24# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ 

25 

26 

27 

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

29#SECRET_KEY = 'django-insecure-hbx$%%92-whwu9n0nvqy4b$68r9t2spgluvty$=#7rku5*!o16' 

30SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'django-insecure-hbx$%%92-whwu9n0nvqy4b$68r9t2spgluvty$=#7rku5*!o16') 

31 

32 

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

34DEBUG = os.getenv('DJANGO_DEBUG', False) 

35 

36#ALLOWED_HOSTS = ['*'] 

37ALLOWED_HOSTS = os.getenv('DJANGO_ALLOWED_HOSTS', '127.0.0.1').split(',') 

38CSRF_TRUSTED_ORIGINS = ['https://syberbuildersdemo.com'] 

39 

40 

41## Collect static files 

42STATIC_ROOT = BASE_DIR / 'productionfiles' 

43 

44STATIC_URL = 'static/' 

45 

46STATICFILES_DIRS = [ 

47 BASE_DIR / 'static_files/' 

48] 

49 

50 

51# Application definition 

52 

53INSTALLED_APPS = [ 

54 'django.contrib.admin', 

55 'django.contrib.auth', 

56 'django.contrib.contenttypes', 

57 'django.contrib.sessions', 

58 'django.contrib.messages', 

59 'django.contrib.staticfiles', 

60 'basic_pages', 

61 'accounts', 

62 'coverage_report', 

63 'fontawesomefree', 

64 'cookie_consent', 

65 'storages', 

66] 

67 

68MIDDLEWARE = [ 

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 'whitenoise.middleware.WhiteNoiseMiddleware', 

77 "cookie_consent.middleware.CleanCookiesMiddleware", 

78] 

79 

80ROOT_URLCONF = 'django_demo.urls' 

81 

82TEMPLATES = [ 

83 { 

84 'BACKEND': 'django.template.backends.django.DjangoTemplates', 

85 'DIRS': [], 

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 ], 

94 }, 

95 }, 

96] 

97 

98WSGI_APPLICATION = 'django_demo.wsgi.application' 

99 

100SESSION_SAVE_EVERY_REQUEST = True 

101 

102# Database 

103# https://docs.djangoproject.com/en/5.0/ref/settings/#databases 

104 

105# DATABASES = { 

106 # 'default': { 

107 # 'ENGINE': 'django.db.backends.sqlite3', 

108 # 'NAME': BASE_DIR / 'db.sqlite3', 

109 # } 

110# } 

111 

112 

113DATABASES = { 

114 'default': { 

115 'ENGINE': os.getenv('DATABASE_ENGINE', 'django.db.backends.sqlite3'), 

116 'NAME': os.getenv('DATABASE_NAME', 'test_db'), 

117 'USER': os.getenv('DATABASE_USERNAME', 'test_user'), 

118 'PASSWORD': os.getenv('DATABASE_PASSWORD', 'test_password'), 

119 'HOST': os.getenv('DATABASE_HOST', '127.0.0.1'), 

120 'PORT': os.getenv('DATABASE_PORT', 25060), 

121 'OPTIONS': json.loads(os.getenv('DATABASE_OPTIONS', '{}')), 

122 } 

123 } 

124 

125 

126 

127# Password validation 

128# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators 

129 

130AUTH_PASSWORD_VALIDATORS = [ 

131 { 

132 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 

133 }, 

134 { 

135 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 

136 }, 

137 { 

138 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 

139 }, 

140 { 

141 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 

142 }, 

143] 

144 

145## email 

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

147DEFAULT_FROM_EMAIL = "contacts@syberbuilders.com" 

148NOTIFY_EMAIL = "notify@syberbuilders.com" 

149 

150# DEFAULT_FROM_EMAIL = "will@learndjango.com" 

151# NOTIFY_EMAIL = "will@learndjango.com" 

152# EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" 

153# EMAIL_HOST = "smtp.sendgrid.net" 

154# EMAIL_HOST_USER = "apikey" 

155# EMAIL_HOST_PASSWORD = "<sendgrid_password>" 

156# EMAIL_PORT = 587 

157# EMAIL_USE_TLS = True 

158 

159 

160 

161 

162 

163# TRACIFY_CHANNELS_CONFIGURATION = { 

164 # "DISCORD": { 

165 # "BACKEND": "tracify.channels.backends.discord.DiscordChannel", 

166 # # "WEBHOOK_URL": <"DISCORD_WEBHOOK_URL">, 

167 # }, 

168 # "TEAMS": { 

169 # "BACKEND": "tracify.channels.backends.teams.TeamsChannel", 

170 # # "WEBHOOK_URL": <"TEAMS_WEBHOOK_URL">, 

171 # }, 

172 # "EMAIL": { 

173 # "BACKEND": "tracify.channels.backends.email.EmailChannel", 

174 # }, 

175 # # If you are using EMAIL in above configuration you must need to configure EMAIL Configuration with EMAIL_ADMIN_USER and EMAIL_HOST_USER in settings.py 

176 # "DB": { 

177 # "BACKEND": "tracify.channels.backends.db.DBChannel", 

178 # }, 

179 # # If you are using DB in above configuration you must need to add tracify.db_backend in INSTALLED_APP 

180 # "SLACK": { 

181 # "BACKEND": "tracify.channels.backends.slack.SlackChannel", 

182 # # "WEBHOOK_URL": <"SLACK_WEBHOOK_URL">, 

183 # } 

184# } 

185 

186# Internationalization 

187# https://docs.djangoproject.com/en/5.0/topics/i18n/ 

188 

189LANGUAGE_CODE = 'en-us' 

190 

191TIME_ZONE = 'UTC' 

192 

193USE_I18N = True 

194 

195USE_TZ = True 

196 

197 

198# Static files (CSS, JavaScript, Images) 

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

200 

201 

202#### 

203# # Static files (CSS, JavaScript, Images) 

204# # https://docs.djangoproject.com/en/2.1/howto/static-files/ 

205 

206# # Moving static assets to DigitalOcean Spaces as per: 

207# # https://www.digitalocean.com/community/tutorials/how-to-set-up-object-storage-with-django 

208# AWS_ACCESS_KEY_ID = os.getenv('STATIC_ACCESS_KEY_ID') 

209# AWS_SECRET_ACCESS_KEY = os.getenv('STATIC_SECRET_KEY') 

210 

211# AWS_STORAGE_BUCKET_NAME = os.getenv('STATIC_BUCKET_NAME') 

212# AWS_S3_ENDPOINT_URL = os.getenv('STATIC_ENDPOINT_URL') 

213# AWS_S3_OBJECT_PARAMETERS = { 

214 # 'CacheControl': 'max-age=86400', 

215# } 

216# AWS_LOCATION = 'static' 

217# AWS_DEFAULT_ACL = 'public-read' 

218 

219# STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' 

220 

221# STATIC_URL = '{}/{}/'.format(AWS_S3_ENDPOINT_URL, AWS_LOCATION) 

222# STATIC_ROOT = 'static/' 

223##### 

224 

225 

226# Default primary key field type 

227# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field 

228 

229DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 

230 

231 

232# Redirect to home URL after login (Default redirects to /accounts/profile/) 

233LOGIN_REDIRECT_URL = '/accounts/profile' 

234LOGOUT_REDIRECT_URL = "/" 

235 

236# Logging Configuration 

237 

238# Clear prev config 

239LOGGING_CONFIG = None 

240 

241# Get loglevel from env 

242LOGLEVEL = os.getenv('DJANGO_LOGLEVEL', 'info').upper() 

243 

244logging.config.dictConfig({ 

245 'version': 1, 

246 'disable_existing_loggers': False, 

247 'formatters': { 

248 'console': { 

249 'format': '%(asctime)s %(levelname)s [%(name)s:%(lineno)s] %(module)s %(process)d %(thread)d %(message)s', 

250 }, 

251 }, 

252 'handlers': { 

253 'console': { 

254 'class': 'logging.StreamHandler', 

255 'formatter': 'console', 

256 }, 

257 }, 

258 'loggers': { 

259 '': { 

260 'level': LOGLEVEL, 

261 'handlers': ['console',], 

262 }, 

263 }, 

264}) 

265