mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Remove old "get_filters" function
- It was confusing! - Manually filter where required
This commit is contained in:
parent
63b5b95610
commit
5ee9af7f0e
@ -230,10 +230,6 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
|
|
||||||
return choices
|
return choices
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_filters(cls, key, **kwargs):
|
|
||||||
return {'key__iexact': key}
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_setting_object(cls, key, **kwargs):
|
def get_setting_object(cls, key, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -247,26 +243,30 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
|
|
||||||
settings = cls.objects.all()
|
settings = cls.objects.all()
|
||||||
|
|
||||||
|
filters = {
|
||||||
|
'key__iexact': key,
|
||||||
|
}
|
||||||
|
|
||||||
# Filter by user
|
# Filter by user
|
||||||
user = kwargs.get('user', None)
|
user = kwargs.get('user', None)
|
||||||
|
|
||||||
if user is not None:
|
if user is not None:
|
||||||
settings = settings.filter(user=user)
|
filters['user'] = user
|
||||||
|
|
||||||
plugin = kwargs.pop('plugin', None)
|
# Filter by plugin
|
||||||
|
plugin = kwargs.get('plugin', None)
|
||||||
|
|
||||||
if plugin:
|
if plugin is not None:
|
||||||
from plugin import InvenTreePluginBase
|
from plugin import InvenTreePluginBase
|
||||||
|
|
||||||
if issubclass(plugin.__class__, InvenTreePluginBase):
|
if issubclass(plugin.__class__, InvenTreePluginBase):
|
||||||
plugin = plugin.plugin_config()
|
plugin = plugin.plugin_config()
|
||||||
|
|
||||||
|
filters['plugin'] = plugin
|
||||||
kwargs['plugin'] = plugin
|
kwargs['plugin'] = plugin
|
||||||
|
|
||||||
settings = settings.filter(plugin=plugin)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
setting = settings.filter(**cls.get_filters(key, **kwargs)).first()
|
setting = settings.filter(**filters).first()
|
||||||
except (ValueError, cls.DoesNotExist):
|
except (ValueError, cls.DoesNotExist):
|
||||||
setting = None
|
setting = None
|
||||||
except (IntegrityError, OperationalError):
|
except (IntegrityError, OperationalError):
|
||||||
@ -344,8 +344,26 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
if change_user is not None and not change_user.is_staff:
|
if change_user is not None and not change_user.is_staff:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
filters = {
|
||||||
|
'key__iexact': key,
|
||||||
|
}
|
||||||
|
|
||||||
|
user = kwargs.get('user', None)
|
||||||
|
plugin = kwargs.get('plugin', None)
|
||||||
|
|
||||||
|
if user is not None:
|
||||||
|
filters['user'] = user
|
||||||
|
|
||||||
|
if plugin is not None:
|
||||||
|
from plugin import InvenTreePluginBase
|
||||||
|
|
||||||
|
if issubclass(plugin.__class__, InvenTreePluginBase):
|
||||||
|
filters['plugin'] = plugin.plugin_config()
|
||||||
|
else:
|
||||||
|
filters['plugin'] = plugin
|
||||||
|
|
||||||
try:
|
try:
|
||||||
setting = cls.objects.get(**cls.get_filters(key, **kwargs))
|
setting = cls.objects.get(**filters)
|
||||||
except cls.DoesNotExist:
|
except cls.DoesNotExist:
|
||||||
|
|
||||||
if create:
|
if create:
|
||||||
@ -452,7 +470,7 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
super().validate_unique(exclude)
|
super().validate_unique(exclude)
|
||||||
|
|
||||||
filters = {
|
filters = {
|
||||||
'key': self.key,
|
'key__iexact': self.key,
|
||||||
}
|
}
|
||||||
|
|
||||||
user = getattr(self, 'user', None)
|
user = getattr(self, 'user', None)
|
||||||
@ -1337,13 +1355,6 @@ class InvenTreeUserSetting(BaseInvenTreeSetting):
|
|||||||
def validate_unique(self, exclude=None, **kwargs):
|
def validate_unique(self, exclude=None, **kwargs):
|
||||||
return super().validate_unique(exclude=exclude, user=self.user)
|
return super().validate_unique(exclude=exclude, user=self.user)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_filters(cls, key, **kwargs):
|
|
||||||
return {
|
|
||||||
'key__iexact': key,
|
|
||||||
'user__id': kwargs['user'].id
|
|
||||||
}
|
|
||||||
|
|
||||||
def to_native_value(self):
|
def to_native_value(self):
|
||||||
"""
|
"""
|
||||||
Return the "pythonic" value,
|
Return the "pythonic" value,
|
||||||
|
@ -175,23 +175,6 @@ class PluginSetting(common.models.BaseInvenTreeSetting):
|
|||||||
|
|
||||||
return super().get_setting_definition(key, **kwargs)
|
return super().get_setting_definition(key, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_filters(cls, key, **kwargs):
|
|
||||||
"""
|
|
||||||
Override filters method to ensure settings are filtered by plugin id
|
|
||||||
"""
|
|
||||||
|
|
||||||
filters = super().get_filters(key, **kwargs)
|
|
||||||
|
|
||||||
plugin = kwargs.get('plugin', None)
|
|
||||||
|
|
||||||
if plugin:
|
|
||||||
if issubclass(plugin.__class__, InvenTreePluginBase):
|
|
||||||
plugin = plugin.plugin_config()
|
|
||||||
filters['plugin'] = plugin
|
|
||||||
|
|
||||||
return filters
|
|
||||||
|
|
||||||
plugin = models.ForeignKey(
|
plugin = models.ForeignKey(
|
||||||
PluginConfig,
|
PluginConfig,
|
||||||
related_name='settings',
|
related_name='settings',
|
||||||
|
Loading…
Reference in New Issue
Block a user