Skip to content

Commit

Permalink
split code and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Diacquenod committed Jan 13, 2025
1 parent 62c1e40 commit a7f9d6c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
24 changes: 24 additions & 0 deletions env-exemple
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
DEBUG = True
SECRET_KEY='django-insecure-oy-h!94w($b%mb2l-jv&g!1-7iqa9(jc!c=guv=%31_z%yyghr'
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True

STATIC_URL = 'static/'
STATIC_ROOT = 'static'
DB_NAME = 'db.sqlite3'

SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = 'Strict'
SESSION_COOKIE_NAME = '__Host-sessionid'

CSRF_USE_SESSIONS = True

SECURE_SSL_REDIRECT = True
SECURE_HSTS_SECONDS = '15768000'
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True

ALLOWED_HOSTS = '127.0.0.1'
44 changes: 22 additions & 22 deletions oxomium/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
from decouple import config, Csv

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -19,25 +20,24 @@
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-oy-h!94w($b%mb2l-jv&g!1-7iqa9(jc!c=guv=%31_z%yyghr'
SECRET_KEY = config('SECRET_KEY', default='django-insecure-oy-h!94w($b%mb2l-jv&g!1-7iqa9(jc!c=guv=%31_z%yyghr')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = config('DEBUG', default='False', cast=bool)

# SECURITY WARNING: to be configured before production setup
ALLOWED_HOSTS = []

ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='[localhost,127.0.0.1]', cast=Csv())

# SECURITY WARNING: to be enabled of production usage
#SECURE_SSL_REDIRECT = True
#SESSION_COOKIE_SECURE = True
#SESSION_COOKIE_HTTPONLY = True
#SESSION_COOKIE_SAMESITE = 'Strict'
#SESSION_COOKIE_NAME = '__Host-sessionid'
#CSRF_USE_SESSIONS = True
#SECURE_HSTS_SECONDS = 15768000
#SECURE_HSTS_INCLUDE_SUBDOMAINS = True
#SECURE_HSTS_PRELOAD = True
SESSION_COOKIE_SECURE = config('SESSION_COOKIE_SECURE', default=False, cast=bool)
SESSION_COOKIE_HTTPONLY = config('SESSION_COOKIE_HTTPONLY', default=False, cast=bool)
SESSION_COOKIE_SAMESITE = config('SESSION_COOKIE_SAMESITE', default='Lax')
SESSION_COOKIE_NAME = config('SESSION_COOKIE_NAME', default='sessionid')
CSRF_USE_SESSIONS = config('CSRF_USE_SESSIONS', default=False, cast=bool)
SECURE_SSL_REDIRECT = config('SECURE_SSL_REDIRECT', default=False, cast=bool)
SECURE_HSTS_SECONDS = config('SECURE_HSTS_SECONDS', default=0, cast=int)
SECURE_HSTS_INCLUDE_SUBDOMAINS = config('SECURE_HSTS_INCLUDE_SUBDOMAINS', default=False, cast=bool)
SECURE_HSTS_PRELOAD = config('SECURE_HSTS_PRELOAD', default=False, cast=bool)

# Application definition

Expand Down Expand Up @@ -95,7 +95,7 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'NAME': BASE_DIR / config('DB_NAME', default='db.sqlite3'),
}
}

Expand All @@ -122,26 +122,26 @@
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
LANGUAGE_CODE = config('LANGUAGE_CODE', default='en-us')
TIME_ZONE = config('TIME_ZONE', default='UTC')
USE_I18N = config('USE_I18N', default='True', cast=bool)
USE_TZ = config('USE_TZ', default='True', cast=bool)


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = 'static/'
STATIC_ROOT = 'static'
STATIC_URL = config('STATIC_URL', default='static/')
STATIC_ROOT = config('STATIC_ROOT', default='static')

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# Login / Logout configuration
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"
LOGIN_REDIRECT_URL = config('STATIC_ROOT', default='/')
LOGOUT_REDIRECT_URL = config('STATIC_ROOT', default='/')

# AuditLog configuration
AUDITLOG_INCLUDE_ALL_MODELS = True
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ django-auditlog
django-tinymce
django-filter
django-tables2
python-magic
python-magic
python-decouple

0 comments on commit a7f9d6c

Please sign in to comment.