-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathresource_mapping_serializers.py
More file actions
44 lines (35 loc) · 1.59 KB
/
resource_mapping_serializers.py
File metadata and controls
44 lines (35 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# coding=utf-8
"""
@project: MaxKB
@Author:虎虎
@file: workspace_user_resource_permission.py
@date:2025/4/28 17:17
@desc:
"""
import os
from django.db import models
from django.db.models import QuerySet
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers
from common.db.search import native_page_search, get_dynamics_model
from common.utils.common import get_file_content
from maxkb.conf import PROJECT_DIR
class ResourceMappingSerializer(serializers.Serializer):
resource = serializers.CharField(required=True, label=_('resource'))
resource_id = serializers.UUIDField(required=True, label=_('resource Id'))
resource_name = serializers.CharField(required=False, allow_null=True, allow_blank=True, label=_('resource'))
def get_query_set(self):
queryset = QuerySet(model=get_dynamics_model({
'name': models.CharField(),
'target_id': models.CharField(),
"target_type": models.CharField()
}))
queryset = queryset.filter(target_id=self.data.get('resource_id'),
target_type=self.data.get('resource'))
if self.data.get('resource_name'):
queryset = queryset.filter(name__icontains=self.data.get('resource_name'))
return queryset
def page(self, current_page, page_size):
return native_page_search(current_page, page_size, self.get_query_set(), get_file_content(
os.path.join(PROJECT_DIR, "apps", "system_manage",
'sql', 'list_resource_mapping.sql')), with_table_name=False)