2024-02-07 01:26:49 +00:00
|
|
|
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
2019-07-08 09:08:07 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2019-07-07 20:49:02 +00:00
|
|
|
|
2020-08-09 16:34:51 +00:00
|
|
|
# This file implements sane defaults to use in production.
|
|
|
|
# Some settings are overridable with an environment variable.
|
|
|
|
|
2019-07-07 20:49:02 +00:00
|
|
|
import os
|
2019-07-08 09:08:07 +00:00
|
|
|
|
2019-07-07 20:49:02 +00:00
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
2021-12-23 20:59:37 +00:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2020-01-27 20:49:02 +00:00
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
2019-07-07 20:49:02 +00:00
|
|
|
|
|
|
|
# Quick-start development settings - unsuitable for production
|
|
|
|
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
|
|
|
|
|
|
|
|
# SECURITY WARNING: keep the secret key used in production secret!
|
2020-08-09 16:34:51 +00:00
|
|
|
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'CHANGE_ME_IN_ENV_SETTINGS')
|
2019-07-07 20:49:02 +00:00
|
|
|
|
|
|
|
# SECURITY WARNING: don't run with debug turned on in production!
|
2020-08-09 15:52:19 +00:00
|
|
|
DEBUG = os.getenv('DJANGO_DEBUG', False)
|
2019-07-08 09:08:07 +00:00
|
|
|
|
2020-08-09 16:34:51 +00:00
|
|
|
ALLOWED_HOSTS = [
|
2020-08-09 16:39:06 +00:00
|
|
|
os.getenv('NOTE_URL', 'localhost'),
|
2020-08-09 16:34:51 +00:00
|
|
|
]
|
2019-07-07 20:49:02 +00:00
|
|
|
|
2022-03-09 11:12:56 +00:00
|
|
|
# Use secure cookies in production
|
|
|
|
SESSION_COOKIE_SECURE = not DEBUG
|
|
|
|
CSRF_COOKIE_SECURE = not DEBUG
|
|
|
|
|
|
|
|
# Remember HTTPS for 1 year
|
|
|
|
SECURE_HSTS_SECONDS = 31536000
|
|
|
|
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
|
|
|
|
SECURE_HSTS_PRELOAD = True
|
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
|
2019-07-07 20:49:02 +00:00
|
|
|
# Application definition
|
|
|
|
|
|
|
|
INSTALLED_APPS = [
|
2019-07-17 09:17:50 +00:00
|
|
|
# External apps
|
2020-08-10 13:36:41 +00:00
|
|
|
'bootstrap_datepicker_plus',
|
|
|
|
'colorfield',
|
2024-02-11 21:24:37 +00:00
|
|
|
'crispy_bootstrap4',
|
2020-08-10 13:36:41 +00:00
|
|
|
'crispy_forms',
|
2024-01-24 19:14:32 +00:00
|
|
|
# 'django_htcpcp_tea',
|
2020-08-10 13:36:41 +00:00
|
|
|
'django_tables2',
|
2020-08-03 18:09:16 +00:00
|
|
|
'mailer',
|
2020-08-05 12:14:51 +00:00
|
|
|
'phonenumber_field',
|
2019-07-17 09:17:50 +00:00
|
|
|
'polymorphic',
|
2020-09-21 09:03:07 +00:00
|
|
|
'oauth2_provider',
|
2020-08-09 15:52:19 +00:00
|
|
|
|
2019-07-08 11:51:15 +00:00
|
|
|
# Django contrib
|
2020-09-21 10:34:34 +00:00
|
|
|
# Django Admin will autodiscover our apps for our custom admin site.
|
|
|
|
'django.contrib.admin',
|
2019-07-08 09:08:07 +00:00
|
|
|
'django.contrib.admindocs',
|
2019-07-07 20:49:02 +00:00
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
2019-07-08 09:08:07 +00:00
|
|
|
'django.contrib.sites',
|
2019-07-07 20:49:02 +00:00
|
|
|
'django.contrib.messages',
|
|
|
|
'django.contrib.staticfiles',
|
2020-03-27 12:50:02 +00:00
|
|
|
'django.forms',
|
2020-08-13 15:04:10 +00:00
|
|
|
'django_filters',
|
2020-12-23 20:06:30 +00:00
|
|
|
'django_extensions',
|
2020-08-09 15:52:19 +00:00
|
|
|
|
2020-02-06 22:29:17 +00:00
|
|
|
# API
|
|
|
|
'rest_framework',
|
2020-02-17 18:25:33 +00:00
|
|
|
'rest_framework.authtoken',
|
2019-07-08 11:51:15 +00:00
|
|
|
|
|
|
|
# Note apps
|
2020-04-05 03:17:28 +00:00
|
|
|
'api',
|
2019-07-16 10:43:23 +00:00
|
|
|
'activity',
|
2024-07-05 09:57:44 +00:00
|
|
|
'food',
|
2020-04-05 03:17:28 +00:00
|
|
|
'logs',
|
2019-07-16 10:43:23 +00:00
|
|
|
'member',
|
2019-07-08 12:30:58 +00:00
|
|
|
'note',
|
2020-03-07 09:42:51 +00:00
|
|
|
'permission',
|
2020-04-05 03:17:28 +00:00
|
|
|
'registration',
|
2020-07-25 15:25:57 +00:00
|
|
|
'scripts',
|
2020-04-05 03:17:28 +00:00
|
|
|
'treasury',
|
2020-04-11 01:37:06 +00:00
|
|
|
'wei',
|
2019-07-07 20:49:02 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
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',
|
2019-07-08 09:08:07 +00:00
|
|
|
'django.contrib.admindocs.middleware.XViewMiddleware',
|
2019-07-07 20:49:02 +00:00
|
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
2019-07-08 09:08:07 +00:00
|
|
|
'django.middleware.locale.LocaleMiddleware',
|
|
|
|
'django.contrib.sites.middleware.CurrentSiteMiddleware',
|
2020-10-19 21:44:47 +00:00
|
|
|
'note_kfet.middlewares.SessionMiddleware',
|
|
|
|
'note_kfet.middlewares.LoginByIPMiddleware',
|
2020-02-21 17:45:18 +00:00
|
|
|
'note_kfet.middlewares.TurbolinksMiddleware',
|
2020-12-31 14:40:18 +00:00
|
|
|
'note_kfet.middlewares.ClacksMiddleware',
|
2019-07-07 20:49:02 +00:00
|
|
|
]
|
2024-02-07 19:00:58 +00:00
|
|
|
if "django_htcpcp_tea" in INSTALLED_APPS:
|
|
|
|
MIDDLEWARE.append('django_htcpcp_tea.middleware.HTCPCPTeaMiddleware')
|
|
|
|
|
2019-07-07 20:49:02 +00:00
|
|
|
|
|
|
|
ROOT_URLCONF = 'note_kfet.urls'
|
|
|
|
|
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
2020-08-09 17:06:57 +00:00
|
|
|
'DIRS': [os.path.join(BASE_DIR, 'note_kfet/templates')],
|
2019-07-07 20:49:02 +00:00
|
|
|
'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',
|
2019-08-13 16:22:19 +00:00
|
|
|
'django.template.context_processors.request',
|
2019-07-07 20:49:02 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
|
|
|
WSGI_APPLICATION = 'note_kfet.wsgi.application'
|
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
|
|
|
|
# Database
|
|
|
|
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
|
|
|
|
|
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
2020-08-09 16:34:51 +00:00
|
|
|
'ENGINE': os.getenv('DJANGO_DB_ENGINE', 'django.db.backends.postgresql'),
|
|
|
|
'NAME': os.getenv('DJANGO_DB_NAME', 'note_db'),
|
2020-08-09 15:52:19 +00:00
|
|
|
'USER': os.getenv('DJANGO_DB_USER', 'note'),
|
2020-08-09 16:34:51 +00:00
|
|
|
'PASSWORD': os.getenv('DJANGO_DB_PASSWORD', 'CHANGE_ME_IN_ENV_SETTINGS'),
|
2020-08-09 15:52:19 +00:00
|
|
|
'HOST': os.getenv('DJANGO_DB_HOST', 'localhost'),
|
|
|
|
'PORT': os.getenv('DJANGO_DB_PORT', ''), # Use default port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-07 20:49:02 +00:00
|
|
|
# Password validation
|
|
|
|
# https://docs.djangoproject.com/en/2.2/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',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
|
|
|
|
# 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')),
|
2020-09-12 07:17:15 +00:00
|
|
|
('es', _('Spanish')),
|
2020-08-09 15:52:19 +00:00
|
|
|
('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
|
2020-09-01 12:28:11 +00:00
|
|
|
# Because we are using Debian, also include /usr/share/javascript
|
2020-08-09 15:52:19 +00:00
|
|
|
STATICFILES_DIRS = [
|
|
|
|
os.path.join(BASE_DIR, 'note_kfet/static'),
|
2020-09-01 12:28:11 +00:00
|
|
|
'/usr/share/javascript',
|
2020-08-09 15:52:19 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# 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')))
|
|
|
|
|
|
|
|
# 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
|
2020-02-20 09:26:00 +00:00
|
|
|
PASSWORD_HASHERS = [
|
|
|
|
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
|
|
|
'member.hashers.CustomNK15Hasher',
|
|
|
|
]
|
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# Custom role-based permission system
|
2019-07-08 12:22:41 +00:00
|
|
|
AUTHENTICATION_BACKENDS = (
|
2020-08-09 15:52:19 +00:00
|
|
|
'permission.backends.PermissionBackend',
|
2019-07-08 12:22:41 +00:00
|
|
|
)
|
2019-07-07 20:49:02 +00:00
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# Use /media/ for user uploaded media (user profile pictures)
|
|
|
|
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
|
|
|
MEDIA_URL = '/media/'
|
|
|
|
|
2020-08-09 16:34:51 +00:00
|
|
|
# Use mailer in production to place emails in a queue before sending them to avoid spam
|
|
|
|
EMAIL_BACKEND = 'mailer.backend.DbBackend'
|
|
|
|
MAILER_EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
|
|
|
EMAIL_USE_SSL = os.getenv('EMAIL_USE_SSL', False)
|
|
|
|
EMAIL_HOST = os.getenv('EMAIL_HOST', 'smtp.example.org')
|
|
|
|
EMAIL_PORT = os.getenv('EMAIL_PORT', 25)
|
|
|
|
EMAIL_HOST_USER = os.getenv('EMAIL_USER', None)
|
|
|
|
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_PASSWORD', None)
|
|
|
|
|
|
|
|
# Mail will be sent from this address
|
|
|
|
SERVER_EMAIL = os.getenv("NOTE_MAIL", "notekfet@example.com")
|
|
|
|
DEFAULT_FROM_EMAIL = "NoteKfet2020 <" + SERVER_EMAIL + ">"
|
|
|
|
|
2020-09-21 13:13:43 +00:00
|
|
|
# Cache
|
|
|
|
# https://docs.djangoproject.com/en/2.2/topics/cache/#setting-up-the-cache
|
|
|
|
cache_address = os.getenv("CACHE_ADDRESS", "127.0.0.1:11211")
|
|
|
|
CACHES = {
|
|
|
|
'default': {
|
|
|
|
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
|
|
|
|
'LOCATION': cache_address,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# Django REST Framework
|
2020-02-06 22:29:17 +00:00
|
|
|
REST_FRAMEWORK = {
|
|
|
|
'DEFAULT_PERMISSION_CLASSES': [
|
2020-03-20 14:58:14 +00:00
|
|
|
# Control API access with our role-based permission system
|
2020-03-18 13:42:35 +00:00
|
|
|
'permission.permissions.StrongDjangoObjectPermissions',
|
2020-02-17 18:25:33 +00:00
|
|
|
],
|
|
|
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
2020-03-11 09:08:28 +00:00
|
|
|
'rest_framework.authentication.SessionAuthentication',
|
2020-02-17 18:25:33 +00:00
|
|
|
'rest_framework.authentication.TokenAuthentication',
|
2021-03-09 08:44:25 +00:00
|
|
|
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
|
2020-03-11 10:15:03 +00:00
|
|
|
],
|
2022-12-14 17:37:13 +00:00
|
|
|
'DEFAULT_PAGINATION_CLASS': 'apps.api.pagination.CustomPagination',
|
2020-03-11 10:15:03 +00:00
|
|
|
'PAGE_SIZE': 20,
|
2020-02-06 22:29:17 +00:00
|
|
|
}
|
|
|
|
|
2021-06-14 21:30:01 +00:00
|
|
|
# OAuth2 Provider
|
|
|
|
OAUTH2_PROVIDER = {
|
|
|
|
'SCOPES_BACKEND_CLASS': 'permission.scopes.PermissionScopes',
|
2021-12-23 20:59:37 +00:00
|
|
|
'OAUTH2_VALIDATOR_CLASS': "permission.scopes.PermissionOAuth2Validator",
|
2021-12-23 21:00:08 +00:00
|
|
|
'REFRESH_TOKEN_EXPIRE_SECONDS': timedelta(days=14),
|
2021-06-14 21:30:01 +00:00
|
|
|
}
|
|
|
|
|
2024-02-07 17:02:56 +00:00
|
|
|
# PKCE (fix a breaking change of django-oauth-toolkit 2.0.0)
|
|
|
|
PKCE_REQUIRED = False
|
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# Take control on how widget templates are sourced
|
|
|
|
# See https://docs.djangoproject.com/en/2.2/ref/forms/renderers/#templatessetting
|
|
|
|
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
|
2019-07-07 20:49:02 +00:00
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# After login redirect user to transfer page
|
2020-10-07 09:29:52 +00:00
|
|
|
LOGIN_REDIRECT_URL = '/'
|
2019-07-07 20:49:02 +00:00
|
|
|
|
2020-08-09 16:34:51 +00:00
|
|
|
# An user session will expired after 3 hours
|
|
|
|
SESSION_COOKIE_AGE = 60 * 60 * 3
|
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# Use Crispy Bootstrap4 theme
|
2024-02-11 21:24:37 +00:00
|
|
|
CRISPY_ALLOWED_TEMPLATE_PACKS = 'bootstrap4'
|
2020-08-09 15:52:19 +00:00
|
|
|
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
2019-08-14 13:17:14 +00:00
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# Use Django Table2 Bootstrap4 theme
|
|
|
|
DJANGO_TABLES2_TEMPLATE = 'django_tables2/bootstrap4.html'
|
2020-02-20 21:15:28 +00:00
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# Use only one Django Sites
|
|
|
|
SITE_ID = 1
|
2019-07-07 20:49:02 +00:00
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# Default regex to validate users aliases
|
2019-07-23 00:13:09 +00:00
|
|
|
ALIAS_VALIDATOR_REGEX = r''
|
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# Profile picture cropping
|
2020-03-05 22:32:01 +00:00
|
|
|
PIC_WIDTH = 200
|
|
|
|
PIC_RATIO = 1
|
2020-08-05 12:14:51 +00:00
|
|
|
|
2020-08-09 15:52:19 +00:00
|
|
|
# Custom phone number format
|
2020-08-05 12:14:51 +00:00
|
|
|
PHONENUMBER_DB_FORMAT = 'NATIONAL'
|
|
|
|
PHONENUMBER_DEFAULT_REGION = 'FR'
|
2021-03-03 17:42:51 +00:00
|
|
|
|
|
|
|
# We add custom information to CAS, in order to give a normalized name to other services
|
|
|
|
CAS_AUTH_CLASS = 'member.auth.CustomAuthUser'
|
2024-02-11 15:51:48 +00:00
|
|
|
|
|
|
|
# Default field for primary key
|
|
|
|
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|