mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-26 15:25:55 +00:00
* perf: 整合系统用户和管理用户 * stash stash perf: 优化系统用户和资产的表结构 * perf: 添加信号 * perf: 添加算法 * perf: 去掉 asset user backends * perf: 整理系统用户api * perfF: 暂存一下 * stash * perf: 暂存一下 * perf: 暂存 * xxx * perf: ... * stash it * xxx * xxx * xxx * xxx * xxx * stash it * 修改Protocols * perf: 修改创建authbook信号 * perf: 添加auth info * .stash * perf: 基本完成 * perf: 修复完成 * perf: 修复更改的id * perf: 修复迁移过去数量不对的问题 * perf: 修改systemuser * fix: 修复批量编辑近期的问题 * fix: 修复authbook加载的问题 * xxx Co-authored-by: ibuler <ibuler@qq.com>
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
from rest_framework import serializers
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
|
|
|
from ..models import Label
|
|
|
|
|
|
class LabelSerializer(BulkOrgResourceModelSerializer):
|
|
asset_count = serializers.SerializerMethodField(label=_("Assets amount"))
|
|
category_display = serializers.ReadOnlyField(source='get_category_display', label=_('Category display'))
|
|
|
|
class Meta:
|
|
model = Label
|
|
fields_mini = ['id', 'name']
|
|
fields_small = fields_mini + [
|
|
'value', 'category', 'category_display',
|
|
'is_active',
|
|
'date_created',
|
|
'comment',
|
|
]
|
|
fields_m2m = ['asset_count', 'assets']
|
|
fields = fields_small + fields_m2m
|
|
read_only_fields = (
|
|
'category', 'date_created', 'asset_count',
|
|
)
|
|
extra_kwargs = {
|
|
'assets': {'required': False}
|
|
}
|
|
|
|
@staticmethod
|
|
def get_asset_count(obj):
|
|
return obj.assets.count()
|
|
|
|
def get_field_names(self, declared_fields, info):
|
|
fields = super().get_field_names(declared_fields, info)
|
|
fields.extend(['get_category_display'])
|
|
return fields
|
|
|
|
|
|
class LabelDistinctSerializer(BulkOrgResourceModelSerializer):
|
|
value = serializers.SerializerMethodField()
|
|
|
|
class Meta:
|
|
model = Label
|
|
fields = ("name", "value")
|
|
|
|
@staticmethod
|
|
def get_value(obj):
|
|
labels = Label.objects.filter(name=obj["name"])
|
|
return ', '.join([label.value for label in labels])
|