mirror of https://github.com/jumpserver/jumpserver
perf: change cateogory data strucature
parent
ea1cb158b5
commit
21a60bf55e
|
@ -55,9 +55,9 @@ class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta):
|
||||||
categories = []
|
categories = []
|
||||||
for category, tps in cls.category_types():
|
for category, tps in cls.category_types():
|
||||||
category_data = {
|
category_data = {
|
||||||
'id': category.value,
|
'value': category.value,
|
||||||
'name': category.label,
|
'label': category.label,
|
||||||
'children': [cls.serialize_type(category, tp, with_constraints) for tp in tps]
|
'types': [cls.serialize_type(category, tp, with_constraints) for tp in tps]
|
||||||
}
|
}
|
||||||
categories.append(category_data)
|
categories.append(category_data)
|
||||||
return categories
|
return categories
|
||||||
|
@ -65,8 +65,8 @@ class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta):
|
||||||
@classmethod
|
@classmethod
|
||||||
def serialize_type(cls, category, tp, with_constraints=True):
|
def serialize_type(cls, category, tp, with_constraints=True):
|
||||||
data = {
|
data = {
|
||||||
'id': tp.value,
|
'value': tp.value,
|
||||||
'name': tp.label,
|
'label': tp.label,
|
||||||
'category': category,
|
'category': category,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,25 +86,6 @@ class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta):
|
||||||
(Category.CLOUD, CloudTypes)
|
(Category.CLOUD, CloudTypes)
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def grouped_choices(cls):
|
|
||||||
grouped_types = [(str(ca), tp.choices) for ca, tp in cls.category_types()]
|
|
||||||
return grouped_types
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def grouped_choices_to_objs(cls):
|
|
||||||
choices = cls.serialize_to_objs(Category.choices)
|
|
||||||
mapper = dict(cls.grouped_choices())
|
|
||||||
for choice in choices:
|
|
||||||
children = cls.serialize_to_objs(mapper[choice['value']])
|
|
||||||
choice['children'] = children
|
|
||||||
return choices
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def serialize_to_objs(choices):
|
|
||||||
title = ['value', 'display_name']
|
|
||||||
return [dict(zip(title, choice)) for choice in choices]
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def choice_to_node(choice, pid, opened=True, is_parent=True, meta=None):
|
def choice_to_node(choice, pid, opened=True, is_parent=True, meta=None):
|
||||||
node = TreeNode(**{
|
node = TreeNode(**{
|
||||||
|
|
|
@ -3,13 +3,13 @@ from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
class TypeSerializer(serializers.Serializer):
|
class TypeSerializer(serializers.Serializer):
|
||||||
id = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('id'))
|
label = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Label'))
|
||||||
name = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Name'))
|
value = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Value'))
|
||||||
category = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Category'))
|
category = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Category'))
|
||||||
constraints = serializers.JSONField(required=False, allow_null=True, label=_('Constraints'))
|
constraints = serializers.JSONField(required=False, allow_null=True, label=_('Constraints'))
|
||||||
|
|
||||||
|
|
||||||
class CategorySerializer(serializers.Serializer):
|
class CategorySerializer(serializers.Serializer):
|
||||||
id = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('id'))
|
label = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Label'))
|
||||||
name = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Name'))
|
value = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Value'))
|
||||||
children = TypeSerializer(many=True, required=False, label=_('Children'), read_only=True)
|
types = TypeSerializer(many=True, required=False, label=_('Types'), read_only=True)
|
||||||
|
|
Loading…
Reference in New Issue