serializers.py 2.78 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
35
36
37
class DeploymentTaskItemSerializer(serializers.ModelSerializer):
    service = ServiceSerializer()
    key = backend_serializers.SSHPublicKeySerializerB()
    site = SiteSerializer()

    class Meta:
        model = models.DeploymentTaskItem
        fields = [
            'action',
            'key',
            'service',
            'site',
        ]


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


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

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

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


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


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


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