fix: improve module tree query to use Q object for filtering by workspace_id
This commit is contained in:
parent
8f0dd16949
commit
32111f6a8f
@ -105,5 +105,12 @@ class ModuleTreeReadAPI(APIMixin):
|
|||||||
enum=["APPLICATION", "KNOWLEDGE", "TOOL"],
|
enum=["APPLICATION", "KNOWLEDGE", "TOOL"],
|
||||||
location='path',
|
location='path',
|
||||||
required=True,
|
required=True,
|
||||||
)
|
),
|
||||||
|
OpenApiParameter(
|
||||||
|
name="name",
|
||||||
|
description="名称",
|
||||||
|
type=OpenApiTypes.STR,
|
||||||
|
location='query',
|
||||||
|
required=False,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -95,9 +95,13 @@ class ModuleTreeSerializer(serializers.Serializer):
|
|||||||
workspace_id = serializers.CharField(required=True, allow_null=True, allow_blank=True, label=_('workspace id'))
|
workspace_id = serializers.CharField(required=True, allow_null=True, allow_blank=True, label=_('workspace id'))
|
||||||
source = serializers.CharField(required=True, label=_('source'))
|
source = serializers.CharField(required=True, label=_('source'))
|
||||||
|
|
||||||
def get_module_tree(self):
|
def get_module_tree(self, name=None):
|
||||||
self.is_valid(raise_exception=True)
|
self.is_valid(raise_exception=True)
|
||||||
Module = get_module_type(self.data.get('source'))
|
Module = get_module_type(self.data.get('source'))
|
||||||
|
if name is not None:
|
||||||
|
nodes = Module.objects.filter(Q(workspace_id=self.data.get('workspace_id')) &
|
||||||
|
Q(name__contains=name)).get_cached_trees()
|
||||||
|
else:
|
||||||
nodes = Module.objects.filter(Q(workspace_id=self.data.get('workspace_id'))).get_cached_trees()
|
nodes = Module.objects.filter(Q(workspace_id=self.data.get('workspace_id'))).get_cached_trees()
|
||||||
serializer = ToolModuleTreeSerializer(nodes, many=True)
|
serializer = ToolModuleTreeSerializer(nodes, many=True)
|
||||||
return serializer.data # 这是可序列化的字典
|
return serializer.data # 这是可序列化的字典
|
||||||
|
|||||||
@ -88,4 +88,4 @@ class ModuleTreeView(APIView):
|
|||||||
def get(self, request: Request, workspace_id: str, source: str):
|
def get(self, request: Request, workspace_id: str, source: str):
|
||||||
return result.success(ModuleTreeSerializer(
|
return result.success(ModuleTreeSerializer(
|
||||||
data={'workspace_id': workspace_id, 'source': source}
|
data={'workspace_id': workspace_id, 'source': source}
|
||||||
).get_module_tree())
|
).get_module_tree(request.query_params.get('name')))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user