99 lines
2.8 KiB
Python
99 lines
2.8 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
def _load_env_file(path: Path) -> None:
|
|
"""Fill unset variables from a local env file. The process environment wins."""
|
|
if not path.is_file():
|
|
return
|
|
for raw in path.read_text(encoding='utf-8').splitlines():
|
|
line = raw.strip()
|
|
if not line or line.startswith('#') or '=' not in line:
|
|
continue
|
|
key, value = line.split('=', 1)
|
|
key = key.strip()
|
|
if not key or key in os.environ:
|
|
continue
|
|
value = value.strip()
|
|
if len(value) >= 2 and value[0] == value[-1] and value[0] in '"\'':
|
|
value = value[1:-1]
|
|
os.environ[key] = value
|
|
|
|
|
|
_load_env_file(BASE_DIR / '.env')
|
|
|
|
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'dev-secret-key-change-in-production')
|
|
|
|
DEBUG = os.environ.get('DJANGO_DEBUG', '1') == '1'
|
|
|
|
ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS', '*').split(',')
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'slips',
|
|
]
|
|
|
|
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',
|
|
]
|
|
|
|
ROOT_URLCONF = 'config.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [],
|
|
'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',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'config.wsgi.application'
|
|
|
|
# Database - SQLite, stored in /app/data/ for Docker volume persistence
|
|
db_path = os.environ.get('DB_PATH', str(BASE_DIR / 'data' / 'db.sqlite3'))
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': db_path,
|
|
}
|
|
}
|
|
|
|
AUTH_PASSWORD_VALIDATORS = []
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
TIME_ZONE = 'Asia/Tehran'
|
|
USE_I18N = True
|
|
USE_TZ = True
|
|
|
|
STATIC_URL = '/static/'
|
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
|
STORAGES = {
|
|
'staticfiles': {
|
|
'BACKEND': 'whitenoise.storage.CompressedManifestStaticFilesStorage',
|
|
},
|
|
}
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|