serializers.py 1.72 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
19
20
21
22


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):
    site = SiteSerializer()
    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
57
58
        fields = [
                'sub', 'email', 'username', 'ssh_keys', 'groups', 'deployments'
                ]
Lukas Burgey's avatar
Lukas Burgey committed
59
60


61
62
63
64
65
66
67
68
class ClientSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = models.User
        fields = [
                'name', 'site'
                ]


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


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