Fix rendering issues

This commit is contained in:
Oliver 2021-07-29 11:43:50 +10:00
parent 27ec65a002
commit a222efda33
3 changed files with 44 additions and 9 deletions

View File

@ -75,6 +75,28 @@ class BaseInvenTreeSetting(models.Model):
"value": cls.get_setting_default(key) "value": cls.get_setting_default(key)
}) })
# Enforce javascript formatting
for idx, setting in enumerate(settings):
key = setting['key']
value = setting['value']
validator = cls.get_setting_validator(key)
# Convert to javascript compatible booleans
if cls.validator_is_bool(validator):
value = 'true' if value else 'false'
# Numerical values remain the same
elif cls.validator_is_int(validator):
pass
# Wrap strings with quotes
else:
value = f"'{value}'"
setting["value"] = value
return settings return settings
@classmethod @classmethod
@ -407,13 +429,7 @@ class BaseInvenTreeSetting(models.Model):
validator = self.__class__.get_setting_validator(self.key) validator = self.__class__.get_setting_validator(self.key)
if validator == bool: return self.__class__.validator_is_bool(validator)
return True
if type(validator) in [list, tuple]:
for v in validator:
if v == bool:
return True
def as_bool(self): def as_bool(self):
""" """
@ -424,6 +440,19 @@ class BaseInvenTreeSetting(models.Model):
return InvenTree.helpers.str2bool(self.value) return InvenTree.helpers.str2bool(self.value)
@classmethod
def validator_is_bool(cls, validator):
if validator == bool:
return True
if type(validator) in [list, tuple]:
for v in validator:
if v == bool:
return True
return False
def is_int(self): def is_int(self):
""" """
Check if the setting is required to be an integer value: Check if the setting is required to be an integer value:
@ -431,6 +460,11 @@ class BaseInvenTreeSetting(models.Model):
validator = self.__class__.get_setting_validator(self.key) validator = self.__class__.get_setting_validator(self.key)
return self.__class__.validator_is_int(validator)
@classmethod
def validator_is_int(cls, validator):
if validator == int: if validator == int:
return True return True

View File

@ -6,12 +6,12 @@
var user_settings = { var user_settings = {
{% for setting in USER_SETTINGS %} {% for setting in USER_SETTINGS %}
{{ setting.key }}: {{ setting.value }}, {{ setting.key }}: {{ setting.value|safe }},
{% endfor %} {% endfor %}
}; };
var global_settings = { var global_settings = {
{% for setting in GLOBAL_SETTINGS %} {% for setting in GLOBAL_SETTINGS %}
{{ setting.key }}: {{ setting.value }}, {{ setting.key }}: {{ setting.value|safe }},
{% endfor %} {% endfor %}
}; };

View File

@ -147,6 +147,7 @@ function getAvailableTableFilters(tableKey) {
title: '{% trans "Depleted" %}', title: '{% trans "Depleted" %}',
description: '{% trans "Show stock items which are depleted" %}', description: '{% trans "Show stock items which are depleted" %}',
}, },
{% settings_value "STOCK_ENABLE_EXPIRY" as expiry %} {% settings_value "STOCK_ENABLE_EXPIRY" as expiry %}
{% if expiry %} {% if expiry %}
expired: { expired: {