serializers.py 1.66 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


class SiteSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Site
11
        fields = ['id', 'name']
Lukas Burgey's avatar
Lukas Burgey committed
12
13
14


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
20
        exclude = []
Lukas Burgey's avatar
Lukas Burgey committed
21
22


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
    groups = backend_serializers.GroupSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
41
    auth_groups = backend_serializers.AuthGroupSerializer(many=True)
42
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
43
    deployments = DeploymentSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
44
45
46

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


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


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


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