- shared-moduuli: DomainError, EmailAddress, UnitOfWork, tapahtumat, TimestampedModel, daisyUI-lomakerenderöinti ja yhteiset pohjat - users-moduuli Clean Architecture -kerroksin: oma käyttäjämalli (AUTH_USER_MODEL), roolit ja oikeudet, harjoittelija-, vastuuhenkilö- ja viimeisen pääkäyttäjän säännöt - kirjautuminen sähköpostilla, yritysten rajoitus, "muista minut", istunnon katkaisu kun tunnus poistetaan käytöstä tai harjoittelu päättyy - kertakäyttöiset salasanalinkit (72 h / 60 min, uusi mitätöi vanhan), salasanasääntö ja create_admin-komento - käyttäjähallinta: lista (HTMX-haku), lomakkeet ja kopioitava linkki - Tailwind 4 + daisyUI 5 + HTMX + Alpine npm-buildilla, suomennokset - testit: domain, application (fakeilla), integraatio ja selaintestit (axe, vaalea/tumma, 1920/320 px); ruff, mypy ja import-linter - dokumentit päivitetty toteutuksen mukaisiksi Co-Authored-By: Claude Opus 5.5 <[email protected]>
201 lines
6.1 KiB
Python
201 lines
6.1 KiB
Python
"""
|
|
Django settings for config project.
|
|
|
|
Generated by 'django-admin startproject' using Django 5.2.19.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/5.2/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/5.2/ref/settings/
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
# Ladataan ympäristömuuttujat .env-tiedostosta
|
|
load_dotenv(BASE_DIR / ".env")
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = os.getenv("DJANGO_DEBUG", "False").lower() in ("1", "true", "yes")
|
|
|
|
ALLOWED_HOSTS = [h.strip() for h in os.getenv("DJANGO_ALLOWED_HOSTS", "").split(",") if h.strip()]
|
|
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
"django.forms",
|
|
"django_htmx",
|
|
"apps.shared",
|
|
"apps.users",
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
"django.middleware.locale.LocaleMiddleware",
|
|
"django.middleware.common.CommonMiddleware",
|
|
"django.middleware.csrf.CsrfViewMiddleware",
|
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
"django.contrib.auth.middleware.LoginRequiredMiddleware",
|
|
"apps.users.presentation.middleware.EnsureAccountIsUsable",
|
|
"django_htmx.middleware.HtmxMiddleware",
|
|
"django.contrib.messages.middleware.MessageMiddleware",
|
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
|
]
|
|
|
|
ROOT_URLCONF = "config.urls"
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
# Project templates + each module's presentation/templates.
|
|
"DIRS": [
|
|
BASE_DIR / "templates",
|
|
*sorted((BASE_DIR / "apps").glob("*/presentation/templates")),
|
|
],
|
|
"APP_DIRS": True,
|
|
"OPTIONS": {
|
|
"context_processors": [
|
|
"django.template.context_processors.request",
|
|
"django.contrib.auth.context_processors.auth",
|
|
"django.contrib.messages.context_processors.messages",
|
|
],
|
|
"builtins": ["django.templatetags.i18n"],
|
|
# Module template tags live in <module>/presentation/templatetags.
|
|
"libraries": {
|
|
"users_tags": "apps.users.presentation.templatetags.users_tags",
|
|
},
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = "config.wsgi.application"
|
|
|
|
FORM_RENDERER = "apps.shared.presentation.forms.DaisyFormRenderer"
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.mysql",
|
|
"NAME": os.getenv("DB_NAME", "django-toiminnanohjaus"),
|
|
"USER": os.getenv("DB_USER", "root"),
|
|
"PASSWORD": os.getenv("DB_PASSWORD", ""),
|
|
"HOST": os.getenv("DB_HOST", "127.0.0.1"),
|
|
"PORT": os.getenv("DB_PORT", "3306"),
|
|
"OPTIONS": {
|
|
"charset": "utf8mb4",
|
|
"init_command": "SET sql_mode='STRICT_TRANS_TABLES'",
|
|
},
|
|
}
|
|
}
|
|
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
|
},
|
|
{
|
|
"NAME": "apps.users.infrastructure.password.ComplexityValidator",
|
|
},
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
|
},
|
|
{
|
|
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
|
},
|
|
]
|
|
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/5.2/topics/i18n/
|
|
|
|
LANGUAGE_CODE = "fi"
|
|
|
|
TIME_ZONE = "Europe/Helsinki"
|
|
|
|
USE_I18N = True
|
|
|
|
LANGUAGES = [("fi", "Suomi")]
|
|
LOCALE_PATHS = [BASE_DIR / "locale"]
|
|
|
|
# Business day boundaries (intern end dates, cash days) are computed in this zone.
|
|
BUSINESS_TIME_ZONE = "Europe/Helsinki"
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/5.2/howto/static-files/
|
|
|
|
STATIC_URL = "static/"
|
|
STATICFILES_DIRS = [BASE_DIR / "static"]
|
|
STATIC_ROOT = BASE_DIR / "staticfiles"
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
|
|
# Authentication (docs/architecture.md, luku 14)
|
|
AUTH_USER_MODEL = "users.User"
|
|
AUTHENTICATION_BACKENDS = ["apps.users.infrastructure.auth.EmailBackend"]
|
|
LOGIN_URL = "users:login"
|
|
LOGIN_REDIRECT_URL = "home"
|
|
LOGOUT_REDIRECT_URL = "users:login"
|
|
PASSWORD_LINK_SETUP_TIMEOUT = 72 * 60 * 60 # link created by an admin
|
|
PASSWORD_RESET_TIMEOUT = 60 * 60 # "forgot password" link
|
|
SESSION_COOKIE_AGE = 14 * 24 * 60 * 60 # "remember me"
|
|
|
|
# Login throttling uses the cache, so it must be shared between processes.
|
|
CACHES = {
|
|
"default": {
|
|
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
|
|
"LOCATION": "django_cache",
|
|
}
|
|
}
|
|
|
|
# Email
|
|
EMAIL_BACKEND = os.getenv("EMAIL_BACKEND", "django.core.mail.backends.console.EmailBackend")
|
|
EMAIL_HOST = os.getenv("EMAIL_HOST", "localhost")
|
|
EMAIL_PORT = int(os.getenv("EMAIL_PORT", "25"))
|
|
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
|
|
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
|
|
EMAIL_USE_TLS = os.getenv("EMAIL_USE_TLS", "False").lower() in ("1", "true", "yes")
|
|
DEFAULT_FROM_EMAIL = os.getenv("DEFAULT_FROM_EMAIL", "toiminnanohjaus@localhost")
|
|
|
|
# Absolute base URL for links in emails.
|
|
SITE_URL = os.getenv("SITE_URL", "http://127.0.0.1:8000")
|
|
|
|
LOGGING = {
|
|
"version": 1,
|
|
"disable_existing_loggers": False,
|
|
"handlers": {"console": {"class": "logging.StreamHandler"}},
|
|
"root": {"handlers": ["console"], "level": "WARNING"},
|
|
}
|