Skip to content

Commit 0b874bd

Browse files
authored
Merge pull request #64 from HackSoftware/settings-structure
Improve settings structure
2 parents 485e5f7 + 21a7dfa commit 0b874bd

File tree

22 files changed

+160
-134
lines changed

22 files changed

+160
-134
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
PYTHONBREAKPOINT=ipdb.set_trace
2+
SENTRY_DSN=""

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ For `production.py`, we have the following:
2828

2929
```python
3030
CORS_ALLOW_ALL_ORIGINS = False
31-
CORS_ORIGIN_WHITELIST = env.list('DJANGO_CORS_ORIGIN_WHITELIST', default=[])
31+
CORS_ORIGIN_WHITELIST = env.list('CORS_ORIGIN_WHITELIST', default=[])
3232
```
3333

3434
### DRF

config/asgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
from django.core.asgi import get_asgi_application
1313

14-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.django.base')
1515

1616
application = get_asgi_application()

config/django/__init__.py

Whitespace-only changes.

config/settings/base.py renamed to config/django/base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import os
1414

15-
from .env_reader import env, environ
15+
from config.env import env, environ
1616

1717
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1818
BASE_DIR = environ.Path(__file__) - 3
@@ -166,6 +166,7 @@
166166
'DEFAULT_AUTHENTICATION_CLASSES': []
167167
}
168168

169-
from .cors import * # noqa
170-
from .sessions import * # noqa
171-
from .celery import * # noqa
169+
from config.settings.cors import * # noqa
170+
from config.settings.sessions import * # noqa
171+
from config.settings.celery import * # noqa
172+
from config.settings.sentry import * # noqa

config/django/local.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .base import * # noqa
2+
3+
CELERY_BROKER_BACKEND = "memory"
4+
CELERY_TASK_ALWAYS_EAGER = True
5+
CELERY_TASK_EAGER_PROPAGATES = True

config/django/production.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from .base import * # noqa
2+
3+
from config.env import env
4+
5+
DEBUG = env.bool('DJANGO_DEBUG', default=False)
6+
7+
SECRET_KEY = env('SECRET_KEY')
8+
9+
ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=[])
10+
11+
CORS_ALLOW_ALL_ORIGINS = False
12+
CORS_ORIGIN_WHITELIST = env.list('CORS_ORIGIN_WHITELIST', default=[])
13+
14+
SESSION_COOKIE_SECURE = env.bool('SESSION_COOKIE_SECURE', default=True)
15+
16+
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
17+
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
18+
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
19+
SECURE_SSL_REDIRECT = env.bool("SECURE_SSL_REDIRECT", default=True)
20+
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
21+
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
22+
"SECURE_CONTENT_TYPE_NOSNIFF", default=True
23+
)

config/django/test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from .base import * # noqa
2+
3+
# Based on https://www.hacksoft.io/blog/optimize-django-build-to-run-faster-on-github-actions
4+
5+
DEBUG = False
6+
PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher']
7+
8+
CELERY_BROKER_BACKEND = "memory"
9+
CELERY_TASK_ALWAYS_EAGER = True
10+
CELERY_TASK_EAGER_PROPAGATES = True
11+
12+
CACHES = {
13+
"default": {
14+
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
15+
}
16+
}
File renamed without changes.

config/settings/celery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from .env_reader import env
1+
from config.env import env
22

33
# https://docs.celeryproject.org/en/stable/userguide/configuration.html
44

5-
CELERY_BROKER_URL = env('DJANGO_CELERY_BROKER_URL', default='amqp://guest:guest@localhost//')
5+
CELERY_BROKER_URL = env('CELERY_BROKER_URL', default='amqp://guest:guest@localhost//')
66
CELERY_RESULT_BACKEND = 'django-db'
77

88
CELERY_TIMEZONE = 'UTC'

0 commit comments

Comments
 (0)