From a128ed480339d5c9c2541535a86a60a1b48a87a7 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 11 Mar 2020 13:24:48 +0100 Subject: [PATCH] Use environment rather than hardcoding strings, closes #36 --- README.md | 8 ++++++-- apps/note/templatetags/__init__.py | 12 ++++++++++++ apps/note/templatetags/getenv.py | 8 ++++++++ apps/note/templatetags/pretty_money.py | 6 ------ note_kfet/settings/__init__.py | 2 ++ note_kfet/settings/development.py | 2 +- note_kfet/settings/production.py | 6 ++++-- templates/base.html | 4 ++-- 8 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 apps/note/templatetags/getenv.py diff --git a/README.md b/README.md index 14ec5f42..c53ee38d 100644 --- a/README.md +++ b/README.md @@ -133,10 +133,14 @@ Il est possible de travailler sur une instance Docker. build: /chemin/vers/nk20 volumes: - /chemin/vers/nk20:/code/ + environment: + MAILING_LIST_DOMAIN: lists.example.com + NOTE_URL: nk20.example.com + DOMAIN: example.com restart: always labels: - - traefik.domain=ndd.exemple.com - - traefik.frontend.rule=Host:ndd.exemple.com + - traefik.domain=ndd.example.com + - traefik.frontend.rule=Host:ndd.example.com - traefik.port=8000 3. Enjoy : diff --git a/apps/note/templatetags/__init__.py b/apps/note/templatetags/__init__.py index e69de29b..19b8e45b 100644 --- a/apps/note/templatetags/__init__.py +++ b/apps/note/templatetags/__init__.py @@ -0,0 +1,12 @@ +# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay +# SPDX-License-Identifier: GPL-3.0-or-later + +from django import template + +from .getenv import getenv +from .pretty_money import pretty_money + +register = template.Library() + +register.filter('getenv', getenv) +register.filter('pretty_money', pretty_money) diff --git a/apps/note/templatetags/getenv.py b/apps/note/templatetags/getenv.py new file mode 100644 index 00000000..7710a389 --- /dev/null +++ b/apps/note/templatetags/getenv.py @@ -0,0 +1,8 @@ +# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay +# SPDX-License-Identifier: GPL-3.0-or-later + +import os + + +def getenv(value): + return os.getenv(value) diff --git a/apps/note/templatetags/pretty_money.py b/apps/note/templatetags/pretty_money.py index 12530c6e..5db2a1c0 100644 --- a/apps/note/templatetags/pretty_money.py +++ b/apps/note/templatetags/pretty_money.py @@ -1,8 +1,6 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later -from django import template - def pretty_money(value): if value % 100 == 0: @@ -16,7 +14,3 @@ def pretty_money(value): abs(value) // 100, abs(value) % 100, ) - - -register = template.Library() -register.filter('pretty_money', pretty_money) diff --git a/note_kfet/settings/__init__.py b/note_kfet/settings/__init__.py index ce31b39f..10b21970 100644 --- a/note_kfet/settings/__init__.py +++ b/note_kfet/settings/__init__.py @@ -51,12 +51,14 @@ except ImportError: if "cas" in INSTALLED_APPS: MIDDLEWARE += ['cas.middleware.CASMiddleware'] # CAS Settings + CAS_SERVER_URL = "https://" + os.getenv("NOTE_URL") + "/cas/" CAS_AUTO_CREATE_USER = False CAS_LOGO_URL = "/static/img/Saperlistpopette.png" CAS_FAVICON_URL = "/static/favicon/favicon-32x32.png" CAS_SHOW_SERVICE_MESSAGES = True CAS_SHOW_POWERED = False CAS_REDIRECT_TO_LOGIN_AFTER_LOGOUT = False + CAS_PROVIDE_URL_TO_LOGOUT = True CAS_INFO_MESSAGES = { "cas_explained": { "message": _( diff --git a/note_kfet/settings/development.py b/note_kfet/settings/development.py index cf738f33..61f6d530 100644 --- a/note_kfet/settings/development.py +++ b/note_kfet/settings/development.py @@ -39,7 +39,7 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # EMAIL_HOST_USER = 'change_me' # EMAIL_HOST_PASSWORD = 'change_me' -SERVER_EMAIL = 'no-reply@example.org' +SERVER_EMAIL = 'no-reply@' + os.getenv("DOMAIN") # Security settings SECURE_CONTENT_TYPE_NOSNIFF = False diff --git a/note_kfet/settings/production.py b/note_kfet/settings/production.py index 4512dc85..ea1e9739 100644 --- a/note_kfet/settings/production.py +++ b/note_kfet/settings/production.py @@ -1,6 +1,8 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later +import os + ######################## # Production Settings # ######################## @@ -37,7 +39,7 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # EMAIL_HOST_USER = 'change_me' # EMAIL_HOST_PASSWORD = 'change_me' -SERVER_EMAIL = 'no-reply@example.org' +SERVER_EMAIL = 'no-reply@' + os.getenv("DOMAIN") # Security settings SECURE_CONTENT_TYPE_NOSNIFF = False @@ -49,4 +51,4 @@ X_FRAME_OPTIONS = 'DENY' SESSION_COOKIE_AGE = 60 * 60 * 3 # CAS Client settings -CAS_SERVER_URL = "https://note.crans.org/cas/" +CAS_SERVER_URL = "https://" + os.getenv("NOTE_URL") + "/cas/" diff --git a/templates/base.html b/templates/base.html index 94810b87..57c741d0 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,4 +1,4 @@ -{% load static i18n pretty_money static %} +{% load static i18n pretty_money static getenv %} {% comment %} SPDX-License-Identifier: GPL-3.0-or-later {% endcomment %} @@ -128,7 +128,7 @@ SPDX-License-Identifier: GPL-3.0-or-later class="form-inline"> NoteKfet2020 — - Nous contacter {% csrf_token %}