From 1bce7b745e91c41d92c88bf11b8fcce60358401f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 24 Apr 2022 16:13:44 +0200 Subject: [PATCH] add custom logo option --- InvenTree/InvenTree/settings.py | 11 +++++++++++ InvenTree/part/templatetags/inventree_extras.py | 12 +++++++++++- InvenTree/templates/503.html | 2 +- InvenTree/templates/account/base.html | 2 +- InvenTree/templates/navbar.html | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 1414be7fd9..ec2cc3f8ea 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -25,6 +25,7 @@ import moneyed import yaml from django.utils.translation import gettext_lazy as _ from django.contrib.messages import constants as messages +from django.core.files.storage import default_storage import django.conf.locale from .config import get_base_dir, get_config_file, get_plugin_file, get_setting @@ -920,3 +921,13 @@ CUSTOMIZE = get_setting( {} ) +CUSTOM_LOGO = get_setting( + 'INVENTREE_LOGO', + CONFIG.get('logo', False), + False +) + +# check that the logo-file exsists in media +if CUSTOM_LOGO and not default_storage.exists(CUSTOM_LOGO): + CUSTOM_LOGO = False + logger.warning("The custom logo file could not be found in the default media storage") diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index ad23487a83..aa8de13082 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -18,7 +18,8 @@ from django.conf import settings as djangosettings from django import template from django.urls import reverse from django.utils.safestring import mark_safe -from django.templatetags.static import StaticNode +from django.templatetags.static import StaticNode, static +from django.core.files.storage import default_storage from InvenTree import version, settings @@ -529,6 +530,15 @@ def inventree_customize(reference, *args, **kwargs): return djangosettings.CUSTOMIZE.get(reference, '') +@register.simple_tag() +def inventree_logo(*args, **kwargs): + """ Return the path to the logo-file """ + + if settings.CUSTOM_LOGO: + return default_storage.url(settings.CUSTOM_LOGO) + return static('img/inventree.png') + + class I18nStaticNode(StaticNode): """ custom StaticNode diff --git a/InvenTree/templates/503.html b/InvenTree/templates/503.html index fbee60c694..7b5b25d611 100644 --- a/InvenTree/templates/503.html +++ b/InvenTree/templates/503.html @@ -30,7 +30,7 @@
diff --git a/InvenTree/templates/account/base.html b/InvenTree/templates/account/base.html index 06c9485fb5..9a68f7ba31 100644 --- a/InvenTree/templates/account/base.html +++ b/InvenTree/templates/account/base.html @@ -67,7 +67,7 @@
diff --git a/InvenTree/templates/navbar.html b/InvenTree/templates/navbar.html index 9a0d87fb4d..6c7498c3a3 100644 --- a/InvenTree/templates/navbar.html +++ b/InvenTree/templates/navbar.html @@ -14,7 +14,7 @@