mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
Reorder base Django settings and read env vars
This commit is contained in:
parent
764eaafb95
commit
ccfc37d226
@ -2,45 +2,32 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
|
||||||
APPS_DIR = os.path.realpath(os.path.join(BASE_DIR, "apps"))
|
|
||||||
sys.path.append(APPS_DIR)
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'CHANGE_ME_IN_LOCAL_SETTINGS!'
|
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'CHANGE_ME_IN_LOCAL_SETTINGS!')
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = os.getenv('DJANGO_DEBUG', False)
|
||||||
|
|
||||||
ADMINS = (
|
|
||||||
# ('Admin', 'webmaster@example.com'),
|
|
||||||
)
|
|
||||||
|
|
||||||
SITE_ID = 1
|
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
# Theme overrides Django Admin templates
|
|
||||||
# 'theme',
|
|
||||||
|
|
||||||
# External apps
|
# External apps
|
||||||
'mailer',
|
'mailer',
|
||||||
'phonenumber_field',
|
'phonenumber_field',
|
||||||
'polymorphic',
|
'polymorphic',
|
||||||
'crispy_forms',
|
'crispy_forms',
|
||||||
'django_tables2',
|
'django_tables2',
|
||||||
|
|
||||||
# Django contrib
|
# Django contrib
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.admindocs',
|
'django.contrib.admindocs',
|
||||||
@ -51,6 +38,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'django.forms',
|
'django.forms',
|
||||||
|
|
||||||
# API
|
# API
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
@ -67,7 +55,6 @@ INSTALLED_APPS = [
|
|||||||
'treasury',
|
'treasury',
|
||||||
'wei',
|
'wei',
|
||||||
]
|
]
|
||||||
LOGIN_REDIRECT_URL = '/note/transfer/'
|
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
@ -97,16 +84,28 @@ TEMPLATES = [
|
|||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.contrib.messages.context_processors.messages',
|
'django.contrib.messages.context_processors.messages',
|
||||||
'django.template.context_processors.request',
|
'django.template.context_processors.request',
|
||||||
# 'django.template.context_processors.media',
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
|
|
||||||
|
|
||||||
WSGI_APPLICATION = 'note_kfet.wsgi.application'
|
WSGI_APPLICATION = 'note_kfet.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
|
# Database
|
||||||
|
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
|
||||||
|
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': os.getenv('DJANGO_DB_ENGINE', 'django.db.backends.sqlite3'),
|
||||||
|
'NAME': os.getenv('DJANGO_DB_NAME', os.path.join(BASE_DIR, 'db.sqlite3')),
|
||||||
|
'USER': os.getenv('DJANGO_DB_USER', 'note'),
|
||||||
|
'HOST': os.getenv('DJANGO_DB_HOST', 'localhost'),
|
||||||
|
'PORT': os.getenv('DJANGO_DB_PORT', ''), # Use default port
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
# Password validation
|
||||||
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
|
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
@ -125,16 +124,71 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
# Use our custom hasher in order to import NK15 passwords
|
|
||||||
|
# Internationalization
|
||||||
|
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
||||||
|
|
||||||
|
LANGUAGE_CODE = 'en'
|
||||||
|
|
||||||
|
TIME_ZONE = 'Europe/Paris'
|
||||||
|
|
||||||
|
USE_I18N = True
|
||||||
|
|
||||||
|
USE_L10N = True
|
||||||
|
|
||||||
|
USE_TZ = True
|
||||||
|
|
||||||
|
# Limit available languages to this subset
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
LANGUAGES = [
|
||||||
|
('de', _('German')),
|
||||||
|
('en', _('English')),
|
||||||
|
('fr', _('French')),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# Static files (CSS, JavaScript, Images)
|
||||||
|
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
||||||
|
|
||||||
|
STATIC_URL = '/static/'
|
||||||
|
|
||||||
|
# Add some custom statics from /note_kfet/static
|
||||||
|
STATICFILES_DIRS = [
|
||||||
|
os.path.join(BASE_DIR, 'note_kfet/static'),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Collect statics to /static/
|
||||||
|
# THIS FOLDER SOULD NOT BE IN GIT TREE!!!
|
||||||
|
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
|
||||||
|
|
||||||
|
# Add /apps/ directory to Python modules search path
|
||||||
|
import sys
|
||||||
|
sys.path.append(os.path.realpath(os.path.join(BASE_DIR, 'apps')))
|
||||||
|
print(BASE_DIR, sys.path)
|
||||||
|
|
||||||
|
# Use /locale/ for locale files
|
||||||
|
LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
|
||||||
|
|
||||||
|
# Use /note_kfet/fixtures for database fixtures
|
||||||
|
FIXTURE_DIRS = [os.path.join(BASE_DIR, 'note_kfet/fixtures')]
|
||||||
|
|
||||||
|
# NK15 password hasher for retrocompatibility
|
||||||
|
# On first login the password will be rehashed with PBKDF2PasswordHasher
|
||||||
PASSWORD_HASHERS = [
|
PASSWORD_HASHERS = [
|
||||||
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
||||||
'member.hashers.CustomNK15Hasher',
|
'member.hashers.CustomNK15Hasher',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Custom role-based permission system
|
||||||
AUTHENTICATION_BACKENDS = (
|
AUTHENTICATION_BACKENDS = (
|
||||||
'permission.backends.PermissionBackend', # Custom role-based permission system
|
'permission.backends.PermissionBackend',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Use /media/ for user uploaded media (user profile pictures)
|
||||||
|
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
||||||
|
MEDIA_URL = '/media/'
|
||||||
|
|
||||||
|
# Django REST Framework
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_PERMISSION_CLASSES': [
|
'DEFAULT_PERMISSION_CLASSES': [
|
||||||
# Control API access with our role-based permission system
|
# Control API access with our role-based permission system
|
||||||
@ -148,55 +202,34 @@ REST_FRAMEWORK = {
|
|||||||
'PAGE_SIZE': 20,
|
'PAGE_SIZE': 20,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Internationalization
|
# Take control on how widget templates are sourced
|
||||||
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
# See https://docs.djangoproject.com/en/2.2/ref/forms/renderers/#templatessetting
|
||||||
|
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en'
|
# After login redirect user to transfer page
|
||||||
|
LOGIN_REDIRECT_URL = '/note/transfer/'
|
||||||
|
|
||||||
LANGUAGES = [
|
# Use Crispy Bootstrap4 theme
|
||||||
('de', _('German')),
|
|
||||||
('en', _('English')),
|
|
||||||
('fr', _('French')),
|
|
||||||
]
|
|
||||||
|
|
||||||
TIME_ZONE = 'Europe/Paris'
|
|
||||||
|
|
||||||
USE_I18N = True
|
|
||||||
|
|
||||||
USE_L10N = True
|
|
||||||
|
|
||||||
USE_TZ = True
|
|
||||||
|
|
||||||
LOCALE_PATHS = [os.path.join(BASE_DIR, "locale")]
|
|
||||||
|
|
||||||
FIXTURE_DIRS = [os.path.join(BASE_DIR, "note_kfet/fixtures")]
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
|
||||||
# https://docs.djangoproject.com/en/2.2/howto/static-files/
|
|
||||||
|
|
||||||
# Absolute path to the directory static files should be collected to.
|
|
||||||
# Don't put anything in this directory yourself; store your static files
|
|
||||||
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
|
|
||||||
# Example: "/var/www/example.com/static/"
|
|
||||||
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
|
|
||||||
# STATICFILES_DIRS = [
|
|
||||||
# os.path.join(BASE_DIR, 'static')]
|
|
||||||
STATICFILES_DIRS = []
|
|
||||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||||
DJANGO_TABLES2_TEMPLATE = 'django_tables2/bootstrap4.html'
|
|
||||||
# URL prefix for static files.
|
|
||||||
# Example: "http://example.com/static/", "http://static.example.com/"
|
|
||||||
STATIC_URL = '/static/'
|
|
||||||
|
|
||||||
|
# Use Django Table2 Bootstrap4 theme
|
||||||
|
DJANGO_TABLES2_TEMPLATE = 'django_tables2/bootstrap4.html'
|
||||||
|
|
||||||
|
# Use only one Django Sites
|
||||||
|
SITE_ID = 1
|
||||||
|
|
||||||
|
# When a server error occured, send an email to these addresses
|
||||||
|
ADMINS = (
|
||||||
|
# ('Admin', 'webmaster@example.com'),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Default regex to validate users aliases
|
||||||
ALIAS_VALIDATOR_REGEX = r''
|
ALIAS_VALIDATOR_REGEX = r''
|
||||||
|
|
||||||
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
# Profile picture cropping
|
||||||
MEDIA_URL = '/media/'
|
|
||||||
|
|
||||||
# Profile Picture Settings
|
|
||||||
PIC_WIDTH = 200
|
PIC_WIDTH = 200
|
||||||
PIC_RATIO = 1
|
PIC_RATIO = 1
|
||||||
|
|
||||||
|
# Custom phone number format
|
||||||
PHONENUMBER_DB_FORMAT = 'NATIONAL'
|
PHONENUMBER_DB_FORMAT = 'NATIONAL'
|
||||||
PHONENUMBER_DEFAULT_REGION = 'FR'
|
PHONENUMBER_DEFAULT_REGION = 'FR'
|
||||||
|
Loading…
Reference in New Issue
Block a user