mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:12:51 +00:00
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"],
|
||||
location='path',
|
||||
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'))
|
||||
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)
|
||||
Module = get_module_type(self.data.get('source'))
|
||||
nodes = Module.objects.filter(Q(workspace_id=self.data.get('workspace_id'))).get_cached_trees()
|
||||
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()
|
||||
serializer = ToolModuleTreeSerializer(nodes, many=True)
|
||||
return serializer.data # 这是可序列化的字典
|
||||
|
|
|
|||
|
|
@ -88,4 +88,4 @@ class ModuleTreeView(APIView):
|
|||
def get(self, request: Request, workspace_id: str, source: str):
|
||||
return result.success(ModuleTreeSerializer(
|
||||
data={'workspace_id': workspace_id, 'source': source}
|
||||
).get_module_tree())
|
||||
).get_module_tree(request.query_params.get('name')))
|
||||
|
|
|
|||
Loading…
Reference in New Issue