222 lines
6.3 KiB
Python
222 lines
6.3 KiB
Python
# -*- encoding: utf-8 -*-
|
|
|
|
import os, environ
|
|
from pathlib import Path
|
|
|
|
from django.utils import timezone
|
|
|
|
now = timezone.now()
|
|
env = environ.Env(
|
|
# set casting, default value
|
|
DEBUG=(bool, True)
|
|
)
|
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
# BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
|
BASE_DIR = Path(__file__).parent.parent
|
|
CORE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
print(BASE_DIR, CORE_DIR)
|
|
|
|
# Take environment variables from .env file
|
|
environ.Env.read_env(BASE_DIR / ".env")
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
|
SECRET_KEY = env('SECRET_KEY', default='S#perS3crEt_007')
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
|
DEBUG = env('DEBUG')
|
|
|
|
# Assets Management
|
|
ASSETS_ROOT = os.getenv('ASSETS_ROOT', '/static/assets')
|
|
|
|
# load production server from .env
|
|
ALLOWED_HOSTS = ['localhost', 'localhost:85', '127.0.0.1', '192.168.0.19', env('SERVER', default='127.0.0.1') ]
|
|
CSRF_TRUSTED_ORIGINS = ['http://localhost:85', 'http://127.0.0.1', 'https://' + env('SERVER', default='127.0.0.1') ]
|
|
|
|
# Application definition
|
|
|
|
INSTALLED_APPS = [
|
|
'django.contrib.admin',
|
|
'django.contrib.auth',
|
|
'django.contrib.contenttypes',
|
|
'django.contrib.sessions',
|
|
'django.contrib.messages',
|
|
'django.contrib.staticfiles',
|
|
'rest_framework',
|
|
"rest_framework.authtoken",
|
|
"django_filters",
|
|
'apps.api',
|
|
'apps.home',
|
|
'apps.authentication'
|
|
]
|
|
|
|
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 = 'core.urls'
|
|
LOGIN_REDIRECT_URL = "home" # Route defined in home/urls.py
|
|
LOGOUT_REDIRECT_URL = "home" # Route defined in home/urls.py
|
|
TEMPLATE_DIR = os.path.join(CORE_DIR, "apps/templates") # ROOT dir for templates
|
|
|
|
TEMPLATES = [
|
|
{
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
'DIRS': [TEMPLATE_DIR],
|
|
'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',
|
|
'apps.context_processors.cfg_assets_root',
|
|
],
|
|
},
|
|
},
|
|
]
|
|
|
|
WSGI_APPLICATION = 'core.wsgi.application'
|
|
|
|
# Database
|
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
|
|
|
if os.environ.get('DB_ENGINE') and os.environ.get('DB_ENGINE') == "mysql":
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE' : 'django.db.backends.mysql',
|
|
'NAME' : os.getenv('DB_NAME' , 'appseed_db'),
|
|
'USER' : os.getenv('DB_USERNAME' , 'appseed_db_usr'),
|
|
'PASSWORD': os.getenv('DB_PASS' , 'pass'),
|
|
'HOST' : os.getenv('DB_HOST' , 'localhost'),
|
|
'PORT' : os.getenv('DB_PORT' , 3306),
|
|
},
|
|
}
|
|
else:
|
|
DATABASES = {
|
|
'default': {
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
'NAME': 'db.sqlite3',
|
|
}
|
|
}
|
|
|
|
# Password validation
|
|
# https://docs.djangoproject.com/en/3.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',
|
|
},
|
|
]
|
|
|
|
# Loggiong
|
|
|
|
LOGGING_DIR = BASE_DIR / "logs"
|
|
LOGGING_DIR.mkdir(exist_ok=True)
|
|
|
|
LOGGING = {
|
|
'version': 1,
|
|
'disable_existing_loggers': False,
|
|
'handlers': {
|
|
'file': {
|
|
'level': 'DEBUG',
|
|
'class': 'logging.FileHandler',
|
|
'filename': LOGGING_DIR / f'{now}.log',
|
|
"formatter": "verbose",
|
|
},
|
|
'console': {
|
|
'level': 'DEBUG',
|
|
'class': 'logging.StreamHandler',
|
|
"formatter": "verbose"
|
|
},
|
|
"timed_file": {
|
|
"level": "DEBUG",
|
|
"class": "logging.handlers.TimedRotatingFileHandler",
|
|
"when": "D",
|
|
"interval": 1,
|
|
"backupCount": 3,
|
|
"encoding": "UTF-8",
|
|
"filename": LOGGING_DIR / "debug.log",
|
|
"formatter": "verbose"
|
|
}
|
|
},
|
|
'loggers': {
|
|
"apps": {
|
|
"handlers": ["timed_file", "console"],
|
|
"level": "DEBUG",
|
|
"propagate": True
|
|
},
|
|
"django": {
|
|
"handlers": ["timed_file", "console"],
|
|
"level": "INFO",
|
|
"propagate": True
|
|
},
|
|
"django.request": {
|
|
"handlers": ["timed_file", "console"],
|
|
"level": "ERROR",
|
|
"propagate": True
|
|
}
|
|
},
|
|
"formatters": {
|
|
"verbose": {
|
|
"format": "[%(asctime)s] [%(levelname)s] [%(name)s]: %(message)s",
|
|
"datefmt": "%Y-%m-%d %H:%M:%S",
|
|
}
|
|
}
|
|
}
|
|
|
|
# Internationalization
|
|
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
|
|
|
LANGUAGE_CODE = 'en-gb'
|
|
|
|
TIME_ZONE = 'Europe/London'
|
|
|
|
USE_I18N = True
|
|
|
|
USE_L10N = True
|
|
|
|
USE_TZ = True
|
|
|
|
#############################################################
|
|
# SRC: https://devcenter.heroku.com/articles/django-assets
|
|
|
|
# Static files (CSS, JavaScript, Images)
|
|
# https://docs.djangoproject.com/en/1.9/howto/static-files/
|
|
STATIC_ROOT = os.path.join(CORE_DIR, 'staticfiles')
|
|
STATIC_URL = '/static/'
|
|
|
|
# Extra places for collectstatic to find static files.
|
|
STATICFILES_DIRS = (
|
|
os.path.join(CORE_DIR, 'apps/static'),
|
|
)
|
|
|
|
# Media Files
|
|
MEDIA_ROOT = os.path.join(CORE_DIR, 'media')
|
|
MEDIA_URL = '/media/'
|
|
|
|
#############################################################
|
|
#############################################################
|
|
|
|
# If route isnt found, try again with appended slash
|
|
APPEND_SLASH = True
|
|
|
|
AUTH_USER_MODEL = "authentication.User"
|
|
|
|
LOGIN_URL = "/login/" |