Skip to content

Commit 15176b4

Browse files
committed
WIP
1 parent d6378b7 commit 15176b4

File tree

4 files changed

+109
-36
lines changed

4 files changed

+109
-36
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
**/.venv
22
*console.log
33
.coverage
4-
.env
4+
.env*
55
.idea/
66
.mypy_cache/**/*
77
.pytest_cache/**/*

config/settings/_base.py

Lines changed: 93 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,64 @@
11
import contextlib
22
import socket
3+
from pathlib import Path
34

4-
import environs
5-
6-
env = environs.Env()
5+
from django_envtools import Env
76

87
"""
98
Django settings for config project.
109
1110
For more information on this file, see
12-
https://docs.djangoproject.com/en/4.2/topics/settings/
11+
https://docs.djangoproject.com/en/dev/topics/settings/
1312
1413
For the full list of settings and their values, see
15-
https://docs.djangoproject.com/en/4.2/ref/settings/
14+
https://docs.djangoproject.com/en/dev/ref/settings/
1615
"""
1716

18-
BASE_DIR = environs.Path(__file__).parent.parent.parent # type: ignore
17+
BASE_DIR = Path(__file__).parent.parent.parent # type: ignore
18+
19+
env = Env()
1920

2021
READ_DOT_ENV_FILE = env.bool("READ_DOT_ENV_FILE", default=True)
2122

2223
if READ_DOT_ENV_FILE is True:
2324
env.read_env(str(BASE_DIR.joinpath(".env")))
2425

2526
# Quick-start development settings - unsuitable for production
26-
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
27+
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
2728

2829
# SECURITY WARNING: keep the secret key used in production secret!
29-
SECRET_KEY = env("SECRET_KEY")
30+
SECRET_KEY = env.str(
31+
"SECRET_KEY",
32+
help_text="Django's secret key, see"
33+
"https://docs.djangoproject.com/en/dev/ref/settings/#secret-key for more information",
34+
initial_func="django.core.management.utils.get_random_secret_key",
35+
)
3036

3137
# SECURITY WARNING: don't run with debug turned on in production!
32-
DEBUG = env.bool("DEBUG", default=False)
38+
DEBUG = env.bool("DEBUG", default=False, initial="on", help_text="Set to `on` to enable debugging")
3339

34-
ALLOWED_HOSTS: list[str] = env.list("ALLOWED_HOSTS", default=[])
35-
INTERNAL_IPS = env.list("INTERNAL_IPS", default=["127.0.0.1"])
40+
ALLOWED_HOSTS = env.list(
41+
"ALLOWED_HOSTS",
42+
default=[],
43+
help_text="List of allowed hosts (e.g., `127.0.0.1,example.com`), see "
44+
"https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts for more information",
45+
)
46+
47+
INTERNAL_IPS = env.list(
48+
"INTERNAL_IPS",
49+
default=["127.0.0.1"],
50+
initial="127.0.0.1,0.0.0.0",
51+
help_text="IPs that are allowed to use debug() (e.g., `127.0.0.1,example.com`), see "
52+
"https://docs.djangoproject.com/en/dev/ref/settings/#internal-ips for more information",
53+
)
3654

3755
# Get the IP to use for Django Debug Toolbar when developing with docker
38-
if env.bool("USE_DOCKER", default=False) is True:
56+
if (
57+
env.bool(
58+
"USE_DOCKER", default=False, help_text="Boolean used to add docker's internal ip to the `INTERNAL_IPS` setting"
59+
)
60+
is True
61+
):
3962
ip = socket.gethostbyname(socket.gethostname())
4063
INTERNAL_IPS += [ip[:-1] + "1"]
4164

@@ -56,6 +79,7 @@
5679
"allauth.account",
5780
"crispy_forms",
5881
"crispy_bootstrap5",
82+
"django_envtools",
5983
"storages",
6084
]
6185

@@ -92,23 +116,35 @@
92116
},
93117
]
94118

