serializers.py 2.9 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
class DeploymentTaskItemSerializer(serializers.ModelSerializer):
    service = ServiceSerializer()
    key = backend_serializers.SSHPublicKeySerializerB()
    site = SiteSerializer()
27
    questionnaire = serializers.JSONField()
Lukas Burgey's avatar
Lukas Burgey committed
28
29
30
31
32
33
34
35

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


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


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

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

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


97
98
99
class ClientSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
100
        fields = ['name', 'site']
101
102


Lukas Burgey's avatar
Lukas Burgey committed
103
104
class StateSerializer(serializers.Serializer):
    services = ServiceSerializer(many=True)
105
106
107
108


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