208 lines
5.5 KiB
Python
208 lines
5.5 KiB
Python
"""
|
|
Django settings for core project.
|
|
|
|
Generated by 'django-admin startproject' using Django 4.1.2.
|
|
|
|
For more information on this file, see
|
|
https://docs.djangoproject.com/en/4.1/topics/settings/
|
|
|
|
For the full list of settings and their values, see
|
|
https://docs.djangoproject.com/en/4.1/ref/settings/
|
|
"""
|
|
|
|
import os, random, string
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
from str2bool import str2bool
|
|
|
|
load_dotenv() # take environment variables from .env.
|
|
|
|
# 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.1/howto/deployment/checklist/
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = os.environ.get('SECRET_KEY', 'Super_Secr3t_9999')
|
|
|
|
# Enable/Disable DEBUG Mode
|
|
DEBUG = str2bool(os.environ.get('DEBUG'))
|
|
#print(' DEBUG -> ' + str(DEBUG) )
|
|
|
|
# Docker HOST
|
|
ALLOWED_HOSTS = ['*']
|
|
|
|
# Add here your deployment HOSTS
|
|
CSRF_TRUSTED_ORIGINS = ['http://localhost:8000', 'http://localhost:5085', 'http://127.0.0.1:8000', 'http://127.0.0.1:5085']
|
|
|
|
RENDER_EXTERNAL_HOSTNAME = os.environ.get('RENDER_EXTERNAL_HOSTNAME')
|
|
if RENDER_EXTERNAL_HOSTNAME:
|
|
ALLOWED_HOSTS.append(RENDER_EXTERNAL_HOSTNAME)
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'jazzmin',
|
|
'admin_material.apps.AdminMaterialDashboardConfig',
|
|
"django.contrib.admin",
|
|
"django.contrib.auth",
|
|
"django.contrib.contenttypes",
|
|
"django.contrib.sessions",
|
|
"django.contrib.messages",
|
|
"django.contrib.staticfiles",
|
|
|
|
# Serve UI pages
|
|
"apps.pages",
|
|
|
|
# Dynamic DT
|
|
"apps.dyn_dt",
|
|
|
|
# Dynamic API
|
|
"apps.dyn_api",
|
|
|
|
# Charts
|
|
"apps.charts",
|
|
|
|
# Tooling API-GEN
|
|
'rest_framework', # Include DRF # <-- NEW
|
|
'rest_framework.authtoken', # Include DRF Auth # <-- NEW
|
|
]
|
|
|
|
MIDDLEWARE = [
|
|
"django.middleware.security.SecurityMiddleware",
|
|
"whitenoise.middleware.WhiteNoiseMiddleware",
|
|
"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 = "config.urls"
|
|
|
|
UI_TEMPLATES = os.path.join(BASE_DIR, 'templates')
|
|
|
|
TEMPLATES = [
|
|
{
|
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
"DIRS": [UI_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 = "config.wsgi.application"
|
|
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
|
|
|
|
DB_ENGINE = os.getenv('DB_ENGINE' , None)
|
|
DB_USERNAME = os.getenv('DB_USERNAME' , None)
|
|
DB_PASS = os.getenv('DB_PASS' , None)
|
|
DB_HOST = os.getenv('DB_HOST' , None)
|
|
DB_PORT = os.getenv('DB_PORT' , None)
|
|
DB_NAME = os.getenv('DB_NAME' , None)
|
|
|
|
if DB_ENGINE and DB_NAME and DB_USERNAME:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE' : 'django.db.backends.' + DB_ENGINE,
|
|
'NAME' : DB_NAME,
|
|
'USER' : DB_USERNAME,
|
|
'PASSWORD': DB_PASS,
|
|
'HOST' : DB_HOST,
|
|
'PORT' : DB_PORT,
|
|
},
|
|
}
|
|
else:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': 'db.sqlite3',
|
|
}
|
|
}
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/4.1/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.1/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.1/howto/static-files/
|
|
|
|
STATIC_URL = '/static/'
|
|
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
|
|
|
STATICFILES_DIRS = (
|
|
os.path.join(BASE_DIR, 'static'),
|
|
)
|
|
|
|
#if not DEBUG:
|
|
# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
|
|
|
# Default primary key field type
|
|
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
|
|
LOGIN_REDIRECT_URL = '/'
|
|
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
|
|
|
|
|
# ### DYNAMIC_DATATB Settings ###
|
|
DYNAMIC_DATATB = {
|
|
# SLUG -> Import_PATH
|
|
'product' : "apps.pages.models.Product",
|
|
}
|
|
########################################
|
|
|
|
# Syntax: URI -> Import_PATH
|
|
DYNAMIC_API = {
|
|
# SLUG -> Import_PATH
|
|
'product' : "apps.pages.models.Product",
|
|
}
|
|
|
|
REST_FRAMEWORK = {
|
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
|
'rest_framework.authentication.SessionAuthentication',
|
|
'rest_framework.authentication.TokenAuthentication',
|
|
],
|
|
}
|
|
########################################
|