serializers.py 2.8 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
25
26
27
28
29
30
31
32
33
34
class DeploymentTaskItemSerializer(serializers.ModelSerializer):
    service = ServiceSerializer()
    key = backend_serializers.SSHPublicKeySerializerB()
    site = SiteSerializer()

    class Meta:
        model = models.DeploymentTaskItem
        fields = [
            'action',
            'key',
            'service',
            'site',
35
            'state',
Lukas Burgey's avatar
Lukas Burgey committed
36
37
38
        ]


39
class DeploymentTaskSerializer(serializers.ModelSerializer):
Lukas Burgey's avatar
Lukas Burgey committed
40
41
    key = backend_serializers.SSHPublicKeySerializerB()
    service = ServiceSerializer()
42
43
    class Meta:
        model = models.DeploymentTask
Lukas Burgey's avatar
Lukas Burgey committed
44
45
46
47
48
        fields = [
            'action',
            'key',
            'service',
        ]
49
50


Lukas Burgey's avatar
Lukas Burgey committed
51
52
class DeploymentSerializer(serializers.Serializer):
    service = ServiceSerializer()
53
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
54
55
56
    ssh_keys_to_withdraw = backend_serializers.SSHPublicKeySerializer(many=True)
    deploys = DeploymentTaskSerializer(many=True)
    withdrawals = DeploymentTaskSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
57
58
59
60
61
62
63
64
65
66
67
68
69

    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
70
class UserSerializer(serializers.ModelSerializer):
71
72
    groups = backend_serializers.GroupSerializer(many=True)
    ssh_keys = backend_serializers.SSHPublicKeySerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
73
    deployments = DeploymentSerializer(many=True)
74
75
    auth_groups = backend_serializers.AuthGroupSerializer(many=True)
    deployment_tasks = DeploymentTaskSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
76
    deployment_task_items = DeploymentTaskItemSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
77
78
79

    class Meta:
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
80
81
82
83
84
85
86
87
88
89
90
        fields = [
            'id',
            'email',
            'userinfo',
            'ssh_keys',
            'groups',
            'deployments',
            'auth_groups',
            'deployment_tasks',
            'deployment_task_items',
        ]
Lukas Burgey's avatar
Lukas Burgey committed
91
92


93
94
95
class ClientSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
96
        fields = ['name', 'site']
97
98


Lukas Burgey's avatar
Lukas Burgey committed
99
100
class StateSerializer(serializers.Serializer):
    services = ServiceSerializer(many=True)
101
102
103
104


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