185 lines
5.1 KiB
Python
185 lines
5.1 KiB
Python
"""
|
|
Django settings for music_storage project.
|
|
|
|
Generated by 'django-admin startproject' using Django 6.0.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/6.0/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/6.0/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
|
|
|
|
load_dotenv(BASE_DIR / ".env")
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = os.getenv("SECRET_KEY", "")
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = os.getenv("DJANGO_DEBUG", "False") == "True"
|
|
|
|
ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "").split(",")
|
|
|
|
if not DEBUG:
|
|
USE_X_FORWARDED_HOST = True
|
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
|
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
# External apps
|
|
'storages',
|
|
'axes',
|
|
# Custom apps
|
|
'core',
|
|
'music',
|
|
'logger',
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
# Third-party middlewares
|
|
'axes.middleware.AxesMiddleware',
|
|
"whitenoise.middleware.WhiteNoiseMiddleware",
|
|
# Default Django middlewares
|
|
'django.middleware.security.SecurityMiddleware',
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
'django.middleware.common.CommonMiddleware',
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
# Custom middlewares
|
|
"core.middleware.current_request.CurrentRequestMiddleware",
|
|
"logger.middleware.AccessLogMiddleware",
|
|
]
|
|
|
|
ROOT_URLCONF = 'music_storage.urls'
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [BASE_DIR / 'templates',],
|
|
'APP_DIRS': True,
|
|
'OPTIONS': {
|
|
'context_processors': [
|
|
'django.template.context_processors.request',
|
|
'django.contrib.auth.context_processors.auth',
|
|
'django.contrib.messages.context_processors.messages',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'music_storage.wsgi.application'
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
|
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.postgresql",
|
|
"NAME": os.getenv("DB_NAME", ""),
|
|
"USER": os.getenv("DB_USER", ""),
|
|
"PASSWORD": os.getenv("DB_PASSWORD", ""),
|
|
"HOST": os.getenv("DB_HOST", ""),
|
|
"PORT": os.getenv("DB_PORT", ""),
|
|
}
|
|
}
|
|
|
|
# Authentication backends
|
|
# https://django-axes.readthedocs.io/en/latest/2_installation.html
|
|
# https://docs.djangoproject.com/en/6.0/ref/settings/#authentication-backends
|
|
AUTHENTICATION_BACKENDS = [
|
|
'axes.backends.AxesBackend',
|
|
'django.contrib.auth.backends.ModelBackend',
|
|
]
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/6.0/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.0/topics/i18n/
|
|
|
|
LANGUAGE_CODE = 'en-us'
|
|
|
|
TIME_ZONE = 'UTC'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
|
|
|
STATIC_URL = 'static/'
|
|
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
|
STATICFILES_DIRS = [
|
|
BASE_DIR / STATIC_URL
|
|
]
|
|
STATICFILES_STORAGE = (
|
|
"whitenoise.storage.CompressedManifestStaticFilesStorage"
|
|
)
|
|
|
|
STORAGES = {
|
|
# default storage for user uploads
|
|
"default": {
|
|
"BACKEND": "storages.backends.s3.S3Storage",
|
|
"OPTIONS": {
|
|
"access_key": os.getenv("S3_ACCESS_KEY", ""),
|
|
"secret_key": os.getenv("S3_SECRET_KEY", ""),
|
|
"bucket_name": os.getenv("S3_BUCKET_NAME", ""),
|
|
"endpoint_url": os.getenv("S3_ENDPOINT_URL", ""),
|
|
"region_name": os.getenv("S3_REGION_NAME", ""),
|
|
"signature_version": os.getenv("S3_SIGNATURE_VERSION", ""),
|
|
}
|
|
},
|
|
|
|
# static files — если нужно, может остаться на FileSystemStorage
|
|
"staticfiles": {
|
|
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
|
|
}
|
|
}
|
|
|
|
|
|
# AXES Configuration
|
|
AXES_ENAVLED = False if DEBUG else True
|
|
AXES_FAILURE_LIMIT = 5
|
|
AXES_COOLOFF_TIME = 0.25 # in hours
|
|
AXES_LOCK_OUT_AT_FAILURE = True
|
|
AXES_VERBOSE = True
|
|
AXES_LOCKOUT_PARAMETERS = [["ip_address", "user_agent"]]
|