Files
ProFi/tisbiProFi/settings.py

206 lines
5.8 KiB
Python
Raw Normal View History

2025-05-18 19:19:16 +03:00
"""
Django settings for tisbiProFi project.
Generated by 'django-admin startproject' using Django 4.2.21.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os
2025-05-19 17:22:00 +03:00
from datetime import timedelta
2025-05-18 19:19:16 +03:00
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/4.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-g*su%0=3d!dh^d#!@f1xow-@v#fuwr$#rsvl!if^r002s1=!t8'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(os.environ.get('LOCALDEV', False))
ALLOWED_HOSTS = [
'localhost',
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
2025-05-19 12:54:50 +03:00
'corsheaders',
'rest_framework',
"django_filters",
'drf_yasg',
2025-05-19 17:22:00 +03:00
'djoser',
'rest_framework_simplejwt',
2025-05-18 19:19:16 +03:00
"core.apps.CoreConfig",
'users.apps.UsersConfig',
2025-05-18 21:29:04 +03:00
"employees.apps.EmployeesConfig",
"education.apps.EducationConfig",
"events.apps.EventsConfig",
"outreach.apps.OutreachConfig",
2025-05-19 18:07:12 +03:00
"surveys.apps.SurveysConfig",
"frontend.apps.FrontendConfig"
2025-05-18 19:19:16 +03:00
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
2025-05-19 12:54:50 +03:00
'corsheaders.middleware.CorsMiddleware',
2025-05-18 19:19:16 +03:00
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'tisbiProFi.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates']
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'tisbiProFi.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
if not DEBUG:
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', 'db'), # 'db' - имя сервиса в Docker Compose
'PORT': os.getenv('DB_PORT', '5432'),
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.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',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'static'
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
2025-05-18 21:29:04 +03:00
AUTH_USER_MODEL = "users.Account"
2025-05-19 12:54:50 +03:00
CORS_ORIGIN_WHITELIST = ['http://localhost:8000',
'http://localhost:3000']
CSRF_TRUSTED_ORIGINS = ['http://localhost:8000',
'http://localhost:3000']
CORS_ALLOW_CREDENTIALS = True
REST_FRAMEWORK = {
"DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.URLPathVersioning",
"DEFAULT_VERSION": "v1",
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 10,
"DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"],
2025-05-19 17:22:00 +03:00
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_simplejwt.authentication.JWTAuthentication",
"rest_framework.authentication.SessionAuthentication", # Сессионная аутентификация
),
2025-05-19 12:54:50 +03:00
}
2025-05-19 17:22:00 +03:00
SIMPLE_JWT = {
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=30),
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
}
DJOSER = {
"LOGIN_FIELD": "login", # Используем поле login вместо username
"USER_CREATE_PASSWORD_RETYPE": True,
"SET_PASSWORD_RETYPE": True,
"PASSWORD_RESET_CONFIRM_URL": "password/reset/confirm/{uid}/{token}",
"USERNAME_RESET_CONFIRM_URL": "username/reset/confirm/{uid}/{token}",
"ACTIVATION_URL": "activate/{uid}/{token}",
"SEND_ACTIVATION_EMAIL": False, # Отключаем отправку email, если не нужно
"SERIALIZERS": {
"user_create": "users.serializers.AccountSerializer",
"user": "users.serializers.AccountSerializer",
},
}