From 33f78f2850546a544e1ed2e0bc7fa67c6e136489 Mon Sep 17 00:00:00 2001 From: EsGeh Date: Fri, 29 Nov 2019 14:56:05 +0100 Subject: [PATCH] fix paths in base template, allow custom configuration. update README --- README.md | 8 ++++++++ res/custom_config/__init__.py | 0 res/custom_config/custom_config.py | 6 ++++++ src/eoa/context_processors.py | 32 ++++++++++++++++++++++++++++++ src/eoa/settings.py | 3 ++- src/eoa/templates/base.html | 12 +++++------ 6 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 res/custom_config/__init__.py create mode 100644 res/custom_config/custom_config.py create mode 100644 src/eoa/context_processors.py diff --git a/README.md b/README.md index 7cf80b3..32cd2c0 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,14 @@ After you have compiled the publication to "django", you might want to import it That's all. +### Configure Project specific Information + +- You might want to tweak the CMS pages: log in to the CMS and do it +- You might want to configer organisation information (org. name, logo, ...): + + 1. edit `res/custom_config/*` + 2. $ ./scripts/init.py --skip-db + ## Run the Webserver $ ./scripts/run.py diff --git a/res/custom_config/__init__.py b/res/custom_config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/res/custom_config/custom_config.py b/res/custom_config/custom_config.py new file mode 100644 index 0000000..6fdd1ea --- /dev/null +++ b/res/custom_config/custom_config.py @@ -0,0 +1,6 @@ + + +organisation = { + 'name' : "ORGANISATION NAME", + 'homepage' : "#" +} diff --git a/src/eoa/context_processors.py b/src/eoa/context_processors.py new file mode 100644 index 0000000..87e88b3 --- /dev/null +++ b/src/eoa/context_processors.py @@ -0,0 +1,32 @@ +from django.conf import settings # import the settings file + +from os import environ +from pathlib import Path +import sys +from importlib import import_module +import importlib.util + + +def load_module( path, module_name ): + spec = importlib.util.spec_from_file_location( + module_name, + path + ) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module( + module + ) + return module + +def custom_cfg(request): + # return the value you want as a dictionnary. + # The values will be added to the template context + # for all templates: + custom_config = load_module( + Path(environ['RES_DIR']) / "custom_config/custom_config.py", + "custom_config" + ) + + return { + 'organisation': custom_config.organisation + } diff --git a/src/eoa/settings.py b/src/eoa/settings.py index 7e8ad4b..0c8d279 100644 --- a/src/eoa/settings.py +++ b/src/eoa/settings.py @@ -106,7 +106,8 @@ 'django.template.context_processors.tz', 'sekizai.context_processors.sekizai', 'django.template.context_processors.static', - 'cms.context_processors.cms_settings' + 'cms.context_processors.cms_settings', + 'eoa.context_processors.custom_cfg' ], 'loaders': [ 'django.template.loaders.filesystem.Loader', diff --git a/src/eoa/templates/base.html b/src/eoa/templates/base.html index 558110d..a71f7dc 100644 --- a/src/eoa/templates/base.html +++ b/src/eoa/templates/base.html @@ -8,9 +8,9 @@ {% block metatags %}{% endblock metatags %} {% block hyperimage %}{% endblock hyperimage %} - + - + {% render_block "css" %} @@ -23,7 +23,7 @@ @@ -67,13 +67,13 @@ {% block hyperimagebottom %}{% endblock hyperimagebottom %} - + {% render_block "js" %}