95-
WSGI_APPLICATION = env("WSGI_APPLICATION", default="config.wsgi.application")
96-
DB_SSL_REQUIRED = env.bool("DB_SSL_REQUIRED", default=not DEBUG)
119+
WSGI_APPLICATION = env.str(
120+
"WSGI_APPLICATION",
121+
default="config.wsgi.application",
122+
help_text="WSGI application callable, see https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application for "
123+
"more information",
124+
)
125+
DB_SSL_REQUIRED = env.bool(
126+
"DB_SSL_REQUIRED",
127+
default=not DEBUG,
128+
help_text="Set to `on` to require SSL for database connections, default is `off` when DEBUG is `on`",
129+
)
97130

98-
# Database
99-
# See https://github.com/jacobian/dj-database-url for more examples
100131
DATABASES = {
101132
"default": env.dj_db_url(
102-
"DATABASE_URL", default="postgres://postgres@postgres/postgres", ssl_require=DB_SSL_REQUIRED
133+
"DATABASE_URL",
134+
default="postgres://postgres@postgres/postgres",
135+
ssl_require=DB_SSL_REQUIRED,
136+
initial="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}",
137+
help_text="Database URL for the default database, see https://github.com/jacobian/dj-database-url for "
138+
"more examples",
103139
)
104140
}
105141

106142
# Custom User Model
107-
# https://docs.djangoproject.com/en/4.2/topics/auth/customizing/#substituting-a-custom-user-model
143+
# https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model
108144
AUTH_USER_MODEL = "accounts.User"
109145

110146
# Password validation
111-
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
147+
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
112148

