Coverage for erisa_project\settings.py: 100%

27 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-14 18:28 -0400

1""" 

2Django settings for erisa_project project. 

3 

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

5 

6For more information on this file, see 

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

8 

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

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

11""" 

12 

13import os 

14from pathlib import Path 

15 

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

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

18 

19 

20# Quick-start development settings - unsuitable for production 

21# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ 

22 

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

24SECRET_KEY = "django-insecure-ek!h=n7ap7p5zw)@$911ef@)&d6nlh9mkfvm2s@fs+=x6q&z_c" 

25 

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

27DEBUG = True 

28 

29ALLOWED_HOSTS = [] 

30 

31 

32# Application definition 

33 

34INSTALLED_APPS = [ 

35 "django.contrib.admin", 

36 "django.contrib.auth", 

37 "django.contrib.contenttypes", 

38 "django.contrib.sessions", 

39 "django.contrib.messages", 

40 "django.contrib.staticfiles", 

41 "django.contrib.humanize", # for readable numbers 

42 "claims", 

43 "django_htmx", 

44] 

45 

46MIDDLEWARE = [ 

47 "django.middleware.security.SecurityMiddleware", 

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

49 "django.middleware.common.CommonMiddleware", 

50 "django.middleware.csrf.CsrfViewMiddleware", 

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

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

53 "django.middleware.clickjacking.XFrameOptionsMiddleware", 

54 "django_htmx.middleware.HtmxMiddleware", 

55] 

56 

57ROOT_URLCONF = "erisa_project.urls" 

58 

59TEMPLATES = [ 

60 { 

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

62 # # add template dir 

63 "DIRS": [os.path.join(BASE_DIR, "templates")], 

64 "APP_DIRS": True, 

65 "OPTIONS": { 

66 "context_processors": [ 

67 "django.template.context_processors.request", 

68 "django.contrib.auth.context_processors.auth", 

69 "django.contrib.messages.context_processors.messages", 

70 ], 

71 }, 

72 }, 

73] 

74 

75WSGI_APPLICATION = "erisa_project.wsgi.application" 

76 

77 

78# Database 

79# https://docs.djangoproject.com/en/5.2/ref/settings/#databases 

80 

81DATABASES = { 

82 "default": { 

83 "ENGINE": "django.db.backends.sqlite3", 

84 "NAME": BASE_DIR / "db.sqlite3", 

85 } 

86} 

87 

88 

89# Password validation 

90# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators 

91 

92AUTH_PASSWORD_VALIDATORS = [ 

93 { 

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

95 }, 

96 { 

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

98 }, 

99 { 

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

101 }, 

102 { 

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

104 }, 

105] 

106 

107STATICFILES_DIRS = [ 

108 os.path.join(BASE_DIR, "static"), 

109] 

110 

111# --- Logging Configuration --- 

112 

113# Automatically create the logs directory if it doesn't exist 

114LOG_DIR = BASE_DIR / "logs" 

115LOG_DIR.mkdir(exist_ok=True) 

116 

117LOGGING = { 

118 "version": 1, 

119 "disable_existing_loggers": False, 

120 "formatters": { 

121 "verbose": { 

122 "format": "{levelname} {asctime} {module} {message}", 

123 "style": "{", 

124 }, 

125 }, 

126 "handlers": { 

127 "console": { 

128 "class": "logging.StreamHandler", 

129 "formatter": "verbose", 

130 }, 

131 "file": { 

132 "level": "INFO", 

133 "class": "logging.handlers.RotatingFileHandler", 

134 "filename": LOG_DIR / "app.log", # Log file location 

135 "maxBytes": 1024 * 1024 * 5, # 5 MB 

136 "backupCount": 5, 

137 "formatter": "verbose", 

138 }, 

139 }, 

140 "loggers": { 

141 "claims": { 

142 "handlers": ["console", "file"], # Send to both console and file 

143 "level": "INFO", 

144 "propagate": False, 

145 }, 

146 "django": { 

147 "handlers": ["console", "file"], # Send to both console and file 

148 "level": "INFO", 

149 "propagate": False, 

150 }, 

151 }, 

152} 

153 

154# Internationalization 

155# https://docs.djangoproject.com/en/5.2/topics/i18n/ 

156 

157LANGUAGE_CODE = "en-us" 

158 

159TIME_ZONE = "America/New_York" 

160 

161USE_I18N = True 

162 

163USE_TZ = True 

164 

165 

166# Static files (CSS, JavaScript, Images) 

167# https://docs.djangoproject.com/en/5.2/howto/static-files/ 

168 

169STATIC_URL = "static/" 

170 

171# Default primary key field type 

172# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field 

173 

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

175 

176LOGIN_URL = "login" 

177LOGIN_REDIRECT_URL = "/" 

178LOGOUT_REDIRECT_URL = "/login/" 

179 

180# For PythonAnywhere configuration 

181# This is where collectstatic will dump all files for production 

182STATIC_ROOT = BASE_DIR / "staticfiles"