<filename>esialogin/settings.py<gh_stars>0
"""
Django settings for esialogin project.

Generated by 'django-admin startproject' using Django 3.1.3.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

import os, sys
from pathlib import Path
from settings_json import get_setting

# Build paths inside the project like this: BASE_DIR / 'subdir'.
#BASE_DIR = Path(__file__).resolve().parent.parent
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(PROJECT_ROOT, 'apps'))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<KEY>'

# SECURITY WARNING: don't run with debug turned on in production!
#DEBUG = True
DEBUG = get_setting('DEBUG')

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [

    'about.apps.AboutConfig',
    'crypto.apps.CryptoConfig',
    'login.apps.LoginConfig',
    'user.apps.UserConfig',

    #'django.contrib.admin',
    #'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    #'django.contrib.messages',
    'django.contrib.staticfiles',
]

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 = 'esialogin.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(PROJECT_ROOT, '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 = 'esialogin.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases


if get_setting('USE_POSTGRESQL'):
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': get_setting('DB_NAME'),
            'USER': get_setting('DB_USER'),
            'PASSWORD': get_setting('DB_PASSWORD'),
            'HOST': get_setting('DB_HOST'),
            'PORT': get_setting('DB_PORT'),
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': '%s/system/db.sqlite3' % BASE_DIR,
        }
    }

# Password validation
# https://docs.djangoproject.com/en/3.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/3.1/topics/i18n/

LANGUAGE_CODE = 'ru-RU'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = False
USE_L10N = False
USE_TZ = False


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = ( os.path.join(PROJECT_ROOT, 'static/'), )

SESSION_COOKIE_AGE = 86400

SYSTEMNAME = 'ESIA LOGIN'
SHORTSYSTEMNAME = 'ESIA'

SIGN_TMP_PATH = BASE_DIR + '/crypto/tmpfs/'
SIGN_PASSWORD = get_setting('SIGN_PASSWORD')
SHA1_PUBLIC_KEY = get_setting('SHA1_PUBLIC_KEY')

SYSTEM_URL = get_setting('SYSTEM_URL')
ESIA_SCOPE = get_setting('ESIA_SCOPE')
ESIA_CLIENT_ID = get_setting('ESIA_CLIENT_ID')
ESIA_TEST = get_setting('ESIA_TEST')

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'large': {
            'format':'%(asctime)s %(levelname)s %(process)d %(pathname)s %(funcName)s %(lineno)d %(message)s'
        },
        'tiny': {
            'format':'%(asctime)s %(message)s'
        },
        'simple': {
            'format':'%(asctime)s %(levelname)s %(funcName)s %(message)s'
        },
    },
    'handlers': {
        'requests': {
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            'maxBytes': 1048576,
            'backupCount': 5,
            'filename': BASE_DIR + '/logs/requests.log',
            'formatter': 'simple',
        },
        'service': {
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            'maxBytes': 1048576,
            'backupCount': 5,
            'filename': BASE_DIR + '/logs/service.log',
            'formatter': 'simple',
        },
        'system': {
            'level': 'ERROR',
            'class': 'logging.handlers.RotatingFileHandler',
            'maxBytes': 1048576,
            'backupCount': 5,
            'filename': BASE_DIR + '/logs/system.log',
            'formatter': 'simple',
        },
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'simple',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['system', 'console'],
            'level': 'INFO',
            'propagate': False,
        },
        'request': {
            'handlers': ['requests', 'console'],
            'level': 'INFO',
            'propagate': False,
        },
        'service': {
            'handlers': ['service', 'console'],
            'level': 'INFO',
            'propagate': False,
        },
    },
}
