Cleanup code

This commit is contained in:
Oliver Walters 2020-10-25 21:43:33 +11:00
parent 432ecc1d96
commit 7d95faa4f5
3 changed files with 16 additions and 50 deletions

View File

@ -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,

View File

@ -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):

View File

@ -3,7 +3,7 @@
{% setting_object key as setting %}
<tr>
<td><b>{% settings_name key %}</b></td>
<td><b>{{ setting.name }}</b></td>
<td>
{% if setting.is_bool %}
<div>
@ -11,17 +11,17 @@
</div>
{% else %}
{% if setting.value %}
<b>{% settings_value key %}</b>{% settings_units key %}</td>
<b>{{ setting.value }}</b>{{ setting.units }}</td>
{% else %}
<i>{% trans "No value set" %}</i>
{% endif %}
{% endif %}
<td>
{% settings_description key %}
{{ setting.description }}
</td>
<td>
<div class='btn-group float-right'>
<button class='btn btn-default btn-glyph btn-edit-setting' pk='{% settings_pk key %}' setting='{{ key }}' title='{% trans "Edit setting" %}'>
<button class='btn btn-default btn-glyph btn-edit-setting' pk='{{ setting.pk }}' setting='{{ key }}' title='{% trans "Edit setting" %}'>
<span class='fas fa-edit icon-green'></span>
</button>
</div>