113149
AUTH_PASSWORD_VALIDATORS = [
114150
{
@@ -127,7 +163,7 @@
127163

128164

129165
# Internationalization
130-
# https://docs.djangoproject.com/en/4.2/topics/i18n/
166+
# https://docs.djangoproject.com/en/dev/topics/i18n/
131167

132168
LANGUAGE_CODE = "en-us"
133169

@@ -140,30 +176,42 @@
140176

141177

142178
# Static files (CSS, JavaScript, Images)
143-
# https://docs.djangoproject.com/en/4.2/howto/static-files/
179+
# https://docs.djangoproject.com/en/dev/howto/static-files/
144180

145181
STATICFILES_FINDERS = (
146182
"django.contrib.staticfiles.finders.FileSystemFinder",
147183
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
148184
)
149185

186+
DEFAULT_FILE_STORAGE = env.str(
187+
"DEFAULT_FILE_STORAGE",
188+
default="django.core.files.storage.FileSystemStorage",
189+
help_text="Default file storage backend, see https://docs.djangoproject.com/en/dev/ref/settings/#storages for "
190+
"more information",
191+
)
192+
STATICFILES_STORAGE = env.str(
193+
"DEFAULT_FILE_STORAGE",
194+
default="django.core.files.storage.FileSystemStorage",
195+
help_text="Default file storage for staticfiles, see https://docs.djangoproject.com/en/dev/ref/settings/#storages "
196+
"for more information",
197+
)
150198
STORAGES = {
151199
"default": {
152-
"BACKEND": env("DEFAULT_FILE_STORAGE", default="django.core.files.storage.FileSystemStorage"),
200+
"BACKEND": DEFAULT_FILE_STORAGE,
153201
},
154202
"staticfiles": {
155-
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
203+
"BACKEND": STATICFILES_STORAGE,
156204
},
157205
}
158206

159207

160208
if STORAGES["default"]["BACKEND"].endswith("MediaS3Storage") is True:
161-
STORAGES["staticfiles"]["BACKEND"] = env("STATICFILES_STORAGE")
162-
AWS_ACCESS_KEY_ID = env("AWS_ACCESS_KEY_ID")
163-
AWS_SECRET_ACCESS_KEY = env("AWS_SECRET_ACCESS_KEY")
164-
AWS_STORAGE_BUCKET_NAME = env("AWS_STORAGE_BUCKET_NAME")
209+
STORAGES["staticfiles"]["BACKEND"] = STATICFILES_STORAGE
210+
AWS_ACCESS_KEY_ID = env.str("AWS_ACCESS_KEY_ID", help_text="AWS Access Key ID for S3 storage")
211+
AWS_SECRET_ACCESS_KEY = env.str("AWS_SECRET_ACCESS_KEY", help_text="AWS Secret Access Key for S3 storage")
212+
AWS_STORAGE_BUCKET_NAME = env.str("AWS_STORAGE_BUCKET_NAME", help_text="AWS S3 Bucket Name for storage")
165213
AWS_DEFAULT_ACL = "public-read"
166-
AWS_S3_REGION = env("AWS_S3_REGION", default="us-east-2")
214+
AWS_S3_REGION = env.str("AWS_S3_REGION", default="us-east-1", help_text="AWS S3 Region for storage")
167215
AWS_S3_CUSTOM_DOMAIN = f"s3.{AWS_S3_REGION}.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}"
168216
AWS_S3_OBJECT_PARAMETERS = {"CacheControl": "max-age=86400"}
169217
STATIC_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/static/"
@@ -181,13 +229,21 @@
181229
STATIC_URL = "/public/static/"
182230

183231
# Default primary key field type
184-
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
232+
# https://docs.djangoproject.com/en/dev/ref/settings/#default-auto-field
185233
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
186234

187235
# CACHE SETTINGS
188-
# Redis scheme docs: https://redis-py.readthedocs.io/en/stable/connections.html#redis.connection.ConnectionPool.from_url
189-
REDIS_URL = env("REDIS_URL", "redis://redis:6379/0")
190-
REDIS_PREFIX = env("REDIS_PREFIX", default="")
236+
REDIS_URL = env.str(
237+
"REDIS_URL",
238+
default="redis://redis:6379/0",
239+
help_text="URL used to connect to Redis, see https://docs.djangoproject.com/en/dev/ref/settings/#location for "
240+
"more information",
241+
)
242+
REDIS_PREFIX = env.str(
243+
"REDIS_PREFIX",
244+
default="",
245+
help_text="Prefix for all Redis keys, useful to avoid key collisions in shared Redis instances",
246+
)
191247
CACHES = {
192248
"default": {
193249
"BACKEND": "django.core.cache.backends.redis.RedisCache",
@@ -232,10 +288,10 @@
232288
ACCOUNT_SIGNUP_OPEN = False
233289
ACCOUNT_SHOW_POST_LOGIN_MESSAGE = False
234290

235-
# See https://github.com/migonzalvar/dj-email-url for more examples on how to set the EMAIL_URL
236291
email = env.dj_email_url(
237292
"EMAIL_URL",
238293
default="smtp://[email protected]:[email protected]:587/?ssl=True&_default_from_email=President%20Skroob%20%[email protected]%3E",
294+
help_text="Email URL for sending emails, see https://github.com/migonzalvar/dj-email-url for more examples",
239295
)
240296
DEFAULT_FROM_EMAIL = email["DEFAULT_FROM_EMAIL"]
241297
EMAIL_HOST = email["EMAIL_HOST"]
@@ -266,7 +322,7 @@ def log_format() -> str:
266322

267323

268324
log_level = "WARNING"
269-
IS_DEBUG_LOGGING_ON = env.bool("IS_DEBUG_LOGGING_ON", default=False)
325+
IS_DEBUG_LOGGING_ON = env.bool("IS_DEBUG_LOGGING_ON", default=False, help_text="Set to `on` to enable debug logging")
270326
if IS_DEBUG_LOGGING_ON is True:
271327
log_level = "DEBUG"
272328

@@ -305,4 +361,6 @@ def log_format() -> str:
305361
MAINTENANCE_MODE_STATE_BACKEND = "maintenance_mode.backends.CacheBackend"
306362
MAINTENANCE_MODE_STATE_BACKEND_FALLBACK_VALUE = True
307363

308-
VITE_DEV_MODE = env.bool("VITE_DEV_MODE", default=DEBUG)
364+
VITE_DEV_MODE = env.bool(
365+
"VITE_DEV_MODE", default=DEBUG, help_text="Set to `on` to enable Vite development mode for HMR in the browser"
366+
)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies = [
1111
"django-alive~=2.0",
1212
"django-allauth~=65.0",
1313
"django-crispy-forms~=2.2",
14+
"django-envtools~=0.2",
1415
"django-maintenance-mode~=0.19",
1516
"django-storages~=1.8",
1617
"environs[django]~=14.1",

uv.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)