2021-08-22 20:10:29 +02:00
|
|
|
"""
|
|
|
|
Django settings for rpg_notes project.
|
|
|
|
|
|
|
|
Generated by 'django-admin startproject' using Django 3.2.6.
|
|
|
|
|
|
|
|
For more information on this file, see
|
|
|
|
https://docs.djangoproject.com/en/3.2/topics/settings/
|
|
|
|
|
|
|
|
For the full list of settings and their values, see
|
|
|
|
https://docs.djangoproject.com/en/3.2/ref/settings/
|
|
|
|
"""
|
2021-10-07 11:43:45 +02:00
|
|
|
from datetime import timedelta
|
2021-08-22 20:10:29 +02:00
|
|
|
from pathlib import Path
|
2021-09-11 18:46:17 +02:00
|
|
|
from subprocess import run
|
2021-08-22 20:10:29 +02:00
|
|
|
|
2021-09-11 18:33:55 +02:00
|
|
|
import sentry_sdk
|
2021-09-25 20:31:08 +02:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2021-10-15 20:10:50 +02:00
|
|
|
from django_jinja.builtins import DEFAULT_EXTENSIONS
|
2021-08-29 13:58:21 +02:00
|
|
|
from django_tenants.files.storage import TenantFileSystemStorage
|
2021-09-11 18:33:55 +02:00
|
|
|
from sentry_sdk.integrations.django import DjangoIntegration
|
2021-08-29 13:58:21 +02:00
|
|
|
|
2021-08-22 20:10:29 +02:00
|
|
|
from .secrets import *
|
|
|
|
|
|
|
|
# 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/3.2/howto/deployment/checklist/
|
|
|
|
|
2021-09-07 16:10:09 +02:00
|
|
|
DOMAIN_WITH_DOT = "." + DOMAIN
|
2021-08-22 20:10:29 +02:00
|
|
|
|
2021-09-07 16:10:09 +02:00
|
|
|
ALLOWED_HOSTS = [DOMAIN_WITH_DOT]
|
2021-08-22 20:10:29 +02:00
|
|
|
|
|
|
|
# Application definition
|
|
|
|
|
2021-08-29 00:20:02 +02:00
|
|
|
DATABASE_ROUTERS = (
|
|
|
|
'django_tenants.routers.TenantSyncRouter',
|
|
|
|
)
|
|
|
|
SHARED_APPS = (
|
|
|
|
'django_tenants', # mandatory
|
|
|
|
'campaigns', # you must list the app where your tenant model resides in
|
|
|
|
'users',
|
2021-08-22 20:10:29 +02:00
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
2021-08-29 00:20:02 +02:00
|
|
|
'tenant_users.permissions', # Defined in both shared apps and tenant apps
|
|
|
|
'tenant_users.tenants', # defined only in shared apps
|
2021-08-22 20:10:29 +02:00
|
|
|
'django.contrib.sessions',
|
|
|
|
'django.contrib.messages',
|
2021-08-29 00:20:02 +02:00
|
|
|
'django.contrib.admin',
|
2021-08-28 19:52:07 +02:00
|
|
|
'django.contrib.humanize',
|
2021-08-29 00:20:02 +02:00
|
|
|
'django.contrib.staticfiles',
|
2021-08-22 20:10:29 +02:00
|
|
|
'django_bootstrap5',
|
2021-10-15 20:10:50 +02:00
|
|
|
'django_jinja',
|
|
|
|
'django_jinja.contrib._humanize',
|
2021-08-28 19:52:07 +02:00
|
|
|
'sorl.thumbnail',
|
2021-09-05 18:52:26 +02:00
|
|
|
'debug_toolbar',
|
2021-09-07 20:03:23 +02:00
|
|
|
'axes',
|
2022-04-11 22:43:06 +02:00
|
|
|
'django_extensions',
|
|
|
|
'django.contrib.postgres'
|
2021-08-29 00:20:02 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
TENANT_APPS = (
|
|
|
|
# The following Django contrib apps must be in TENANT_APPS
|
|
|
|
'django.contrib.auth', # Defined in both shared apps and tenant apps
|
|
|
|
'django.contrib.contenttypes', # Defined in both shared apps and tenant apps
|
|
|
|
'tenant_users.permissions', # Defined in both shared apps and tenant apps
|
|
|
|
'django.contrib.admin',
|
|
|
|
|
2021-09-06 20:34:43 +02:00
|
|
|
'locations',
|
2021-08-29 22:09:22 +02:00
|
|
|
'characters',
|
|
|
|
'loot',
|
|
|
|
'days',
|
2021-10-03 16:44:54 +02:00
|
|
|
'factions',
|
2021-10-03 16:09:59 +02:00
|
|
|
'notes',
|
2022-04-11 22:43:06 +02:00
|
|
|
'search',
|
2022-11-19 22:09:15 +01:00
|
|
|
'graph',
|
2021-08-29 22:09:22 +02:00
|
|
|
'common',
|
2021-08-29 00:20:02 +02:00
|
|
|
'simple_history',
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
INSTALLED_APPS = list(SHARED_APPS) + [app for app in TENANT_APPS if app not in SHARED_APPS]
|
|
|
|
|
|
|
|
TENANT_MODEL = "campaigns.Campaign"
|
|
|
|
|
|
|
|
TENANT_DOMAIN_MODEL = "campaigns.Domain"
|
|
|
|
|
2021-09-07 16:10:09 +02:00
|
|
|
TENANT_USERS_DOMAIN = DOMAIN
|
2021-08-29 00:20:02 +02:00
|
|
|
|
|
|
|
AUTH_USER_MODEL = 'users.TenantUser'
|
|
|
|
|
|
|
|
AUTHENTICATION_BACKENDS = (
|
2021-09-07 18:53:53 +02:00
|
|
|
'axes.backends.AxesBackend',
|
2021-08-29 00:20:02 +02:00
|
|
|
'tenant_users.permissions.backend.UserBackend',
|
|
|
|
)
|
|
|
|
|
2021-09-07 16:10:09 +02:00
|
|
|
SESSION_COOKIE_DOMAIN = DOMAIN_WITH_DOT
|
2021-08-22 20:10:29 +02:00
|
|
|
|
2021-08-29 13:58:21 +02:00
|
|
|
DEFAULT_FILE_STORAGE = "django_tenants.files.storage.TenantFileSystemStorage"
|
|
|
|
|
2021-08-22 20:10:29 +02:00
|
|
|
MIDDLEWARE = [
|
2021-08-29 00:20:02 +02:00
|
|
|
'django_tenants.middleware.main.TenantMainMiddleware',
|
2021-08-28 19:52:07 +02:00
|
|
|
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
2021-08-22 20:10:29 +02:00
|
|
|
'django.middleware.security.SecurityMiddleware',
|
|
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
2021-09-25 20:31:08 +02:00
|
|
|
'django.middleware.locale.LocaleMiddleware',
|
2021-08-22 20:10:29 +02:00
|
|
|
'django.middleware.common.CommonMiddleware',
|
|
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
2021-09-06 21:10:55 +02:00
|
|
|
'common.middlewares.AuthMiddleware',
|
2021-09-05 18:52:26 +02:00
|
|
|
'simple_history.middleware.HistoryRequestMiddleware',
|
2021-09-06 21:10:55 +02:00
|
|
|
'csp.middleware.CSPMiddleware',
|
2021-09-05 18:52:26 +02:00
|
|
|
'axes.middleware.AxesMiddleware'
|
2021-08-22 20:10:29 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
ROOT_URLCONF = 'rpg_notes.urls'
|
2021-08-29 13:58:21 +02:00
|
|
|
PUBLIC_SCHEMA_URLCONF = 'rpg_notes.urls_public'
|
2021-08-22 20:10:29 +02:00
|
|
|
|
2021-08-29 16:45:40 +02:00
|
|
|
TEMPLATES_DIR = BASE_DIR / 'templates'
|
2021-08-22 20:10:29 +02:00
|
|
|
TEMPLATES = [
|
2021-10-15 20:10:50 +02:00
|
|
|
{
|
|
|
|
"BACKEND": "django_jinja.backend.Jinja2",
|
|
|
|
"DIRS": [TEMPLATES_DIR],
|
|
|
|
"APP_DIRS": True,
|
|
|
|
"OPTIONS": {
|
|
|
|
# "extensions": DEFAULT_EXTENSIONS + [
|
|
|
|
# 'jdj_tags.extensions.DjangoCompat',
|
|
|
|
# ]
|
|
|
|
'context_processors': [
|
|
|
|
'django.template.context_processors.request',
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
2021-10-15 21:47:49 +02:00
|
|
|
'django.template.context_processors.debug',
|
2021-10-15 20:10:50 +02:00
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
],
|
|
|
|
"bytecode_cache": {
|
|
|
|
"name": "default",
|
|
|
|
"backend": "django_jinja.cache.BytecodeCache",
|
|
|
|
"enabled": True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2021-08-22 20:10:29 +02:00
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
2021-08-29 13:58:21 +02:00
|
|
|
'DIRS': [TEMPLATES_DIR],
|
2021-08-22 20:10:29 +02:00
|
|
|
'APP_DIRS': True,
|
|
|
|
'OPTIONS': {
|
|
|
|
'context_processors': [
|
2021-08-29 00:20:02 +02:00
|
|
|
'django.template.context_processors.request',
|
2021-08-22 20:10:29 +02:00
|
|
|
'django.template.context_processors.debug',
|
|
|
|
'django.template.context_processors.request',
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
WSGI_APPLICATION = 'rpg_notes.wsgi.application'
|
|
|
|
|
|
|
|
# Password validation
|
|
|
|
# https://docs.djangoproject.com/en/3.2/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',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2021-08-29 16:45:40 +02:00
|
|
|
PASSWORD_HASHERS = [
|
|
|
|
'django.contrib.auth.hashers.Argon2PasswordHasher',
|
|
|
|
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
|
|
|
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
|
|
|
|
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
|
|
|
|
]
|
|
|
|
|
|
|
|
LOGIN_URL = "login"
|
|
|
|
LOGIN_REDIRECT_URL = "/"
|
|
|
|
LOGOUT_REDIRECT_URL = "/"
|
|
|
|
|
2021-08-22 20:10:29 +02:00
|
|
|
# Internationalization
|
|
|
|
# https://docs.djangoproject.com/en/3.2/topics/i18n/
|
|
|
|
|
2021-09-25 20:31:08 +02:00
|
|
|
LANGUAGE_CODE = 'en'
|
|
|
|
|
|
|
|
LANGUAGES = [
|
|
|
|
('de', _('German')),
|
|
|
|
('en', _('English')),
|
|
|
|
]
|
|
|
|
|
|
|
|
LOCALE_PATHS = [
|
|
|
|
BASE_DIR / "locale"
|
|
|
|
]
|
2021-08-22 20:10:29 +02:00
|
|
|
|
2021-08-28 19:52:07 +02:00
|
|
|
TIME_ZONE = 'Europe/Vienna'
|
2021-08-22 20:10:29 +02:00
|
|
|
|
|
|
|
USE_I18N = True
|
|
|
|
|
|
|
|
USE_L10N = True
|
|
|
|
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
|
|
# https://docs.djangoproject.com/en/3.2/howto/static-files/
|
|
|
|
|
|
|
|
STATIC_URL = '/static/'
|
|
|
|
|
|
|
|
MEDIA_URL = '/media/'
|
|
|
|
|
|
|
|
# Default primary key field type
|
|
|
|
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
|
|
|
|
2021-09-07 20:03:23 +02:00
|
|
|
SHELL_PLUS = "bpython"
|
|
|
|
|
2021-08-22 20:10:29 +02:00
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
|
|
|
|
|
|
THUMBNAIL_ALTERNATIVE_RESOLUTIONS = [2, 3]
|
2021-09-05 22:04:14 +02:00
|
|
|
|
2021-09-06 20:34:43 +02:00
|
|
|
ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window
|
2021-09-05 22:04:14 +02:00
|
|
|
|
|
|
|
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
2021-09-24 19:20:09 +02:00
|
|
|
EMAIL_SUBJECT_PREFIX = "[RPGnotes]"
|
2021-09-06 21:10:55 +02:00
|
|
|
|
2021-09-11 19:24:48 +02:00
|
|
|
CSP_DEFAULT_SRC = ["'self'", 'data:', "https://bugs.lw1.at"]
|
2021-09-11 19:23:59 +02:00
|
|
|
CSP_SCRIPT_SRC = ["'self'", "https://bugs.lw1.at"]
|
2022-11-25 20:54:12 +01:00
|
|
|
CSP_WORKER_SRC = ["'self'", "blob:"]
|
2021-09-06 21:10:55 +02:00
|
|
|
CSP_STYLE_SRC = ["'self'", "'unsafe-inline'"]
|
2022-07-30 16:24:28 +02:00
|
|
|
CSP_REPORT_ONLY = DEBUG
|
|
|
|
if DEBUG:
|
|
|
|
CSP_EXCLUDE_URL_PREFIXES = ("/")
|
2021-09-11 18:39:56 +02:00
|
|
|
if SENTRY_CSP_REPORT_URI:
|
|
|
|
CSP_REPORT_URL = SENTRY_CSP_REPORT_URI
|
2021-09-06 21:10:55 +02:00
|
|
|
CSP_FRAME_ANCESTORS = ["'none'"]
|
2021-09-11 19:23:59 +02:00
|
|
|
CSP_INCLUDE_NONCE_IN = ['script-src']
|
2021-09-07 14:16:14 +02:00
|
|
|
|
|
|
|
THUMBNAIL_KVSTORE = "sorl.thumbnail.kvstores.redis_kvstore.KVStore"
|
|
|
|
redis_url = "redis://127.0.0.1:6379/9" if DEBUG else "unix:///var/run/redis-rpgnotes/redis-server.sock?db=2"
|
2021-09-14 20:10:38 +02:00
|
|
|
THUMBNAIL_REDIS_URL = redis_url.replace("?db=2", "?db=1")
|
2021-09-07 14:16:14 +02:00
|
|
|
CACHES = {
|
|
|
|
"default": {
|
|
|
|
"BACKEND": "django_redis.cache.RedisCache",
|
|
|
|
"LOCATION": redis_url,
|
|
|
|
"OPTIONS": {
|
|
|
|
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
|
|
|
}
|
2021-10-15 20:10:50 +02:00
|
|
|
},
|
2021-09-07 14:16:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"
|
|
|
|
SESSION_CACHE_ALIAS = "default"
|
2022-07-04 19:55:13 +02:00
|
|
|
SESSION_COOKIE_AGE = 60 * 60 * 24 * 30 * 2
|
2021-09-07 14:16:14 +02:00
|
|
|
|
2021-09-14 20:10:38 +02:00
|
|
|
THUMBNAIL_DEBUG = DEBUG
|
2021-10-08 14:30:10 +02:00
|
|
|
THUMBNAIL_PRESERVE_FORMAT = True
|
2021-09-14 20:10:38 +02:00
|
|
|
|
2021-09-07 14:16:14 +02:00
|
|
|
if not DEBUG:
|
|
|
|
SECURE_SSL_REDIRECT = True
|
|
|
|
SECURE_HSTS_SECONDS = 60 * 60 * 24 * 365
|
|
|
|
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
|
2021-09-07 16:40:46 +02:00
|
|
|
SECURE_HSTS_PRELOAD = True
|
2021-09-07 14:16:14 +02:00
|
|
|
SESSION_COOKIE_SECURE = True
|
|
|
|
CSRF_COOKIE_SECURE = True
|
2021-10-07 11:43:45 +02:00
|
|
|
|
|
|
|
AXES_META_PRECEDENCE_ORDER = ['HTTP_X_REAL_IP']
|
|
|
|
AXES_COOLOFF_TIME = timedelta(hours=1)
|
|
|
|
AXES_FAILURE_LIMIT = 6
|
|
|
|
|
2021-09-07 16:40:46 +02:00
|
|
|
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
|
|
|
|
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
2021-09-07 14:16:14 +02:00
|
|
|
LOGGING = {
|
|
|
|
'version': 1,
|
|
|
|
'disable_existing_loggers': False,
|
|
|
|
'handlers': {
|
|
|
|
'file': {
|
|
|
|
'level': 'DEBUG',
|
|
|
|
'class': 'logging.FileHandler',
|
|
|
|
'filename': '/srv/server/rpgnotes/app.log',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
'django': {
|
|
|
|
'handlers': ['file'],
|
|
|
|
'level': 'INFO',
|
|
|
|
'propagate': True,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-09-11 18:33:55 +02:00
|
|
|
if SENTRY_DSN:
|
2021-09-11 18:46:17 +02:00
|
|
|
sp = run(["git", "rev-parse", "--verify", "HEAD"], capture_output=True)
|
|
|
|
commit = sp.stdout.decode().strip()
|
|
|
|
|
2021-09-11 18:33:55 +02:00
|
|
|
sentry_sdk.init(
|
|
|
|
dsn=SENTRY_DSN,
|
2021-09-11 18:39:56 +02:00
|
|
|
integrations=[DjangoIntegration()],
|
|
|
|
auto_session_tracking=False,
|
2021-09-11 18:46:17 +02:00
|
|
|
traces_sample_rate=0.01,
|
|
|
|
release=commit
|
2021-09-11 18:33:55 +02:00
|
|
|
)
|