Une interface REST partielle pour Noethys
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

258 lines
8.9 KiB

"""
Django settings for resthys project.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import logging
import os.path
import environ
logger = logging.getLogger('resthys')
# ENVIRONMENT VARIABLES AND PATHS
# ------------------------------------------------------------------------------
# Load environment variables
env = environ.Env()
# Package - e.g. Django project - root and apps directories
root_dir = environ.Path(__file__) - 2
apps_dir = root_dir.path('apps')
# Base directory of the app instance
# Note that it should be defined in OS environment variables in case of a
# multi-instances application.
base_dir = env.path('BASE_DIR', default=str(root_dir - 1))
# Local directory used for static and templates overrides
local_dir = base_dir.path('local')
# Directory for variable stuffs, i.e. user-uploaded media
var_dir = base_dir.path('var')
if not os.path.isdir(var_dir()):
os.mkdir(var_dir(), mode=0o755)
# Whether config.env should be loaded here
READ_CONFIG_FILE = env.bool('DJANGO_READ_CONFIG_FILE', default=True)
if READ_CONFIG_FILE:
# Note that OS environment variables have precedence over variables defined
# in the config.env file. The latter will only be used if not defined as
# environment variables.
env_file = str(base_dir.path('config.env'))
if os.path.isfile(env_file):
logger.debug('Loading configuration from: %s', env_file)
env.read_env(env_file)
else:
logger.warning('Configuration file does not exist: %s', env_file)
# Location on which the application is served
APP_LOCATION = env('APP_LOCATION', default='/')
# APP CONFIGURATION
# ------------------------------------------------------------------------------
DJANGO_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
# Project dependencies
THIRD_PARTY_APPS = []
# Project applications
LOCAL_APPS = [
'resthys.base',
]
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
# MIDDLEWARE CONFIGURATION
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#middleware
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',
]
# DEBUG
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#debug
DEBUG = env.bool('DJANGO_DEBUG', default=False)
# FIXTURE CONFIGURATION
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#fixture-dirs
FIXTURE_DIRS = (
root_dir('fixtures'),
)
# EMAIL CONFIGURATION
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/topics/email/#email-backends
# @link https://django-environ.readthedocs.io/en/stable/#supported-types
vars().update(env.email_url(
'DJANGO_EMAIL_URL', default='smtp://localhost:25'))
DEFAULT_FROM_EMAIL = env('DEFAULT_FROM_EMAIL', default='webmaster@localhost')
# MANAGER CONFIGURATION
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#admins
ADMINS = [
("""Cliss XXI""", 'tech@cliss21.com'),
]
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#managers
MANAGERS = ADMINS
# DATABASE CONFIGURATION
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#databases
# @link https://django-environ.readthedocs.io/en/stable/#supported-types
DATABASES = {
'default': env.db_url(
'DJANGO_DATABASE_URL', default='sqlite:///{}'.format(
base_dir('sqlite.db'))),
}
# GENERAL CONFIGURATION
# ------------------------------------------------------------------------------
# Local time zone for this installation.
TIME_ZONE = 'Europe/Paris'
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#language-code
LANGUAGE_CODE = 'fr'
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#use-i18n
USE_I18N = True
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#use-l10n
USE_L10N = True
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#use-tz
USE_TZ = True
# TEMPLATE CONFIGURATION
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#templates
# @link https://docs.djangoproject.com/en/2.0/topics/templates/
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
root_dir('templates'),
],
'OPTIONS': {
'debug': DEBUG,
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
# 'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
if os.path.isdir(local_dir('templates')):
TEMPLATES[0]['DIRS'].insert(0, local_dir('templates'))
# STATIC FILE CONFIGURATION
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#static-files
STATIC_ROOT = var_dir('static')
STATIC_URL = os.path.join(APP_LOCATION, 'static/')
STATICFILES_DIRS = [
root_dir('static'),
]
if os.path.isdir(local_dir('static')):
STATICFILES_DIRS.insert(0, local_dir('static'))
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
# MEDIA CONFIGURATION
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#media-root
MEDIA_ROOT = var_dir('media')
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#media-url
MEDIA_URL = os.path.join(APP_LOCATION, 'media/')
# URL Configuration
# ------------------------------------------------------------------------------
ROOT_URLCONF = 'resthys.urls'
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#wsgi-application
WSGI_APPLICATION = 'resthys.wsgi.application'
# PASSWORD STORAGE SETTINGS
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/ref/settings/#password-hashers
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
# @link https://docs.djangoproject.com/en/2.0/topics/auth/passwords/#using-argon2-with-django # noqa
# 'django.contrib.auth.hashers.Argon2PasswordHasher',
]
# PASSWORD VALIDATION
# ------------------------------------------------------------------------------
# @link https://docs.djangoproject.com/en/2.0/topics/auth/passwords/#password-validation # noqa
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'),
},
]
# COOKIES
# ------------------------------------------------------------------------------
SESSION_COOKIE_PATH = APP_LOCATION
CSRF_COOKIE_PATH = APP_LOCATION
# ------------------------------------------------------------------------------
# APPLICATION AND 3RD PARTY LIBRARY SETTINGS
# ------------------------------------------------------------------------------
Map all the world