mirror of
https://github.com/seriousm4x/UpSnap.git
synced 2026-03-31 06:24:11 -04:00
175 lines
5.0 KiB
Python
175 lines
5.0 KiB
Python
"""
|
|
Django settings for backend project.
|
|
|
|
Generated by 'django-admin startproject' using Django 4.0.2.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/4.0/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/4.0/ref/settings/
|
|
"""
|
|
|
|
from pathlib import Path
|
|
import os
|
|
|
|
# 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.0/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY')
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = os.getenv('DJANGO_DEBUG', 'False') == 'True'
|
|
|
|
ALLOWED_HOSTS = ["*"]
|
|
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'channels',
|
|
'django_celery_beat',
|
|
'wol'
|
|
]
|
|
|
|
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',
|
|
]
|
|
|
|
ROOT_URLCONF = 'backend.urls'
|
|
|
|
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 = 'backend.wsgi.application'
|
|
WSGI_APPLICATION = 'backend.wsgi.application'
|
|
ASGI_APPLICATION = 'backend.asgi.application'
|
|
CELERY_BROKER_URL = f"redis://{os.getenv('REDIS_HOST', '127.0.0.1')}:{os.getenv('REDIS_PORT', 6379)}"
|
|
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
|
|
|
|
if os.getenv("DB_TYPE") == "postgres":
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.postgresql_psycopg2",
|
|
"NAME": os.getenv("DB_NAME", "upsnap"),
|
|
"USER": os.getenv("DB_USER", "upsnap"),
|
|
"PASSWORD": os.getenv("DB_PASSWORD", "upsnap"),
|
|
"HOST": os.getenv("DB_HOST", "127.0.0.1"),
|
|
"PORT": os.getenv("DB_PORT", 5432),
|
|
"OPTIONS": {
|
|
"connect_timeout": 30
|
|
}
|
|
}
|
|
}
|
|
elif os.getenv("DB_TYPE") == "mysql":
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.mysql",
|
|
"NAME": os.getenv("DB_NAME", "upsnap"),
|
|
"USER": os.getenv("DB_USER", "upsnap"),
|
|
"PASSWORD": os.getenv("DB_PASSWORD", "upsnap"),
|
|
"HOST": os.getenv("DB_HOST", "127.0.0.1"),
|
|
"PORT": os.getenv("DB_PORT", 3306),
|
|
"OPTIONS": {
|
|
"connect_timeout": 30
|
|
}
|
|
}
|
|
}
|
|
elif os.getenv("DB_TYPE") == "sqlite":
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME" : "db.sqlite3",
|
|
}
|
|
}
|
|
|
|
CHANNEL_LAYERS = {
|
|
"default": {
|
|
"BACKEND": "channels_redis.core.RedisChannelLayer",
|
|
"CONFIG": {
|
|
"hosts": [(os.getenv("REDIS_HOST", "127.0.0.1"), os.getenv("REDIS_PORT", 6379))],
|
|
"capacity": 1000,
|
|
"expiry": 10
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/4.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/4.0/topics/i18n/
|
|
|
|
LANGUAGE_CODE = os.getenv("DJANGO_LANGUAGE_CODE", "en")
|
|
|
|
TIME_ZONE = os.getenv("DJANGO_TIME_ZONE", "UTC")
|
|
|
|
USE_I18N = True
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/4.0/howto/static-files/
|
|
|
|
STATIC_URL = 'static/'
|
|
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
|
VERSION = "v2.0.0"
|