-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathsettings.py
246 lines (208 loc) · 8.44 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
"""
Django settings for portal project.
Generated by 'django-admin startproject' using Django 5.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/5.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/5.1/ref/settings/
"""
import os
from pathlib import Path
import dj_database_url
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(os.environ.get("DEBUG", default=0))
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS")
if ALLOWED_HOSTS:
ALLOWED_HOSTS = ALLOWED_HOSTS.split(",")
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sites",
"django_bootstrap5",
"allauth",
"allauth.account",
"portal",
"volunteer",
"portal_account",
"sponsorship",
"dashboard",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"allauth.account.middleware.AccountMiddleware",
]
ROOT_URLCONF = "portal.urls"
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.request",
],
},
},
]
WSGI_APPLICATION = "portal.wsgi.application"
# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
if os.environ.get("DATABASE_URL", None) is not None:
DATABASES = {
"default": dj_database_url.config(
conn_max_age=600,
conn_health_checks=True,
)
}
else:
DATABASES = {
"default": {
"ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"),
"NAME": os.environ.get("SQL_DATABASE", BASE_DIR / "db.sqlite3"),
"USER": os.environ.get("SQL_USER", "user"),
"PASSWORD": os.environ.get("SQL_PASSWORD", "password"),
"HOST": os.environ.get("SQL_HOST", "localhost"),
"PORT": os.environ.get("SQL_PORT", "5432"),
}
}
# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]
# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "staticroot"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
# `allauth` specific authentication methods, such as login by email
"allauth.account.auth_backends.AuthenticationBackend",
]
SITE_ID = 1
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_EMAIL_VERIFICATION_BY_CODE_ENABLED = True
ACCOUNT_EMAIL_SUBJECT_PREFIX = "[PyLadiesCon Dev] "
LOGIN_REDIRECT_URL = "/"
ACCOUNT_LOGIN_METHODS = {"username"}
ACCOUNT_SIGNUP_FIELDS = ["email*", "username*", "first_name*", "last_name*", "password1*", "password2*"]
ACCOUNT_MAX_EMAIL_ADDRESSES = 3
# Use custom signup form
ACCOUNT_FORMS = {
'signup': 'portal.forms.CustomSignupForm'
}
# Default settings
BOOTSTRAP5 = {
# The complete URL to the Bootstrap CSS file.
# Note that a URL can be either a string
# ("https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"),
# or a dict with keys `url`, `integrity` and `crossorigin` like the default value below.
"css_url": {
"url": "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
"integrity": "sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx",
"crossorigin": "anonymous",
},
# The complete URL to the Bootstrap bundle JavaScript file.
"javascript_url": {
"url": "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js",
"integrity": "sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa",
"crossorigin": "anonymous",
},
# The complete URL to the Bootstrap CSS theme file (None means no theme).
"theme_url": None,
# Color mode (None means do not set color mode).
"color_mode": None,
# Put JavaScript in the HEAD section of the HTML document (only relevant if you use bootstrap5.html).
"javascript_in_head": False,
# Wrapper class for non-inline fields.
# The default value "mb-3" is the spacing as used by Bootstrap 5 example code.
"wrapper_class": "mb-3",
# Wrapper class for inline fields.
# The default value is empty, as Bootstrap5 example code doesn't use a wrapper class.
"inline_wrapper_class": "",
# Label class to use in horizontal forms.
"horizontal_label_class": "col-sm-2",
# Field class to use in horizontal forms.
"horizontal_field_class": "col-sm-10",
# Field class used for horizontal fields withut a label.
"horizontal_field_offset_class": "offset-sm-2",
# HTML attributes with any of these prefixes will have underscores converted to hyphens.
"hyphenate_attribute_prefixes": ["data"],
# Set placeholder attributes to label if no placeholder is provided.
"set_placeholder": True,
# Class to indicate required field (better to set this in your Django form).
"required_css_class": "",
# Class to indicate field has one or more errors (better to set this in your Django form).
"error_css_class": "",
# Class to indicate success, meaning the field has valid input (better to set this in your Django form).
"success_css_class": "",
# Enable or disable Bootstrap 5 server side validation classes (separate from the indicator classes above).
"server_side_validation": True,
# Renderers (only set these if you have studied the source and understand the inner workings).
"formset_renderers": {
"default": "django_bootstrap5.renderers.FormsetRenderer",
},
"form_renderers": {
"default": "django_bootstrap5.renderers.FormRenderer",
},
"field_renderers": {
"default": "django_bootstrap5.renderers.FieldRenderer",
},
}
## Email settings
if "DJANGO_EMAIL_HOST" in os.environ:
# If the env vars are set, use them
EMAIL_HOST = os.getenv("DJANGO_EMAIL_HOST")
EMAIL_PORT = os.getenv("DJANGO_EMAIL_PORT")
EMAIL_HOST_USER = os.getenv("DJANGO_EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("DJANOG_EMAIL_HOST_PASSWORD")
EMAIL_USE_TLS = os.getenv("DJANGO_EMAIL_USE_TLS")
DEFAULT_FROM_EMAIL = os.getenv("DJANGO_DEFAULT_FROM_EMAIL")
else:
# Otherwise, send emails to the console
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"