From 7d95faa4f559df98504952db4a8a2abacdb2df02 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 25 Oct 2020 21:43:33 +1100 Subject: [PATCH] Cleanup code --- InvenTree/common/models.py | 12 +++++ .../part/templatetags/inventree_extras.py | 46 ------------------- .../templates/InvenTree/settings/setting.html | 8 ++-- 3 files changed, 16 insertions(+), 50 deletions(-) diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 0e778610cb..3150dad2a4 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -273,6 +273,18 @@ class InvenTreeSetting(models.Model): value = models.CharField(max_length=200, blank=True, unique=False, help_text=_('Settings value')) + @property + def name(self): + return InvenTreeSetting.get_setting_name(self.key) + + @property + def description(self): + return InvenTreeSetting.get_setting_description(self.key) + + @property + def units(self): + return InvenTreeSetting.get_setting_units(self.key) + def clean(self): """ If a validator (or multiple validators) are defined for a particular setting key, diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 9be02b8273..982f38f38f 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -102,54 +102,8 @@ def setting_object(key, *args, **kwargs): setting = InvenTreeSetting.get_setting_object(key) - print("Setting:", key, setting) - return setting -@register.simple_tag() -def settings_name(key, *args, **kwargs): - """ - Returns the name of a GLOBAL_SETTINGS object - """ - - return InvenTreeSetting.get_setting_name(key) - - -@register.simple_tag() -def settings_description(key, *args, **kwargs): - """ - Returns the description of a GLOBAL_SETTINGS object - """ - - return InvenTreeSetting.get_setting_description(key) - - -@register.simple_tag() -def settings_units(key, *args, **kwargs): - """ - Return the units of a GLOBAL_SETTINGS object - """ - - return InvenTreeSetting.get_setting_units(key) - - -@register.simple_tag() -def settings_value(key, *args, **kwargs): - """ - Returns the value of a GLOBAL_SETTINGS object - """ - - return InvenTreeSetting.get_setting(key, backup_value=kwargs.get('backup', None)) - - -@register.simple_tag() -def settings_pk(key, *args, **kwargs): - """ - Return the ID (pk) of a GLOBAL_SETTINGS Object - """ - - return InvenTreeSetting.get_setting_pk(key) - @register.simple_tag() def get_color_theme_css(username): diff --git a/InvenTree/templates/InvenTree/settings/setting.html b/InvenTree/templates/InvenTree/settings/setting.html index 0a75b15cdd..ffbb78cbbc 100644 --- a/InvenTree/templates/InvenTree/settings/setting.html +++ b/InvenTree/templates/InvenTree/settings/setting.html @@ -3,7 +3,7 @@ {% setting_object key as setting %} - {% settings_name key %} + {{ setting.name }} {% if setting.is_bool %}
@@ -11,17 +11,17 @@
{% else %} {% if setting.value %} - {% settings_value key %}{% settings_units key %} + {{ setting.value }}{{ setting.units }} {% else %} {% trans "No value set" %} {% endif %} {% endif %} - {% settings_description key %} + {{ setting.description }}
-