clients.py 1.06 KB
Newer Older
1
2
3
4

from rest_framework import serializers
from rest_polymorphic.serializers import PolymorphicSerializer

5
from feudal.backend.models.auth.vos import VO, Group, Entitlement, EntitlementNameSpace
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
45
46
47
48


class EntitlementNameSpaceSerializer(serializers.ModelSerializer):
    class Meta:
        model = EntitlementNameSpace
        fields = ('name', )


# polymorphic serializer
VO_FIELDS = (
    'name',
)


class AbstractVOSerializer(serializers.ModelSerializer):
    class Meta:
        model = VO
        fields = VO_FIELDS


class GroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = Group
        fields = VO_FIELDS


class EntitlementSerializer(serializers.ModelSerializer):
    name_space = EntitlementNameSpaceSerializer()

    class Meta:
        model = Entitlement
        fields = VO_FIELDS + (
            'name_space',
            'group_authority',
        )


class VOSerializer(PolymorphicSerializer):
    model_serializer_mapping = {
        VO: AbstractVOSerializer,
        Group: GroupSerializer,
        Entitlement: EntitlementSerializer,
    }