2025.09.17-19:07:57

This commit is contained in:
2025-09-17 19:07:58 +02:00
parent ff37c9cd8b
commit 38a85cb9d5
47 changed files with 1530 additions and 38 deletions

View File

@@ -11,13 +11,20 @@ https://docs.djangoproject.com/en/5.2/ref/settings/
"""
from pathlib import Path
from django.urls import reverse_lazy
import sys
from environ import Env
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
LOCAL_DIR = Path(__file__).resolve().parent / "local"
ENV = Env(
DEBUG=(bool,False),
DOTENV=(Path,LOCAL_DIR/'.env'),
DOTENV_PROD=(Path,LOCAL_DIR/'.env.prod'),
DOTENV_DEVEL=(Path,LOCAL_DIR/'.env.dev'),
DATABASE_URL=(str,f"sqlite:///{str(BASE_DIR/"db.sqlite3").replace("\\","/")}"),
ALLOWED_HOSTS=(list,['*']),
STATIC_URL=(str,"static/"),
@@ -28,15 +35,18 @@ ENV = Env(
EMAIL_BACKEND=(str,"console"),
)
DEBUG = ENV.bool("DEBUG")
_env_file = Path(ENV.path("DOTENV"))
if _env_file.is_file():
ENV.read_env(_env_file)
DEBUG = ENV.bool("DEBUG")
if DEBUG:
_env_file = Path(ENV.path("DOTENV",str(BASE_DIR/'.env.dev'))).resolve()
_env_file = Path(ENV.path("DOTENV_DEVEL")).resolve()
if _env_file.is_file():
ENV.read_env(_env_file)
else:
_env_file = Path(ENV.path("DOTENV",str(BASE_DIR/'.env.prod'))).resolve()
_env_file = Path(ENV.path("DOTENV_PROD")).resolve()
if _env_file.is_file():
ENV.read_env(_env_file)
del _env_file
@@ -119,7 +129,7 @@ ROOT_URLCONF = 'django_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [BASE_DIR/"templates"],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
@@ -174,6 +184,8 @@ USE_I18N = True
USE_TZ = True
# Auth settings
LOGIN_REDIRECT_URL = reverse_lazy('tinywiki:home')
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.2/howto/static-files/
@@ -186,6 +198,9 @@ MEDIA_ROOT = ENV("MEDIA_ROOT")
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
STATICFILES_DIRS = [
BASE_DIR/"static",
]
if ENV("EMAIL_BACKEND") == 'smtp':
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
@@ -200,5 +215,25 @@ else:
if ENV("EMAIL_BACKEND") != 'console':
print("Email backend not known falling back to console!",file=sys.stderr)
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
_secret_key = LOCAL_DIR / "secret_key.py"
if _secret_key.is_file():
from .local import secret_key
if hasattr(secret_key,'SECRET_KEY'):
SECRET_KEY = secret_key.SECRET_KEY
if hasattr(secret_key,"SECRET_KEY_FALLBACKS"):
SECRET_KEY_FALLBACKS = secret_key.SECRET_KEY_FALLBACKS
_local_settings = LOCAL_DIR / "settings.py"
if _local_settings.is_file():
from .local.settings import *
if DEBUG:
_local_settings = LOCAL_DIR / "settings_dev.py"
if _local_settings.is_file():
from .local.settings_dev import *
else:
_local_settings = LOCAL_DIR / "settings_prod.py"
if _local_settings.is_file():
from .local.settings_prod import *
del _local_settings