213 lines
6.1 KiB
Python
213 lines
6.1 KiB
Python
"""
|
|
Django settings for safeshare project.
|
|
|
|
Generated by 'django-admin startproject' using Django 4.2.6.
|
|
|
|
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/
|
|
"""
|
|
|
|
from datetime import timedelta
|
|
from pathlib import Path
|
|
import environ
|
|
import os
|
|
|
|
env = environ.Env(
|
|
# set casting, default value
|
|
DEBUG=(bool, False)
|
|
)
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
|
|
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
|
|
|
|
# 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 = env('SECRET_KEY', default='django-insecure-j-35kvg#frf3@swdljf8(f0%!j4-1=%2-9v7q4+ek(aj&5-#yw')
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = env('DEBUG', default=False)
|
|
|
|
ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=['*'])
|
|
|
|
REDIS_HOST = env.str('REDIS_HOST', default='localhost')
|
|
REDIS_PORT = env.str('REDIS_PORT', default='6379')
|
|
REDIS_DB = env.str('REDIS_DB', default='0')
|
|
TRASH_TIMEOUT = env.int('TRASH_TIMEOUT', default=60)
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'rest_framework',
|
|
'corsheaders',
|
|
'drf_yasg',
|
|
'safeshare_app',
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
'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',
|
|
'corsheaders.middleware.CorsMiddleware',
|
|
]
|
|
|
|
ROOT_URLCONF = 'safeshare.urls'
|
|
|
|
# REST_FRAMEWORK = {
|
|
# 'DEFAULT_PERMISSION_CLASSES': (
|
|
# 'rest_framework.permissions.IsAuthenticated',
|
|
# ),
|
|
# 'DEFAULT_AUTHENTICATION_CLASSES': (
|
|
# 'rest_framework_simplejwt.authentication.JWTAuthentication',
|
|
# 'rest_framework.authentication.SessionAuthentication',
|
|
# 'rest_framework.authentication.BasicAuthentication',
|
|
# ),
|
|
# }
|
|
SIMPLE_JWT = {
|
|
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=10),
|
|
'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
|
|
"ROTATE_REFRESH_TOKENS": True,
|
|
"BLACKLIST_AFTER_ROTATION": True,
|
|
"ALGORITHM": "HS256",
|
|
"SIGNING_KEY": SECRET_KEY,
|
|
"VERIFYING_KEY": None,
|
|
"USER_ID_FIELD": "id",
|
|
"USER_ID_CLAIM": "user_id",
|
|
"AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",),
|
|
"TOKEN_TYPE_CLAIM": "token_type",
|
|
}
|
|
|
|
CORS_ALLOWED_ORIGINS = [
|
|
'http://localhost:3000',
|
|
]
|
|
|
|
CORS_EXPOSE_HEADERS = [
|
|
'Content-Disposition',
|
|
'Content-Type',
|
|
]
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [],
|
|
'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 = 'safeshare.wsgi.application'
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
|
|
|
if os.getenv('GITHUB_WORKFLOW'):
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.postgresql',
|
|
'NAME': 'github-actions',
|
|
'USER': 'postgres',
|
|
'PASSWORD': 'postgres',
|
|
'HOST': 'localhost',
|
|
'PORT': '5432'
|
|
}
|
|
}
|
|
else:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
# Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
|
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), # Or path to database file if using sqlite3.
|
|
'USER': '', # Not used with sqlite3.
|
|
'PASSWORD': '', # Not used with sqlite3.
|
|
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
|
|
'PORT': '', # Set to empty string for default. Not used with sqlite3.
|
|
}
|
|
}
|
|
|
|
if env.bool('CACHE', default=False):
|
|
CACHES = {
|
|
"default": {
|
|
"BACKEND": "django.core.cache.backends.redis.RedisCache",
|
|
"LOCATION": f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}",
|
|
}
|
|
}
|
|
|
|
|
|
PASSWORD_HASHERS = [
|
|
"django.contrib.auth.hashers.Argon2PasswordHasher",
|
|
"django.contrib.auth.hashers.PBKDF2PasswordHasher",
|
|
"django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
|
|
"django.contrib.auth.hashers.BCryptSHA256PasswordHasher",
|
|
"django.contrib.auth.hashers.ScryptPasswordHasher",
|
|
]
|
|
|
|
# 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',
|
|
},
|
|
]
|
|
|
|
# Media Storage
|
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
|
|
|
if not os.path.exists(MEDIA_ROOT):
|
|
os.makedirs(MEDIA_ROOT)
|
|
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/4.2/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/4.2/howto/static-files/
|
|
|
|
STATIC_URL = 'static/'
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|