serializers.py 1.59 KB
Newer Older
1
2
# we don't need to deserialize, so we do not implement the abstract methods
# pylint: disable=abstract-method
Lukas Burgey's avatar
Lukas Burgey committed
3

4
5
from rest_framework import serializers
from .. import models, serializers as backend_serializers
Lukas Burgey's avatar
Lukas Burgey committed
6
7
8
9
10
11
12
13
14


class SiteSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Site
        fields = ['name']


class ServiceSerializer(serializers.ModelSerializer):
15
    site = SiteSerializer(many=True)
16
    groups = backend_serializers.GroupSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
17
18

    class Meta:
19
        model = models.Service
Lukas Burgey's avatar
Lukas Burgey committed
20
21
22
        exclude = ['id']


Lukas Burgey's avatar
Lukas Burgey committed
23
24
class DeploymentSerializer(serializers.Serializer):
    service = ServiceSerializer()
25
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
26
27
28
29
30
31
32
33
34
35
36
37
38

    class Meta:
        model = models.Deployment
        exclude = ['user']


class DeploymentSerializerB(serializers.Serializer):
    service = ServiceSerializer()

    class Meta:
        model = models.Deployment


Lukas Burgey's avatar
Lukas Burgey committed
39
class UserSerializer(serializers.ModelSerializer):
40
41
    groups = backend_serializers.GroupSerializer(many=True)
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
42
    deployments = DeploymentSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
43
44
45

    class Meta:
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
46
        fields = ['sub', 'email', 'username', 'ssh_keys', 'groups', 'deployments']
Lukas Burgey's avatar
Lukas Burgey committed
47
48


49
50
51
class ClientSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
52
        fields = ['name', 'site']
53
54


Lukas Burgey's avatar
Lukas Burgey committed
55
56
class StateSerializer(serializers.Serializer):
    services = ServiceSerializer(many=True)
57
58
59
60


class ClientViewSerializer(serializers.Serializer):
    deployments = serializers.JSONField()