mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-02 11:40:58 +00:00
Enable regex search (#4566)
* Adds custom search filter to allow 'regex' searching of results * Specify if "shell" can access database for certain commands * Bug fix for settings API - Do not allow cache on detail endpoints - Was causing strange error conditions with missing or duplicate PK values * Adds user setting to control regex search * Enable regex for search queries - bootstrap tables - search preview * Pass search options through bettererer * Refactor API endpoints to use new filter approach * Bump API version * Add "whole word" search - Closes https://github.com/inventree/InvenTree/issues/4510 * Handle case where existing fields are empty * pop > get
This commit is contained in:
@ -20,6 +20,7 @@ import common.models
|
||||
import common.serializers
|
||||
from InvenTree.api import BulkDeleteMixin
|
||||
from InvenTree.config import CONFIG_LOOKUPS
|
||||
from InvenTree.filters import InvenTreeSearchFilter
|
||||
from InvenTree.helpers import inheritors
|
||||
from InvenTree.mixins import (ListAPI, RetrieveAPI, RetrieveUpdateAPI,
|
||||
RetrieveUpdateDestroyAPI)
|
||||
@ -169,7 +170,7 @@ class SettingsList(ListAPI):
|
||||
|
||||
filter_backends = [
|
||||
DjangoFilterBackend,
|
||||
filters.SearchFilter,
|
||||
InvenTreeSearchFilter,
|
||||
filters.OrderingFilter,
|
||||
]
|
||||
|
||||
@ -226,7 +227,10 @@ class GlobalSettingsDetail(RetrieveUpdateAPI):
|
||||
if key not in common.models.InvenTreeSetting.SETTINGS.keys():
|
||||
raise NotFound()
|
||||
|
||||
return common.models.InvenTreeSetting.get_setting_object(key)
|
||||
return common.models.InvenTreeSetting.get_setting_object(
|
||||
key,
|
||||
cache=False, create=True
|
||||
)
|
||||
|
||||
permission_classes = [
|
||||
permissions.IsAuthenticated,
|
||||
@ -284,7 +288,11 @@ class UserSettingsDetail(RetrieveUpdateAPI):
|
||||
if key not in common.models.InvenTreeUserSetting.SETTINGS.keys():
|
||||
raise NotFound()
|
||||
|
||||
return common.models.InvenTreeUserSetting.get_setting_object(key, user=self.request.user)
|
||||
return common.models.InvenTreeUserSetting.get_setting_object(
|
||||
key,
|
||||
user=self.request.user,
|
||||
cache=False, create=True
|
||||
)
|
||||
|
||||
permission_classes = [
|
||||
UserSettingsPermissions,
|
||||
@ -334,7 +342,7 @@ class NotificationList(NotificationMessageMixin, BulkDeleteMixin, ListAPI):
|
||||
|
||||
filter_backends = [
|
||||
DjangoFilterBackend,
|
||||
filters.SearchFilter,
|
||||
InvenTreeSearchFilter,
|
||||
filters.OrderingFilter,
|
||||
]
|
||||
|
||||
|
@ -388,10 +388,10 @@ class BaseInvenTreeSetting(models.Model):
|
||||
if not setting:
|
||||
|
||||
# Unless otherwise specified, attempt to create the setting
|
||||
create = kwargs.get('create', True)
|
||||
create = kwargs.pop('create', True)
|
||||
|
||||
# Prevent creation of new settings objects when importing data
|
||||
if InvenTree.ready.isImportingData() or not InvenTree.ready.canAppAccessDatabase(allow_test=True):
|
||||
if InvenTree.ready.isImportingData() or not InvenTree.ready.canAppAccessDatabase(allow_test=True, allow_shell=True):
|
||||
create = False
|
||||
|
||||
if create:
|
||||
@ -1979,6 +1979,20 @@ class InvenTreeUserSetting(BaseInvenTreeSetting):
|
||||
'validator': [int, MinValueValidator(1)]
|
||||
},
|
||||
|
||||
'SEARCH_REGEX': {
|
||||
'name': _('Regex Search'),
|
||||
'description': _('Enable regular expressions in search queries'),
|
||||
'default': False,
|
||||
'validator': bool,
|
||||
},
|
||||
|
||||
'SEARCH_WHOLE': {
|
||||
'name': _('Whole Word Search'),
|
||||
'description': _('Search queries return results for whole word matches'),
|
||||
'default': False,
|
||||
'validator': bool,
|
||||
},
|
||||
|
||||
'PART_SHOW_QUANTITY_IN_FORMS': {
|
||||
'name': _('Show Quantity in Forms'),
|
||||
'description': _('Display available part quantity in some forms'),
|
||||
|
Reference in New Issue
Block a user