2022-11-23 11:41:43 +03:00
|
|
|
"""
|
|
|
|
Base settings to build other settings files upon.
|
|
|
|
"""
|
2024-03-30 01:02:07 +03:00
|
|
|
|
2022-11-23 11:41:43 +03:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import environ
|
2022-12-13 13:21:50 +03:00
|
|
|
import structlog
|
2023-11-07 03:43:05 +03:00
|
|
|
from celery.schedules import crontab
|
2023-10-25 10:42:08 +03:00
|
|
|
from sentry_sdk.integrations.celery import CeleryIntegration
|
2022-11-23 11:41:43 +03:00
|
|
|
|
|
|
|
ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent.parent
|
|
|
|
# akarpov/
|
|
|
|
APPS_DIR = ROOT_DIR / "akarpov"
|
|
|
|
env = environ.Env()
|
|
|
|
|
|
|
|
READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=True)
|
|
|
|
if READ_DOT_ENV_FILE:
|
|
|
|
# OS environment variables take precedence over variables from .env
|
|
|
|
env.read_env(str(ROOT_DIR / ".env"))
|
|
|
|
|
|
|
|
# GENERAL
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
|
|
|
|
DEBUG = env.bool("DJANGO_DEBUG", False)
|
|
|
|
# Local time zone. Choices are
|
|
|
|
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
|
|
|
# though not all of them may be available with every OS.
|
|
|
|
# In Windows, this must be set to your system time zone.
|
|
|
|
TIME_ZONE = "Europe/Moscow"
|
|
|
|
DATETIME_FORMAT = "%H:%M:%S %d.%m.%Y"
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#language-code
|
|
|
|
LANGUAGE_CODE = "en-us"
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#site-id
|
|
|
|
SITE_ID = 1
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
|
|
|
|
USE_I18N = True
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
|
|
|
|
USE_TZ = True
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#locale-paths
|
|
|
|
LOCALE_PATHS = [str(ROOT_DIR / "locale")]
|
|
|
|
|
2023-01-01 23:18:24 +03:00
|
|
|
LANGUAGES = [
|
|
|
|
("en-us", "English"),
|
|
|
|
("ru", "Russian"),
|
|
|
|
]
|
|
|
|
|
2022-11-23 11:41:43 +03:00
|
|
|
# DATABASES
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
2022-12-20 19:21:39 +03:00
|
|
|
DATABASES = {"default": env.db("DATABASE_URL")}
|
2022-11-23 11:41:43 +03:00
|
|
|
DATABASES["default"]["ATOMIC_REQUESTS"] = True
|
|
|
|
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
|
2022-12-20 19:21:39 +03:00
|
|
|
# CACHES
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-12-07 02:52:24 +03:00
|
|
|
CACHES = {
|
|
|
|
"default": {
|
|
|
|
"BACKEND": "django_redis.cache.RedisCache",
|
|
|
|
"LOCATION": env("REDIS_CACHE_URL", default="redis://localhost:6379/1"),
|
|
|
|
"OPTIONS": {
|
|
|
|
"CLIENT_CLASS": "django_redis.client.DefaultClient",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2023-07-28 20:03:19 +03:00
|
|
|
CACHE_MIDDLEWARE_KEY_PREFIX = "cache_middleware"
|
|
|
|
CACHE_MIDDLEWARE_SECONDS = 0
|
|
|
|
CACHE_TTL = 60 * 10
|
2022-12-20 19:21:39 +03:00
|
|
|
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
|
|
|
|
SESSION_CACHE_ALIAS = "default"
|
|
|
|
CACHEOPS = {
|
|
|
|
"auth.user": {"ops": "get", "timeout": 60 * 15},
|
2023-07-28 20:03:19 +03:00
|
|
|
"auth.*": {"ops": ("fetch", "get"), "timeout": 60 * 2},
|
2023-11-19 02:38:51 +03:00
|
|
|
"blog.post": {"ops": ("fetch", "get"), "timeout": 20 * 15},
|
|
|
|
"themes.theme": {"ops": ("fetch", "get"), "timeout": 60 * 60},
|
2023-12-16 21:11:08 +03:00
|
|
|
"gallery.*": {"ops": ("fetch", "get", "list"), "timeout": 60 * 15},
|
2023-12-17 16:22:40 +03:00
|
|
|
"files.*": {"ops": ("fetch", "get", "list"), "timeout": 60},
|
2023-07-28 20:03:19 +03:00
|
|
|
"auth.permission": {"ops": "all", "timeout": 60 * 15},
|
2023-12-16 21:11:08 +03:00
|
|
|
"music.*": {"ops": ("fetch", "get", "list"), "timeout": 60 * 15},
|
2023-12-29 00:56:44 +03:00
|
|
|
"otp_totp.totpdevice": {"ops": "all", "timeout": 15 * 60},
|
2024-03-30 01:02:07 +03:00
|
|
|
"users.userapitoken": {"ops": "all", "timeout": 20 * 60},
|
2024-04-07 23:14:33 +03:00
|
|
|
"users.user": {"ops": "all", "timeout": 5 * 60},
|
2022-12-20 19:21:39 +03:00
|
|
|
}
|
2023-01-03 10:58:52 +03:00
|
|
|
CACHEOPS_REDIS = env.str("REDIS_URL")
|
2022-12-20 19:21:39 +03:00
|
|
|
|
2022-11-23 11:41:43 +03:00
|
|
|
# URLS
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
|
|
|
|
ROOT_URLCONF = "config.urls"
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
|
|
|
|
WSGI_APPLICATION = "config.wsgi.application"
|
2023-04-05 08:50:00 +03:00
|
|
|
ASGI_APPLICATION = "config.asgi.application"
|
2022-11-23 11:41:43 +03:00
|
|
|
|
2023-07-10 03:13:42 +03:00
|
|
|
|
|
|
|
# CHANNELS
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
CHANNEL_LAYERS = {
|
|
|
|
"default": {
|
|
|
|
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
|
|
|
"CONFIG": {
|
2023-10-25 10:27:55 +03:00
|
|
|
"hosts": [env("REDIS_URL")],
|
2023-07-10 03:13:42 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-11-23 11:41:43 +03:00
|
|
|
# APPS
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
DJANGO_APPS = [
|
2023-03-28 00:26:49 +03:00
|
|
|
"daphne",
|
2022-11-23 11:41:43 +03:00
|
|
|
"django.contrib.auth",
|
|
|
|
"django.contrib.contenttypes",
|
|
|
|
"django.contrib.sessions",
|
|
|
|
"django.contrib.sites",
|
2023-04-20 13:09:50 +03:00
|
|
|
"django.contrib.sitemaps",
|
2022-11-23 11:41:43 +03:00
|
|
|
"django.contrib.messages",
|
|
|
|
"django.contrib.staticfiles",
|
|
|
|
"django.contrib.humanize", # Handy template tags
|
2022-12-20 19:21:39 +03:00
|
|
|
# required for jazzmin to work
|
|
|
|
"jazzmin",
|
2022-11-23 11:41:43 +03:00
|
|
|
"django.contrib.admin",
|
|
|
|
"django.forms",
|
|
|
|
]
|
2022-11-25 12:16:10 +03:00
|
|
|
|
2022-11-23 11:41:43 +03:00
|
|
|
THIRD_PARTY_APPS = [
|
2023-11-07 16:13:59 +03:00
|
|
|
"django.contrib.postgres",
|
2022-11-23 11:41:43 +03:00
|
|
|
"crispy_forms",
|
|
|
|
"crispy_bootstrap5",
|
|
|
|
"allauth",
|
|
|
|
"allauth.account",
|
|
|
|
"allauth.socialaccount",
|
|
|
|
"django_celery_beat",
|
|
|
|
"rest_framework",
|
|
|
|
"rest_framework.authtoken",
|
|
|
|
"corsheaders",
|
|
|
|
"drf_spectacular",
|
2024-03-30 01:02:07 +03:00
|
|
|
"django_ckeditor_5",
|
2022-11-23 11:41:43 +03:00
|
|
|
"colorfield",
|
2022-12-13 13:21:50 +03:00
|
|
|
"polymorphic",
|
2022-12-20 19:21:39 +03:00
|
|
|
"cacheops",
|
|
|
|
"extra_settings",
|
2023-03-27 16:15:03 +03:00
|
|
|
"akarpov.contrib.chunked_upload",
|
2023-02-10 13:30:20 +03:00
|
|
|
"active_link",
|
2023-04-20 13:09:50 +03:00
|
|
|
"robots",
|
2023-04-24 14:48:15 +03:00
|
|
|
"django_filters",
|
|
|
|
"django_tables2",
|
2023-05-09 22:48:35 +03:00
|
|
|
"location_field",
|
2023-11-20 22:22:19 +03:00
|
|
|
"django_elasticsearch_dsl",
|
2023-12-29 00:24:01 +03:00
|
|
|
# 2fa
|
|
|
|
"django_otp",
|
|
|
|
"django_otp.plugins.otp_static",
|
|
|
|
"django_otp.plugins.otp_totp",
|
|
|
|
"django_otp.plugins.otp_hotp",
|
|
|
|
"django_otp.plugins.otp_email",
|
2022-11-23 11:41:43 +03:00
|
|
|
]
|
|
|
|
|
2022-11-25 12:16:10 +03:00
|
|
|
HEALTH_CHECKS = [
|
|
|
|
"health_check", # required
|
|
|
|
"health_check.db", # stock Django health checkers
|
|
|
|
"health_check.cache",
|
|
|
|
"health_check.storage",
|
|
|
|
"health_check.contrib.celery",
|
|
|
|
"health_check.contrib.celery_ping",
|
|
|
|
"health_check.contrib.migrations",
|
|
|
|
"health_check.contrib.psutil", # disk and memory utilization
|
|
|
|
"health_check.contrib.redis",
|
|
|
|
]
|
|
|
|
|
2023-04-29 11:46:22 +03:00
|
|
|
ALLAUTH_PROVIDERS = [
|
2022-11-25 12:16:10 +03:00
|
|
|
"allauth.socialaccount.providers.github",
|
2023-12-07 12:07:33 +03:00
|
|
|
"allauth.socialaccount.providers.google",
|
2023-12-07 12:49:58 +03:00
|
|
|
# "allauth.socialaccount.providers.telegram", TODO
|
|
|
|
# "allauth.socialaccount.providers.yandex", TODO
|
2022-11-25 12:16:10 +03:00
|
|
|
]
|
|
|
|
|
2023-01-15 11:19:14 +03:00
|
|
|
LOCAL_APPS = [
|
|
|
|
"akarpov.users",
|
2023-03-24 12:20:58 +03:00
|
|
|
"akarpov.about",
|
2023-01-15 11:19:14 +03:00
|
|
|
"akarpov.blog",
|
|
|
|
"akarpov.files",
|
2023-03-28 00:26:49 +03:00
|
|
|
"akarpov.music",
|
2023-04-29 11:46:22 +03:00
|
|
|
"akarpov.gallery",
|
2023-09-24 20:28:21 +03:00
|
|
|
"akarpov.tools.qr",
|
2023-01-15 11:19:14 +03:00
|
|
|
"akarpov.pipeliner",
|
2023-10-25 10:27:55 +03:00
|
|
|
"akarpov.users.themes",
|
2023-09-24 20:28:21 +03:00
|
|
|
"akarpov.notifications",
|
2023-02-24 19:37:34 +03:00
|
|
|
"akarpov.test_platform",
|
2023-02-16 14:00:16 +03:00
|
|
|
"akarpov.tools.shortener",
|
2023-06-21 17:02:53 +03:00
|
|
|
"akarpov.tools.promocodes",
|
2023-01-15 11:19:14 +03:00
|
|
|
]
|
2022-11-23 11:41:43 +03:00
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
2022-11-25 12:16:10 +03:00
|
|
|
INSTALLED_APPS = (
|
2023-04-29 11:46:22 +03:00
|
|
|
DJANGO_APPS + LOCAL_APPS + THIRD_PARTY_APPS + HEALTH_CHECKS + ALLAUTH_PROVIDERS
|
2022-11-25 12:16:10 +03:00
|
|
|
)
|
2022-11-23 11:41:43 +03:00
|
|
|
|
|
|
|
# MIGRATIONS
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#migration-modules
|
|
|
|
MIGRATION_MODULES = {"sites": "akarpov.contrib.sites.migrations"}
|
|
|
|
|
|
|
|
# AUTHENTICATION
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#authentication-backends
|
|
|
|
AUTHENTICATION_BACKENDS = [
|
|
|
|
"django.contrib.auth.backends.ModelBackend",
|
|
|
|
"allauth.account.auth_backends.AuthenticationBackend",
|
|
|
|
]
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-user-model
|
|
|
|
AUTH_USER_MODEL = "users.User"
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url
|
|
|
|
LOGIN_REDIRECT_URL = "users:redirect"
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#login-url
|
|
|
|
LOGIN_URL = "account_login"
|
|
|
|
|
|
|
|
# PASSWORDS
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#password-hashers
|
|
|
|
PASSWORD_HASHERS = [
|
|
|
|
# https://docs.djangoproject.com/en/dev/topics/auth/passwords/#using-argon2-with-django
|
|
|
|
"django.contrib.auth.hashers.Argon2PasswordHasher",
|
|
|
|
"django.contrib.auth.hashers.PBKDF2PasswordHasher",
|
|
|
|
"django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
|
|
|
|
"django.contrib.auth.hashers.BCryptSHA256PasswordHasher",
|
|
|
|
]
|
|
|
|
# https://docs.djangoproject.com/en/dev/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"},
|
|
|
|
]
|
|
|
|
|
|
|
|
# MIDDLEWARE
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#middleware
|
|
|
|
MIDDLEWARE = [
|
|
|
|
"django.middleware.security.SecurityMiddleware",
|
2023-01-03 10:58:52 +03:00
|
|
|
"django.middleware.cache.UpdateCacheMiddleware",
|
2022-11-23 11:41:43 +03:00
|
|
|
"corsheaders.middleware.CorsMiddleware",
|
|
|
|
"whitenoise.middleware.WhiteNoiseMiddleware",
|
2022-12-13 13:21:50 +03:00
|
|
|
"django_structlog.middlewares.RequestMiddleware",
|
2022-11-23 11:41:43 +03:00
|
|
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
|
|
"django.middleware.locale.LocaleMiddleware",
|
|
|
|
"django.middleware.common.CommonMiddleware",
|
|
|
|
"django.middleware.csrf.CsrfViewMiddleware",
|
|
|
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
2023-12-29 00:24:01 +03:00
|
|
|
"django_otp.middleware.OTPMiddleware",
|
|
|
|
"akarpov.users.middleware.Enforce2FAMiddleware",
|
2022-11-23 11:41:43 +03:00
|
|
|
"django.contrib.messages.middleware.MessageMiddleware",
|
|
|
|
"django.middleware.common.BrokenLinkEmailsMiddleware",
|
|
|
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
2023-01-03 10:58:52 +03:00
|
|
|
"django.middleware.cache.FetchFromCacheMiddleware",
|
2022-11-23 11:41:43 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
# STATIC
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#static-root
|
|
|
|
STATIC_ROOT = str(ROOT_DIR / "staticfiles")
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#static-url
|
|
|
|
STATIC_URL = "/static/"
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
|
|
|
|
STATICFILES_DIRS = [str(APPS_DIR / "static")]
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
|
|
|
|
STATICFILES_FINDERS = [
|
|
|
|
"django.contrib.staticfiles.finders.FileSystemFinder",
|
|
|
|
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
|
|
|
|
]
|
|
|
|
|
|
|
|
# MEDIA
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#media-root
|
|
|
|
MEDIA_ROOT = str(APPS_DIR / "media")
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#media-url
|
|
|
|
MEDIA_URL = "/media/"
|
|
|
|
|
|
|
|
# TEMPLATES
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
|
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
|
|
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#dirs
|
|
|
|
"DIRS": [str(APPS_DIR / "templates")],
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#app-dirs
|
|
|
|
"APP_DIRS": True,
|
|
|
|
"OPTIONS": {
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
|
|
|
|
"context_processors": [
|
|
|
|
"django.template.context_processors.debug",
|
|
|
|
"django.template.context_processors.request",
|
|
|
|
"django.contrib.auth.context_processors.auth",
|
|
|
|
"django.template.context_processors.i18n",
|
|
|
|
"django.template.context_processors.media",
|
|
|
|
"django.template.context_processors.static",
|
|
|
|
"django.template.context_processors.tz",
|
|
|
|
"django.contrib.messages.context_processors.messages",
|
|
|
|
"akarpov.users.context_processors.allauth_settings",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#form-renderer
|
|
|
|
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"
|
|
|
|
|
|
|
|
# http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
|
|
|
|
CRISPY_TEMPLATE_PACK = "bootstrap5"
|
|
|
|
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
|
|
|
|
|
|
|
|
# FIXTURES
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#fixture-dirs
|
|
|
|
FIXTURE_DIRS = (str(APPS_DIR / "fixtures"),)
|
|
|
|
|
|
|
|
# SECURITY
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-httponly
|
|
|
|
SESSION_COOKIE_HTTPONLY = True
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-httponly
|
|
|
|
CSRF_COOKIE_HTTPONLY = True
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-browser-xss-filter
|
|
|
|
SECURE_BROWSER_XSS_FILTER = True
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#x-frame-options
|
|
|
|
X_FRAME_OPTIONS = "DENY"
|
|
|
|
|
|
|
|
# EMAIL
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
|
|
|
|
EMAIL_BACKEND = env(
|
|
|
|
"DJANGO_EMAIL_BACKEND",
|
|
|
|
default="django.core.mail.backends.smtp.EmailBackend",
|
|
|
|
)
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#email-timeout
|
|
|
|
EMAIL_TIMEOUT = 5
|
2023-10-15 23:02:53 +03:00
|
|
|
EMAIL_HOST_PASSWORD = env(
|
2023-12-07 02:52:24 +03:00
|
|
|
"EMAIL_HOST_PASSWORD",
|
2023-10-15 23:02:53 +03:00
|
|
|
default="",
|
|
|
|
)
|
|
|
|
EMAIL_HOST_USER = env(
|
2023-12-07 02:52:24 +03:00
|
|
|
"EMAIL_HOST_USER",
|
2023-10-15 23:02:53 +03:00
|
|
|
default="",
|
|
|
|
)
|
|
|
|
EMAIL_USE_SSL = env(
|
|
|
|
"EMAIL_USE_SSL",
|
|
|
|
default=False,
|
|
|
|
)
|
2022-11-23 11:41:43 +03:00
|
|
|
|
2023-12-07 02:52:24 +03:00
|
|
|
EMAIL_HOST = env("EMAIL_HOST", default="mailhog")
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#email-port
|
|
|
|
EMAIL_PORT = env("EMAIL_PORT", default="1025")
|
|
|
|
EMAIL_FROM = env("EMAIL_FROM", default="noreply@akarpov.ru")
|
2023-12-07 03:13:40 +03:00
|
|
|
DEFAULT_FROM_EMAIL = env("EMAIL_FROM", default="noreply@akarpov.ru")
|
|
|
|
SERVER_EMAIL = env("EMAIL_FROM", default="noreply@akarpov.ru")
|
2023-12-07 02:52:24 +03:00
|
|
|
|
2022-11-23 11:41:43 +03:00
|
|
|
# ADMIN
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Django Admin URL.
|
|
|
|
ADMIN_URL = "admin/"
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#admins
|
|
|
|
ADMINS = [("""sanspie""", "alexandr.d.karpov@gmail.com")]
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#managers
|
|
|
|
MANAGERS = ADMINS
|
|
|
|
|
|
|
|
# LOGGING
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# https://docs.djangoproject.com/en/dev/ref/settings/#logging
|
|
|
|
# See https://docs.djangoproject.com/en/dev/topics/logging for
|
|
|
|
# more details on how to customize your logging configuration.
|
2022-12-13 13:21:50 +03:00
|
|
|
|
2022-11-23 11:41:43 +03:00
|
|
|
LOGGING = {
|
|
|
|
"version": 1,
|
|
|
|
"disable_existing_loggers": False,
|
|
|
|
"formatters": {
|
2022-12-13 13:21:50 +03:00
|
|
|
"json_formatter": {
|
|
|
|
"()": structlog.stdlib.ProcessorFormatter,
|
|
|
|
"processor": structlog.processors.JSONRenderer(),
|
|
|
|
},
|
|
|
|
"plain_console": {
|
|
|
|
"()": structlog.stdlib.ProcessorFormatter,
|
|
|
|
"processor": structlog.dev.ConsoleRenderer(),
|
|
|
|
},
|
|
|
|
"key_value": {
|
|
|
|
"()": structlog.stdlib.ProcessorFormatter,
|
|
|
|
"processor": structlog.processors.KeyValueRenderer(
|
|
|
|
key_order=["timestamp", "level", "event", "logger"]
|
|
|
|
),
|
|
|
|
},
|
2022-11-23 11:41:43 +03:00
|
|
|
},
|
|
|
|
"handlers": {
|
|
|
|
"console": {
|
|
|
|
"class": "logging.StreamHandler",
|
2022-12-13 13:21:50 +03:00
|
|
|
"formatter": "plain_console",
|
|
|
|
},
|
|
|
|
"json_file": {
|
|
|
|
"class": "logging.handlers.WatchedFileHandler",
|
|
|
|
"filename": "logs/json.log",
|
|
|
|
"formatter": "json_formatter",
|
|
|
|
},
|
|
|
|
"flat_line_file": {
|
|
|
|
"class": "logging.handlers.WatchedFileHandler",
|
|
|
|
"filename": "logs/flat_line.log",
|
|
|
|
"formatter": "key_value",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"loggers": {
|
|
|
|
"django_structlog": {
|
|
|
|
"handlers": ["console", "flat_line_file", "json_file"],
|
|
|
|
"level": "INFO",
|
|
|
|
},
|
|
|
|
# Make sure to replace the following logger's name for yours
|
|
|
|
"django_structlog_demo_project": {
|
|
|
|
"handlers": ["console", "flat_line_file", "json_file"],
|
|
|
|
"level": "INFO",
|
|
|
|
},
|
2022-11-23 11:41:43 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:21:50 +03:00
|
|
|
structlog.configure(
|
|
|
|
processors=[
|
|
|
|
structlog.contextvars.merge_contextvars,
|
|
|
|
structlog.stdlib.filter_by_level,
|
|
|
|
structlog.processors.TimeStamper(fmt="iso"),
|
|
|
|
structlog.stdlib.add_logger_name,
|
|
|
|
structlog.stdlib.add_log_level,
|
|
|
|
structlog.stdlib.PositionalArgumentsFormatter(),
|
|
|
|
structlog.processors.StackInfoRenderer(),
|
|
|
|
structlog.processors.format_exc_info,
|
|
|
|
structlog.processors.UnicodeDecoder(),
|
|
|
|
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
|
|
|
|
],
|
2023-11-07 03:43:05 +03:00
|
|
|
context_class=dict,
|
2022-12-13 13:21:50 +03:00
|
|
|
logger_factory=structlog.stdlib.LoggerFactory(),
|
|
|
|
cache_logger_on_first_use=True,
|
|
|
|
)
|
|
|
|
|
2022-11-23 11:41:43 +03:00
|
|
|
# Celery
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
if USE_TZ:
|
|
|
|
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-timezone
|
|
|
|
CELERY_TIMEZONE = TIME_ZONE
|
|
|
|
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-broker_url
|
|
|
|
CELERY_BROKER_URL = env("CELERY_BROKER_URL")
|
|
|
|
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-result_backend
|
|
|
|
CELERY_RESULT_BACKEND = CELERY_BROKER_URL
|
|
|
|
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-extended
|
|
|
|
CELERY_RESULT_EXTENDED = True
|
|
|
|
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-accept_content
|
|
|
|
CELERY_ACCEPT_CONTENT = ["json"]
|
|
|
|
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-task_serializer
|
|
|
|
CELERY_TASK_SERIALIZER = "json"
|
|
|
|
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-result_serializer
|
|
|
|
CELERY_RESULT_SERIALIZER = "json"
|
|
|
|
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-time-limit
|
2023-08-11 22:38:38 +03:00
|
|
|
CELERY_TASK_TIME_LIMIT = 20 * 60
|
2022-11-23 11:41:43 +03:00
|
|
|
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-soft-time-limit
|
2023-08-11 22:38:38 +03:00
|
|
|
CELERY_TASK_SOFT_TIME_LIMIT = 10 * 60
|
2022-11-23 11:41:43 +03:00
|
|
|
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#beat-scheduler
|
|
|
|
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
|
2023-11-07 03:43:05 +03:00
|
|
|
CELERY_BEAT_SCHEDULE = {
|
|
|
|
"update-index-every-hour": {
|
2023-11-20 22:22:19 +03:00
|
|
|
"task": "akarpov.files.tasks.update_index_task",
|
2023-11-07 03:43:05 +03:00
|
|
|
"schedule": crontab(minute="0"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-11-25 12:16:10 +03:00
|
|
|
|
2022-11-23 11:41:43 +03:00
|
|
|
# django-allauth
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
ACCOUNT_ALLOW_REGISTRATION = env.bool("DJANGO_ACCOUNT_ALLOW_REGISTRATION", True)
|
|
|
|
# https://django-allauth.readthedocs.io/en/latest/configuration.html
|
|
|
|
ACCOUNT_AUTHENTICATION_METHOD = "username"
|
|
|
|
# https://django-allauth.readthedocs.io/en/latest/configuration.html
|
|
|
|
ACCOUNT_EMAIL_REQUIRED = True
|
2022-11-25 12:16:10 +03:00
|
|
|
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
|
|
|
|
ACCOUNT_LOGIN_ON_PASSWORD_RESET = True
|
|
|
|
SOCIALACCOUNT_EMAIL_VERIFICATION = False
|
2022-11-23 11:41:43 +03:00
|
|
|
# https://django-allauth.readthedocs.io/en/latest/configuration.html
|
|
|
|
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
|
|
|
|
# https://django-allauth.readthedocs.io/en/latest/configuration.html
|
|
|
|
ACCOUNT_ADAPTER = "akarpov.users.adapters.AccountAdapter"
|
|
|
|
# https://django-allauth.readthedocs.io/en/latest/forms.html
|
|
|
|
ACCOUNT_FORMS = {"signup": "akarpov.users.forms.UserSignupForm"}
|
|
|
|
# https://django-allauth.readthedocs.io/en/latest/configuration.html
|
|
|
|
SOCIALACCOUNT_ADAPTER = "akarpov.users.adapters.SocialAccountAdapter"
|
|
|
|
# https://django-allauth.readthedocs.io/en/latest/forms.html
|
|
|
|
SOCIALACCOUNT_FORMS = {"signup": "akarpov.users.forms.UserSocialSignupForm"}
|
2022-11-25 12:16:10 +03:00
|
|
|
SOCIALACCOUNT_PROVIDERS = {
|
|
|
|
"github": {
|
|
|
|
"SCOPE": [
|
|
|
|
"user",
|
|
|
|
"read:org",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"google": {
|
|
|
|
"SCOPE": [
|
|
|
|
"profile",
|
|
|
|
"email",
|
|
|
|
],
|
|
|
|
"AUTH_PARAMS": {
|
|
|
|
"access_type": "online",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2023-12-07 03:36:49 +03:00
|
|
|
ACCOUNT_DEFAULT_HTTP_PROTOCOL = env("HTTP_PROTOCOL", default="http")
|
2022-11-23 11:41:43 +03:00
|
|
|
|
|
|
|
# django-rest-framework
|
|
|
|
# -------------------------------------------------------------------------------
|
|
|
|
REST_FRAMEWORK = {
|
|
|
|
"DEFAULT_AUTHENTICATION_CLASSES": (
|
|
|
|
"rest_framework.authentication.SessionAuthentication",
|
|
|
|
"rest_framework.authentication.TokenAuthentication",
|
2024-03-30 01:02:07 +03:00
|
|
|
"akarpov.users.api.authentification.UserTokenAuthentication",
|
2022-11-23 11:41:43 +03:00
|
|
|
),
|
|
|
|
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
|
|
|
|
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
|
|
|
}
|
|
|
|
CORS_URLS_REGEX = r"^/api/.*$"
|
2024-01-02 20:38:21 +03:00
|
|
|
APPEND_SLASH = False
|
2022-11-23 11:41:43 +03:00
|
|
|
SPECTACULAR_SETTINGS = {
|
|
|
|
"TITLE": "akarpov API",
|
2023-01-11 01:06:08 +03:00
|
|
|
"SCHEMA_PATH_PREFIX": "/api/v[0-9]",
|
2022-11-23 11:41:43 +03:00
|
|
|
"DESCRIPTION": "Documentation of API endpoints of akarpov",
|
|
|
|
"VERSION": "1.0.0",
|
2023-01-11 01:06:08 +03:00
|
|
|
"SERVE_INCLUDE_SCHEMA": False,
|
2022-11-23 11:41:43 +03:00
|
|
|
"SERVERS": [
|
|
|
|
{"url": "http://127.0.0.1:8000", "description": "Local Development server"},
|
2023-10-25 10:42:08 +03:00
|
|
|
{"url": "https://new.akarpov.ru", "description": "Production server"},
|
2022-11-23 11:41:43 +03:00
|
|
|
],
|
2024-04-07 23:28:29 +03:00
|
|
|
"EXTENSIONS": {
|
|
|
|
"authentication": [
|
|
|
|
"akarpov.users.api.authentification.UserTokenAuthenticationExtension"
|
|
|
|
],
|
|
|
|
},
|
2022-11-23 11:41:43 +03:00
|
|
|
}
|
2023-06-21 17:02:53 +03:00
|
|
|
|
2022-11-23 11:41:43 +03:00
|
|
|
# CKEDITOR
|
|
|
|
# ------------------------------------------------------------------------------
|
2024-03-30 01:02:07 +03:00
|
|
|
CKEDITOR_5_UPLOAD_PATH = "uploads/"
|
|
|
|
CKEDITOR_5_CONFIGS = {
|
2022-11-23 11:41:43 +03:00
|
|
|
"default": {
|
2024-03-30 01:02:07 +03:00
|
|
|
"toolbar": [
|
|
|
|
"heading",
|
|
|
|
"|",
|
|
|
|
"bold",
|
|
|
|
"italic",
|
|
|
|
"link",
|
|
|
|
"bulletedList",
|
|
|
|
"numberedList",
|
|
|
|
"blockQuote",
|
|
|
|
"imageUpload",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"extends": {
|
|
|
|
"blockToolbar": [
|
|
|
|
"paragraph",
|
|
|
|
"heading1",
|
|
|
|
"heading2",
|
|
|
|
"heading3",
|
|
|
|
"|",
|
|
|
|
"bulletedList",
|
|
|
|
"numberedList",
|
|
|
|
"|",
|
|
|
|
"blockQuote",
|
2022-11-23 11:41:43 +03:00
|
|
|
],
|
2024-03-30 01:02:07 +03:00
|
|
|
"toolbar": [
|
|
|
|
"heading",
|
|
|
|
"|",
|
|
|
|
"outdent",
|
|
|
|
"indent",
|
|
|
|
"|",
|
|
|
|
"bold",
|
|
|
|
"italic",
|
|
|
|
"link",
|
|
|
|
"underline",
|
|
|
|
"strikethrough",
|
|
|
|
"code",
|
|
|
|
"subscript",
|
|
|
|
"superscript",
|
|
|
|
"highlight",
|
|
|
|
"|",
|
|
|
|
"codeBlock",
|
|
|
|
"sourceEditing",
|
|
|
|
"insertImage",
|
|
|
|
"bulletedList",
|
|
|
|
"numberedList",
|
|
|
|
"todoList",
|
|
|
|
"|",
|
|
|
|
"blockQuote",
|
|
|
|
"imageUpload",
|
|
|
|
"|",
|
|
|
|
"fontSize",
|
|
|
|
"fontFamily",
|
|
|
|
"fontColor",
|
|
|
|
"fontBackgroundColor",
|
|
|
|
"mediaEmbed",
|
|
|
|
"removeFormat",
|
|
|
|
"insertTable",
|
|
|
|
],
|
|
|
|
"image": {
|
|
|
|
"toolbar": [
|
|
|
|
"imageTextAlternative",
|
|
|
|
"|",
|
|
|
|
"imageStyle:alignLeft",
|
|
|
|
"imageStyle:alignRight",
|
|
|
|
"imageStyle:alignCenter",
|
|
|
|
"imageStyle:side",
|
|
|
|
"|",
|
|
|
|
],
|
|
|
|
"styles": [
|
|
|
|
"full",
|
|
|
|
"side",
|
|
|
|
"alignLeft",
|
|
|
|
"alignRight",
|
|
|
|
"alignCenter",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
"table": {
|
|
|
|
"contentToolbar": [
|
|
|
|
"tableColumn",
|
|
|
|
"tableRow",
|
|
|
|
"mergeTableCells",
|
|
|
|
"tableProperties",
|
|
|
|
"tableCellProperties",
|
|
|
|
],
|
2022-11-23 11:41:43 +03:00
|
|
|
},
|
2024-03-30 01:02:07 +03:00
|
|
|
"heading": {
|
|
|
|
"options": [
|
|
|
|
{
|
|
|
|
"model": "paragraph",
|
|
|
|
"title": "Paragraph",
|
|
|
|
"class": "ck-heading_paragraph",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"model": "heading1",
|
|
|
|
"view": "h1",
|
|
|
|
"title": "Heading 1",
|
|
|
|
"class": "ck-heading_heading1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"model": "heading2",
|
|
|
|
"view": "h2",
|
|
|
|
"title": "Heading 2",
|
|
|
|
"class": "ck-heading_heading2",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"model": "heading3",
|
|
|
|
"view": "h3",
|
|
|
|
"title": "Heading 3",
|
|
|
|
"class": "ck-heading_heading3",
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"list": {
|
|
|
|
"properties": {
|
|
|
|
"styles": "true",
|
|
|
|
"startIndex": "true",
|
|
|
|
"reversed": "true",
|
|
|
|
}
|
2022-11-23 11:41:43 +03:00
|
|
|
},
|
|
|
|
}
|
2022-12-20 19:21:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
# JAZZMIN
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
JAZZMIN_SETTINGS = {
|
|
|
|
"site_title": "sanspie's site admin",
|
|
|
|
"site_header": "site admin",
|
|
|
|
"site_brand": "sanspie's site",
|
2023-04-05 08:50:00 +03:00
|
|
|
"site_logo": "images/favicons/favicon.ico",
|
|
|
|
"login_logo": "images/favicons/favicon.ico",
|
2022-12-20 19:21:39 +03:00
|
|
|
"site_icon": None,
|
|
|
|
"welcome_sign": "welcum back",
|
|
|
|
"copyright": "admin on akarpov.ru",
|
|
|
|
"user_avatar": "image_cropped",
|
|
|
|
}
|
2023-01-15 11:19:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
# DRF_CHUNKED_UPLOAD
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-01-15 12:31:15 +03:00
|
|
|
DRF_CHUNKED_UPLOAD_ABSTRACT_MODEL = False
|
2023-01-15 11:19:14 +03:00
|
|
|
DRF_CHUNKED_UPLOAD_PATH = "uploads/chucked/"
|
2023-01-16 00:30:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
# SHORTENER
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
SHORTENER_ADD_SLUG = True
|
|
|
|
SHORTENER_SLUG_LENGTH = 3
|
2023-08-10 17:25:10 +03:00
|
|
|
# let nginx do some magic here
|
|
|
|
SHORTENER_REDIRECT_TO = "https://akarpov.ru"
|
|
|
|
SHORTENER_HOST = "https://akarpov.ru"
|
2023-02-10 13:30:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
# ACTIVE_LINK
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-02-16 14:00:16 +03:00
|
|
|
ACTIVE_LINK_CSS_CLASS = "nav-active"
|
2023-03-28 00:26:49 +03:00
|
|
|
|
|
|
|
# MUSIC
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# MPD
|
|
|
|
MUSIC_MPD_HOST = env("MPD_HOST", default="")
|
2023-06-05 22:04:42 +03:00
|
|
|
MUSIC_MPD_PASSWORD = env("MPD_PASSWORD", default="")
|
2023-03-28 00:26:49 +03:00
|
|
|
|
|
|
|
# SPOTIFY
|
2023-06-05 22:04:42 +03:00
|
|
|
MUSIC_SPOTIFY_ID = env("SPOTIFY_ID", default="")
|
|
|
|
MUSIC_SPOTIFY_SECRET = env("SPOTIFY_SECRET", default="")
|
2023-03-28 00:26:49 +03:00
|
|
|
|
|
|
|
# YANDEX_MUSIC
|
2023-06-05 22:04:42 +03:00
|
|
|
MUSIC_YANDEX_TOKEN = env("YANDEX_TOKEN", default="")
|
2023-04-20 13:09:50 +03:00
|
|
|
|
2024-01-14 17:26:43 +03:00
|
|
|
# LAST.FM
|
|
|
|
LAST_FM_API_KEY = env("LAST_FM_API_KET", default="")
|
|
|
|
LAST_FM_SECRET = env("LAST_FM_SECRET", default="")
|
|
|
|
|
2023-04-20 13:09:50 +03:00
|
|
|
# ROBOTS
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
ROBOTS_USE_SITEMAP = True
|
|
|
|
ROBOTS_USE_SCHEME_IN_HOST = True
|
2023-05-09 22:48:35 +03:00
|
|
|
|
|
|
|
# LOCATION_FIELD
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
LOCATION_FIELD = {
|
|
|
|
"map.provider": "openstreetmap",
|
|
|
|
"search.provider": "nominatim",
|
|
|
|
}
|
2023-06-21 17:02:53 +03:00
|
|
|
|
|
|
|
# SENTRY
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
dsn = env("SENTRY_DSN", default="")
|
|
|
|
if dsn:
|
|
|
|
import sentry_sdk
|
|
|
|
from sentry_sdk.integrations.django import DjangoIntegration
|
|
|
|
|
|
|
|
sentry_sdk.init(
|
|
|
|
dsn=dsn,
|
|
|
|
traces_sample_rate=1.0,
|
|
|
|
integrations=[
|
|
|
|
DjangoIntegration(
|
|
|
|
transaction_style="url",
|
|
|
|
middleware_spans=True,
|
|
|
|
signals_spans=True,
|
|
|
|
cache_spans=True,
|
|
|
|
),
|
2023-10-25 10:42:08 +03:00
|
|
|
CeleryIntegration(monitor_beat_tasks=True, propagate_traces=True),
|
2023-06-21 17:02:53 +03:00
|
|
|
],
|
|
|
|
)
|
2023-11-07 03:43:05 +03:00
|
|
|
|
|
|
|
|
2023-11-20 22:22:19 +03:00
|
|
|
# ELASTICSEARCH
|
2023-11-07 03:43:05 +03:00
|
|
|
# ------------------------------------------------------------------------------
|
2023-11-20 22:22:19 +03:00
|
|
|
ELASTICSEARCH_DSL = {
|
|
|
|
"default": {"hosts": env("ELASTIC_SEARCH", default="http://127.0.0.1:9200/")},
|
2023-11-07 03:43:05 +03:00
|
|
|
}
|
2023-12-08 01:38:39 +03:00
|
|
|
USE_DEBUG_TOOLBAR = False
|
2024-04-07 14:59:10 +03:00
|
|
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
|
|
|
USE_X_FORWARDED_HOST = True
|
|
|
|
USE_X_FORWARDED_PORT = True
|