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


23
24
25
26
27
28
class DeploymentTaskSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.DeploymentTask
        fields = ['action', 'key']


Lukas Burgey's avatar
Lukas Burgey committed
29
30
class DeploymentSerializer(serializers.Serializer):
    service = ServiceSerializer()
31
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
32
33
34
    ssh_keys_to_withdraw = backend_serializers.SSHPublicKeySerializer(many=True)
    deploys = DeploymentTaskSerializer(many=True)
    withdrawals = DeploymentTaskSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
35
36
37
38
39
40
41
42
43
44
45
46
47

    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
48
class UserSerializer(serializers.ModelSerializer):
49
50
    groups = backend_serializers.GroupSerializer(many=True)
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
51
    deployments = DeploymentSerializer(many=True)
52
53
    auth_groups = backend_serializers.AuthGroupSerializer(many=True)
    deployment_tasks = DeploymentTaskSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
54
55
56

    class Meta:
        model = models.User
57
58
        fields = ['id', 'email', 'userinfo', 'ssh_keys', 'groups', 'deployments', 'auth_groups',
                  'deployment_tasks']
Lukas Burgey's avatar
Lukas Burgey committed
59
60


61
62
63
class ClientSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
64
        fields = ['name', 'site']
65
66


Lukas Burgey's avatar
Lukas Burgey committed
67
68
class StateSerializer(serializers.Serializer):
    services = ServiceSerializer(many=True)
69
70
71
72


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