From d8e3cd656663d1338c8077fdbabf3317fdeebf6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 9 May 2020 15:48:51 +0200 Subject: [PATCH] Split settings between COF / BDS / Local --- cof/settings/{prod.py => bds_prod.py} | 19 +-- cof/settings/cof_prod.py | 162 ++++++++++++++++++++++++++ cof/settings/common.py | 151 ++++++------------------ cof/settings/local.py | 33 ++++-- 4 files changed, 229 insertions(+), 136 deletions(-) rename cof/settings/{prod.py => bds_prod.py} (55%) create mode 100644 cof/settings/cof_prod.py diff --git a/cof/settings/prod.py b/cof/settings/bds_prod.py similarity index 55% rename from cof/settings/prod.py rename to cof/settings/bds_prod.py index 748abe73..d674a0a6 100644 --- a/cof/settings/prod.py +++ b/cof/settings/bds_prod.py @@ -6,14 +6,15 @@ The settings that are not listed here are imported from .common import os from .common import * # NOQA -from .common import BASE_DIR, INSTALLED_APPS, TESTING, import_secret +from .common import BASE_DIR, INSTALLED_APPS -DEBUG = False +# --- +# BDS-only Django settings +# --- -ALLOWED_HOSTS = ["cof.ens.fr", "www.cof.ens.fr", "dev.cof.ens.fr"] +ALLOWED_HOSTS = ["bds.ens.fr", "www.bds.ens.fr", "dev.cof.ens.fr"] -if TESTING: - INSTALLED_APPS += ["events", "clubs"] +INSTALLED_APPS += ["bds", "events", "clubs"] STATIC_ROOT = os.path.join( os.path.dirname(os.path.dirname(BASE_DIR)), "public", "gestion", "static" @@ -24,5 +25,9 @@ MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media") MEDIA_URL = "/gestion/media/" -RECAPTCHA_PUBLIC_KEY = import_secret("RECAPTCHA_PUBLIC_KEY") -RECAPTCHA_PRIVATE_KEY = import_secret("RECAPTCHA_PRIVATE_KEY") +# --- +# Auth-related stuff +# --- + +LOGIN_URL = "admin:login" +LOGIN_REDIRECT_URL = "bds:home" diff --git a/cof/settings/cof_prod.py b/cof/settings/cof_prod.py new file mode 100644 index 00000000..fe60af24 --- /dev/null +++ b/cof/settings/cof_prod.py @@ -0,0 +1,162 @@ +""" +Django development settings for the cof project. +The settings that are not listed here are imported from .common +""" + +import os + +from .common import * # NOQA +from .common import ( + AUTHENTICATION_BACKENDS, + BASE_DIR, + INSTALLED_APPS, + MIDDLEWARE, + TEMPLATES, + import_secret, +) + +# --- +# COF-specific secrets +# --- + +RECAPTCHA_PUBLIC_KEY = import_secret("RECAPTCHA_PUBLIC_KEY") +RECAPTCHA_PRIVATE_KEY = import_secret("RECAPTCHA_PRIVATE_KEY") +KFETOPEN_TOKEN = import_secret("KFETOPEN_TOKEN") + +# --- +# COF-only Django settings +# --- + +ALLOWED_HOSTS = ["cof.ens.fr", "www.cof.ens.fr", "dev.cof.ens.fr"] + +INSTALLED_APPS = ( + [ + "gestioncof", + # Must be before django admin + # https://github.com/infoportugal/wagtail-modeltranslation/issues/193 + "wagtail_modeltranslation", + "wagtail_modeltranslation.makemigrations", + "wagtail_modeltranslation.migrate", + "modeltranslation", + ] + + INSTALLED_APPS + + [ + "bda", + "petitscours", + "captcha", + "kfet", + "kfet.open", + "channels", + "custommail", + "djconfig", + "wagtail.contrib.forms", + "wagtail.contrib.redirects", + "wagtail.embeds", + "wagtail.sites", + "wagtail.users", + "wagtail.snippets", + "wagtail.documents", + "wagtail.images", + "wagtail.search", + "wagtail.admin", + "wagtail.core", + "wagtail.contrib.modeladmin", + "wagtail.contrib.routable_page", + "wagtailmenus", + "modelcluster", + "taggit", + "kfet.auth", + "kfet.cms", + "gestioncof.cms", + "django_js_reverse", + ] +) + +MIDDLEWARE = ( + ["corsheaders.middleware.CorsMiddleware"] + + MIDDLEWARE + + [ + "djconfig.middleware.DjConfigMiddleware", + "wagtail.core.middleware.SiteMiddleware", + "wagtail.contrib.redirects.middleware.RedirectMiddleware", + ] +) + +TEMPLATES[0]["OPTIONS"]["context_processors"] += [ + "wagtailmenus.context_processors.wagtailmenus", + "djconfig.context_processors.config", + "gestioncof.shared.context_processor", + "kfet.auth.context_processors.temporary_auth", + "kfet.context_processors.config", +] + +STATIC_ROOT = os.path.join( + os.path.dirname(os.path.dirname(BASE_DIR)), "public", "gestion", "static" +) + +STATIC_URL = "/gestion/static/" +MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media") +MEDIA_URL = "/gestion/media/" + +CORS_ORIGIN_WHITELIST = ("bda.ens.fr", "www.bda.ens.fr" "cof.ens.fr", "www.cof.ens.fr") + + +# --- +# Auth-related stuff +# --- + +AUTHENTICATION_BACKENDS += [ + "gestioncof.shared.COFCASBackend", + "kfet.auth.backends.GenericBackend", +] + +LOGIN_URL = "cof-login" +LOGIN_REDIRECT_URL = "home" + + +# --- +# reCAPTCHA settings +# https://github.com/praekelt/django-recaptcha +# +# Default settings authorize reCAPTCHA usage for local developement. +# Public and private keys are appended in the 'prod' module settings. +# --- + +NOCAPTCHA = True +RECAPTCHA_USE_SSL = True + + +# --- +# Wagtail settings +# --- + +WAGTAIL_SITE_NAME = "GestioCOF" +WAGTAIL_ENABLE_UPDATE_CHECK = False +TAGGIT_CASE_INSENSITIVE = True + + +# --- +# Django-js-reverse settings +# --- + +JS_REVERSE_JS_VAR_NAME = "django_urls" +# Quand on aura namespace les urls... +# JS_REVERSE_INCLUDE_ONLY_NAMESPACES = ['k-fet'] + + +# --- +# Mail config +# --- + +MAIL_DATA = { + "petits_cours": { + "FROM": "Le COF ", + "BCC": "archivescof@gmail.com", + "REPLYTO": "cof@ens.fr", + }, + "rappels": {"FROM": "Le BdA ", "REPLYTO": "Le BdA "}, + "revente": { + "FROM": "BdA-Revente ", + "REPLYTO": "BdA-Revente ", + }, +} diff --git a/cof/settings/common.py b/cof/settings/common.py index ecf464fe..0c34bf67 100644 --- a/cof/settings/common.py +++ b/cof/settings/common.py @@ -8,6 +8,10 @@ the local development server should be here. import os import sys +# --- +# Secrets +# --- + try: from . import secret except ImportError: @@ -42,19 +46,19 @@ REDIS_DB = import_secret("REDIS_DB") REDIS_HOST = import_secret("REDIS_HOST") REDIS_PORT = import_secret("REDIS_PORT") -KFETOPEN_TOKEN = import_secret("KFETOPEN_TOKEN") LDAP_SERVER_URL = import_secret("LDAP_SERVER_URL") +# --- +# Default Django settings +# --- + +DEBUG = False # False by default feels safer +TESTING = len(sys.argv) > 1 and sys.argv[1] == "test" BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -TESTING = sys.argv[1] == "test" - - -# Application definition INSTALLED_APPS = [ "shared", - "gestioncof", # Must be before 'django.contrib.admin'. # https://django-autocomplete-light.readthedocs.io/en/master/install.html "dal", @@ -64,51 +68,15 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.sites", "django.contrib.messages", - "cof.apps.IgnoreSrcStaticFilesConfig", - # Must be before django admin - # https://github.com/infoportugal/wagtail-modeltranslation/issues/193 - "wagtail_modeltranslation", - "wagtail_modeltranslation.makemigrations", - "wagtail_modeltranslation.migrate", - "modeltranslation", "django.contrib.admin", "django.contrib.admindocs", - "bda", - "petitscours", - "captcha", + "cof.apps.IgnoreSrcStaticFilesConfig", "django_cas_ng", "bootstrapform", - "kfet", - "kfet.open", - "channels", "widget_tweaks", - "custommail", - "djconfig", - "wagtail.contrib.forms", - "wagtail.contrib.redirects", - "wagtail.embeds", - "wagtail.sites", - "wagtail.users", - "wagtail.snippets", - "wagtail.documents", - "wagtail.images", - "wagtail.search", - "wagtail.admin", - "wagtail.core", - "wagtail.contrib.modeladmin", - "wagtail.contrib.routable_page", - "wagtailmenus", - "modelcluster", - "taggit", - "kfet.auth", - "kfet.cms", - "gestioncof.cms", - "django_js_reverse", ] - MIDDLEWARE = [ - "corsheaders.middleware.CorsMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", @@ -116,9 +84,6 @@ MIDDLEWARE = [ "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "django.middleware.security.SecurityMiddleware", - "djconfig.middleware.DjConfigMiddleware", - "wagtail.core.middleware.SiteMiddleware", - "wagtail.contrib.redirects.middleware.RedirectMiddleware", "django.middleware.locale.LocaleMiddleware", ] @@ -127,7 +92,6 @@ ROOT_URLCONF = "cof.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], "APP_DIRS": True, "OPTIONS": { "context_processors": [ @@ -138,11 +102,6 @@ TEMPLATES = [ "django.template.context_processors.i18n", "django.template.context_processors.media", "django.template.context_processors.static", - "wagtailmenus.context_processors.wagtailmenus", - "djconfig.context_processors.config", - "gestioncof.shared.context_processor", - "kfet.auth.context_processors.temporary_auth", - "kfet.context_processors.config", ] }, } @@ -158,43 +117,28 @@ DATABASES = { } } - -# Internationalization -# https://docs.djangoproject.com/en/1.8/topics/i18n/ - -LANGUAGE_CODE = "fr-fr" - -TIME_ZONE = "Europe/Paris" - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - -LANGUAGES = (("fr", "Français"), ("en", "English")) - -# Various additional settings SITE_ID = 1 -GRAPPELLI_ADMIN_HEADLINE = "GestioCOF" -GRAPPELLI_ADMIN_TITLE = 'GestioCOF' -MAIL_DATA = { - "petits_cours": { - "FROM": "Le COF ", - "BCC": "archivescof@gmail.com", - "REPLYTO": "cof@ens.fr", - }, - "rappels": {"FROM": "Le BdA ", "REPLYTO": "Le BdA "}, - "revente": { - "FROM": "BdA-Revente ", - "REPLYTO": "BdA-Revente ", - }, -} +# --- +# Internationalization +# https://docs.djangoproject.com/en/1.8/topics/i18n/ +# --- -LOGIN_URL = "cof-login" -LOGIN_REDIRECT_URL = "home" +LANGUAGE_CODE = "fr-fr" +TIME_ZONE = "Europe/Paris" +USE_I18N = True +USE_L10N = True +USE_TZ = True +LANGUAGES = (("fr", "Français"), ("en", "English")) +FORMAT_MODULE_PATH = "cof.locale" + + +# --- +# Auth-related stuff +# --- + +AUTHENTICATION_BACKENDS = ["django.contrib.auth.backends.ModelBackend"] CAS_SERVER_URL = "https://cas.eleves.ens.fr/" CAS_VERSION = "2" @@ -203,37 +147,23 @@ CAS_IGNORE_REFERER = True CAS_REDIRECT_URL = "/" CAS_EMAIL_FORMAT = "%s@clipper.ens.fr" -AUTHENTICATION_BACKENDS = ( - "django.contrib.auth.backends.ModelBackend", - "gestioncof.shared.COFCASBackend", - "kfet.auth.backends.GenericBackend", -) - - -# reCAPTCHA settings -# https://github.com/praekelt/django-recaptcha -# -# Default settings authorize reCAPTCHA usage for local developement. -# Public and private keys are appended in the 'prod' module settings. - -NOCAPTCHA = True -RECAPTCHA_USE_SSL = True - -CORS_ORIGIN_WHITELIST = ("bda.ens.fr", "www.bda.ens.fr" "cof.ens.fr", "www.cof.ens.fr") - +# --- # Cache settings +# --- CACHES = { "default": { "BACKEND": "redis_cache.RedisCache", - "LOCATION": "redis://:{passwd}@{host}:{port}/db".format( + "LOCATION": "redis://:{passwd}@{host}:{port}/{db}".format( passwd=REDIS_PASSWD, host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB ), } } +# --- # Channels settings +# --- CHANNEL_LAYERS = { "default": { @@ -253,16 +183,3 @@ CHANNEL_LAYERS = { "ROUTING": "cof.routing.routing", } } - -FORMAT_MODULE_PATH = "cof.locale" - -# Wagtail settings - -WAGTAIL_SITE_NAME = "GestioCOF" -WAGTAIL_ENABLE_UPDATE_CHECK = False -TAGGIT_CASE_INSENSITIVE = True - -# Django-js-reverse settings -JS_REVERSE_JS_VAR_NAME = "django_urls" -# Quand on aura namespace les urls... -# JS_REVERSE_INCLUDE_ONLY_NAMESPACES = ['k-fet'] diff --git a/cof/settings/local.py b/cof/settings/local.py index 789ec12b..0ccb05dd 100644 --- a/cof/settings/local.py +++ b/cof/settings/local.py @@ -1,26 +1,35 @@ -""" -Django local development settings for the cof project. -The settings that are not listed here are imported from .common -""" +"""Django local development settings.""" import os -from .common import * # NOQA -from .common import BASE_DIR, INSTALLED_APPS, MIDDLEWARE, TESTING +from . import bds_prod +from .cof_prod import * # NOQA +from .cof_prod import BASE_DIR, INSTALLED_APPS, MIDDLEWARE, TESTING -EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" +# --- +# Merge COF and BDS configs +# --- + +for app in bds_prod.INSTALLED_APPS: + if app not in INSTALLED_APPS: + INSTALLED_APPS.append(app) + + +# --- +# Tweaks for debug/local development +# --- + +ALLOWED_HOSTS = None DEBUG = True +EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" if TESTING: PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"] -# As long as these apps are not ready for production, they are only available -# in development mode -INSTALLED_APPS += ["events", "bds", "clubs"] - STATIC_URL = "/static/" -MEDIA_URL = os.path.join(BASE_DIR, "media") +MEDIA_URL = "/media/" +MEDIA_ROOT = os.path.join(BASE_DIR, "media") DATABASES = { "default": {