218 lines
7.4 KiB
Python
218 lines
7.4 KiB
Python
"""
|
|
Django settings for tasksnest project.
|
|
|
|
Generated by 'django-admin startproject' using Django 6.1.1.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/6.1/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/6.1/ref/settings/
|
|
"""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/6.1/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = 'django-insecure-x%2-iw9@k2s1td)7m7-ww55w1x(5lh$j*luk8_fbytb-36il%t'
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = True
|
|
|
|
ALLOWED_HOSTS = ["localhost", "127.0.0.1", "tasksnest.jorendegraaf.eu"]
|
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
|
CSRF_TRUSTED_ORIGINS = [
|
|
"https://tasksnest.jorendegraaf.eu",
|
|
]
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'oauth2_provider',
|
|
'planner',
|
|
'food.apps.FoodConfig',
|
|
'recipes',
|
|
'stress',
|
|
'dreams',
|
|
]
|
|
|
|
# Published recipes owned by this account may appear in the optional matching demo.
|
|
RECIPE_MATCH_DEMO_USERNAME = os.environ.get('TASKNEST_RECIPE_MATCH_DEMO_USERNAME', 'demo')
|
|
|
|
MIDDLEWARE = [
|
|
'food.api_middleware.ApiErrorMiddleware',
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
'django.middleware.common.CommonMiddleware',
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
'planner.middleware.UserTimezoneMiddleware',
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
]
|
|
|
|
ROOT_URLCONF = 'tasksnest.urls'
|
|
|
|
OAUTH2_PROVIDER = {
|
|
'OIDC_ISS_ENDPOINT': os.environ.get('TASKNEST_OAUTH_ISSUER_URL',
|
|
'https://tasksnest.jorendegraaf.eu/'),
|
|
'SCOPES': {
|
|
'food:read': 'Read your food diary and saved foods',
|
|
'food:write': 'Create, change, and delete food diary entries and images',
|
|
'inventory:read': 'Read your kitchen inventory',
|
|
'inventory:write': 'Create, change, and remove kitchen inventory items',
|
|
'journal:read': 'Read your private stress and dream journals',
|
|
'journal:write': 'Create, change, and delete stress and dream entries',
|
|
},
|
|
'ACCESS_TOKEN_GENERATOR': 'food.oauth_pat.oauth_access_token',
|
|
'ACCESS_TOKEN_EXPIRE_SECONDS': 3600,
|
|
'REFRESH_TOKEN_EXPIRE_SECONDS': 604800,
|
|
'ROTATE_REFRESH_TOKEN': True,
|
|
'REFRESH_TOKEN_REUSE_PROTECTION': True,
|
|
'CIMD_ENABLED': True,
|
|
'CIMD_METADATA_FETCHER': 'food.cimd.CompatibleCIMDFetcher',
|
|
'DCR_ENABLED': False,
|
|
'OAUTH2_GRANT_TYPES_SUPPORTED': ['authorization_code', 'refresh_token'],
|
|
'OAUTH2_TOKEN_ENDPOINT_AUTH_METHODS_SUPPORTED': ['none', 'client_secret_basic', 'client_secret_post'],
|
|
'COMPLIANT_BCP_RFC9700_TOKEN_STORAGE': True,
|
|
'COMPLIANT_BCP_RFC9700_PKCE_METHOD': True,
|
|
'COMPLIANT_BCP_RFC9700_PKCE_REQUIRED': True,
|
|
'COMPLIANT_BCP_RFC9700_ACCESS_TOKEN_TRANSPORT': True,
|
|
'COMPLIANT_BCP_RFC9700_AUTHZ_RESPONSE_ISS': True,
|
|
'COMPLIANT_BCP_RFC9700_IMPLICIT_GRANT': True,
|
|
'COMPLIANT_BCP_RFC9700_PASSWORD_GRANT': True,
|
|
}
|
|
TASKNEST_MCP_PUBLIC_URL = os.environ.get('TASKNEST_MCP_PUBLIC_URL',
|
|
'https://tasksnest.jorendegraaf.eu/mcp')
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
'planner.context_processors.appearance',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'tasksnest.wsgi.application'
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/6.1/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': BASE_DIR / 'db.sqlite3',
|
|
}
|
|
}
|
|
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/6.1/ref/settings/#auth-password-validators
|
|
|
|
AUTH_PASSWORD_VALIDATORS = [
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
|
},
|
|
{
|
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
|
},
|
|
]
|
|
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/6.1/topics/i18n/
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
TIME_ZONE = 'Europe/Amsterdam'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/6.1/howto/static-files/
|
|
|
|
STATIC_URL = 'static/'
|
|
MEDIA_ROOT = BASE_DIR / 'private_media'
|
|
|
|
# Vite writes built assets and its manifest here. Use the Vite server only when
|
|
# explicitly requested by the HMR workflow.
|
|
VITE_DEV_SERVER = os.environ.get('VITE_DEV_SERVER', 'http://localhost:5173')
|
|
VITE_USE_DEV_SERVER = os.environ.get('VITE_USE_DEV_SERVER', 'false').lower() in {'1', 'true', 'yes'}
|
|
VITE_MANIFEST_PATH = BASE_DIR / 'planner' / 'static' / 'planner' / 'dist' / '.vite' / 'manifest.json'
|
|
|
|
# Open Food Facts is queried only by explicit food search or product lookup.
|
|
OPENFOODFACTS_ENABLED = os.environ.get('OPENFOODFACTS_ENABLED', 'true').lower() in {'1', 'true', 'yes'}
|
|
OPENFOODFACTS_PRODUCT_URL = os.environ.get('OPENFOODFACTS_PRODUCT_URL', 'https://world.openfoodfacts.org/api/v2/product/{barcode}.json')
|
|
OPENFOODFACTS_SEARCH_URL = os.environ.get('OPENFOODFACTS_SEARCH_URL', 'https://world.openfoodfacts.org/cgi/search.pl')
|
|
OPENFOODFACTS_USER_AGENT = os.environ.get('OPENFOODFACTS_USER_AGENT', 'Tasknest/1.0 (https://tasksnest.jorendegraaf.eu)')
|
|
OPENFOODFACTS_TIMEOUT_SECONDS = float(os.environ.get('OPENFOODFACTS_TIMEOUT_SECONDS', '6'))
|
|
|
|
# Optional Gitea contribution grid on the task dashboard. Read only these
|
|
# values from the repository's ignored .env file; the process environment wins.
|
|
def _gitea_env(name, default=''):
|
|
if name in os.environ:
|
|
return os.environ[name]
|
|
env_file = BASE_DIR.parent / '.env'
|
|
try:
|
|
lines = env_file.read_text(encoding='utf-8').splitlines()
|
|
except FileNotFoundError:
|
|
return default
|
|
for line in lines:
|
|
key, separator, value = line.strip().partition('=')
|
|
if separator and key.strip() == name:
|
|
value = value.strip()
|
|
if len(value) >= 2 and value[0] == value[-1] and value[0] in {'"', "'"}:
|
|
value = value[1:-1]
|
|
return value
|
|
return default
|
|
|
|
|
|
GITEA_BASE_URL = _gitea_env('GITEA_BASE_URL', 'https://git.jorendegraaf.eu').rstrip('/')
|
|
GITEA_USERNAME = _gitea_env('GITEA_USERNAME').strip()
|
|
GITEA_TOKEN = _gitea_env('GITEA_TOKEN').strip()
|
|
|
|
LOGIN_URL = 'planner:login'
|
|
LOGIN_REDIRECT_URL = 'planner:task-list'
|
|
LOGOUT_REDIRECT_URL = 'planner:login'
|
|
|
|
|
|
# Email
|
|
# https://docs.djangoproject.com/en/6.1/topics/email/#topic-email-configuration
|
|
|
|
MAILERS = {
|
|
'default': {
|
|
'BACKEND': 'django.core.mail.backends.console.EmailBackend',
|
|
},
|
|
}
|