mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Adds API endpoints for viewing and updating plugin settings
A lot of code updates / refactoring here to get this to work as expected
This commit is contained in:
@ -71,7 +71,7 @@ class BaseInvenTreeSetting(models.Model):
|
||||
super().save()
|
||||
|
||||
@classmethod
|
||||
def allValues(cls, user=None, plugin=None, exclude_hidden=False):
|
||||
def allValues(cls, user=None, exclude_hidden=False):
|
||||
"""
|
||||
Return a dict of "all" defined global settings.
|
||||
|
||||
@ -86,10 +86,6 @@ class BaseInvenTreeSetting(models.Model):
|
||||
if user is not None:
|
||||
results = results.filter(user=user)
|
||||
|
||||
# Optionally filter by plugin
|
||||
if plugin is not None:
|
||||
results = results.filter(plugin=plugin)
|
||||
|
||||
# Query the database
|
||||
settings = {}
|
||||
|
||||
@ -238,16 +234,12 @@ class BaseInvenTreeSetting(models.Model):
|
||||
|
||||
settings = cls.objects.all()
|
||||
|
||||
# Filter by user
|
||||
user = kwargs.get('user', None)
|
||||
|
||||
if user is not None:
|
||||
settings = settings.filter(user=user)
|
||||
|
||||
plugin = kwargs.get('plugin', None)
|
||||
|
||||
if plugin is not None:
|
||||
settings = settings.filter(plugin=plugin)
|
||||
|
||||
try:
|
||||
setting = settings.filter(**cls.get_filters(key, **kwargs)).first()
|
||||
except (ValueError, cls.DoesNotExist):
|
||||
@ -255,6 +247,16 @@ class BaseInvenTreeSetting(models.Model):
|
||||
except (IntegrityError, OperationalError):
|
||||
setting = None
|
||||
|
||||
plugin = kwargs.pop('plugin', None)
|
||||
|
||||
if plugin:
|
||||
from plugin import InvenTreePlugin
|
||||
|
||||
if issubclass(plugin.__class__, InvenTreePlugin):
|
||||
plugin = plugin.plugin_config()
|
||||
|
||||
kwargs['plugin'] = plugin
|
||||
|
||||
# Setting does not exist! (Try to create it)
|
||||
if not setting:
|
||||
|
||||
@ -554,7 +556,9 @@ class BaseInvenTreeSetting(models.Model):
|
||||
|
||||
|
||||
def settings_group_options():
|
||||
"""build up group tuple for settings based on gour choices"""
|
||||
"""
|
||||
Build up group tuple for settings based on your choices
|
||||
"""
|
||||
return [('', _('No group')), *[(str(a.id), str(a)) for a in Group.objects.all()]]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user