serializers.py 1.67 KB
Newer Older
Lukas Burgey's avatar
Lukas Burgey committed
1
2
from django.contrib.auth.models import Group
from rest_framework import serializers
3
from .. import models
Lukas Burgey's avatar
Lukas Burgey committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18


class GroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = Group
        fields = ['name']


class SiteSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Site
        fields = ['name']


class ServiceSerializer(serializers.ModelSerializer):
19
    site = SiteSerializer(many=True)
Lukas Burgey's avatar
Lukas Burgey committed
20
21
22
    groups = GroupSerializer(many=True)

    class Meta:
23
        model = models.Service
Lukas Burgey's avatar
Lukas Burgey committed
24
25
26
27
28
29
30
31
32
        exclude = ['id']


class SSHPublicKeySerializer(serializers.ModelSerializer):
    class Meta:
        model = models.SSHPublicKey
        fields = ['name', 'key']


Lukas Burgey's avatar
Lukas Burgey committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class DeploymentSerializer(serializers.Serializer):
    service = ServiceSerializer()
    ssh_keys = SSHPublicKeySerializer(many=True)

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

    class Meta:
        model = models.User
Lukas Burgey's avatar
Lukas Burgey committed
56
        fields = ['sub', 'email', 'username', 'ssh_keys', 'groups', 'deployments']
Lukas Burgey's avatar
Lukas Burgey committed
57
58


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


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


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