2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 21:15:41 +00:00

Add 'settings.js' which provides all settings (global and user) as a dynamic javascript file

- Minimal database hits required
This commit is contained in:
Oliver
2021-07-29 11:28:04 +10:00
parent 915756eacf
commit 27ec65a002
5 changed files with 80 additions and 3 deletions

View File

@ -38,6 +38,45 @@ class BaseInvenTreeSetting(models.Model):
class Meta:
abstract = True
@classmethod
def allValues(cls, user=None):
"""
Return a dict of "all" defined global settings.
This performs a single database lookup,
and then any settings which are not *in* the database
are assigned their default values
"""
keys = set()
settings = []
results = cls.objects.all()
if user is not None:
results = results.filter(user=user)
# Query the database
for setting in results:
settings.append({
"key": setting.key.upper(),
"value": setting.value
})
keys.add(setting.key.upper())
# Specify any "default" values which are not in the database
for key in cls.GLOBAL_SETTINGS.keys():
if key.upper() not in keys:
settings.append({
"key": key.upper(),
"value": cls.get_setting_default(key)
})
return settings
@classmethod
def get_setting_name(cls, key):
"""
@ -739,7 +778,6 @@ class InvenTreeSetting(BaseInvenTreeSetting):
help_text=_('Settings key (must be unique - case insensitive'),
)
class InvenTreeUserSetting(BaseInvenTreeSetting):
"""
An InvenTreeSetting object with a usercontext