blob: ab79886738e7c60143a448857eb7d5ec15c0ba6b [file] [log] [blame]
Tony Mack7130ac32013-03-22 21:58:00 -04001from django.forms import widgets
2from rest_framework import serializers
Tony Mack0e17ee22013-04-06 20:04:02 -04003from plstackapi.planetstack.models import *
Tony Mack7130ac32013-03-22 21:58:00 -04004
5
Tony Macka28f1cd2013-04-07 20:02:31 -04006class RoleSerializer(serializers.HyperlinkedModelSerializer):
7
8 class Meta:
9 model = Role
10 fields = ('role_id',
11 'role_type')
12
Tony Mack7130ac32013-03-22 21:58:00 -040013class SliceSerializer(serializers.HyperlinkedModelSerializer):
14
15 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
16
17 class Meta:
18 model = Slice
19 fields = ('url',
20 'name',
21 'instantiation',
22 'omf_friendly',
23 'description',
24 'slice_url',
25 'site',
26 'updated',
27 'created')
28
29class SiteSerializer(serializers.HyperlinkedModelSerializer):
30
31 #Experimenting with whether to use ids, hyperlinks, or nested includes
32 #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
33 #slices = serializers.RelatedField(many=True, read_only=True)
34 #slices = SliceSerializer(many=True)
35 slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail')
36 deploymentNetworks = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='sitedeploymentnetwork-detail')
37
38 class Meta:
39 model = Site
40 fields = ('url',
41 'name',
42 'deploymentNetworks',
43 'slices',
44 'site_url',
45 'enabled',
46 'longitude',
47 'latitude',
48 'login_base',
49 'is_public',
50 'abbreviated_name',
51 'updated',
52 'created')
53
54class DeploymentNetworkSerializer(serializers.HyperlinkedModelSerializer):
55
56 sites = serializers.HyperlinkedRelatedField(view_name='sitedeploymentnetwork-detail')
57 class Meta:
58 model = DeploymentNetwork
59 fields = ('url',
60 'name',
61 'sites'
62 )
63
64class SiteDeploymentNetworkSerializer(serializers.HyperlinkedModelSerializer):
65
66 site = serializers.HyperlinkedRelatedField(view_name='site-detail')
67 deploymentNetwork = serializers.HyperlinkedRelatedField(view_name='deploymentnetwork-detail')
68
69 class Meta:
70 model = SiteDeploymentNetwork
71 fields = ('url',
72 'site',
73 'deploymentNetwork')
74
75class SliverSerializer(serializers.ModelSerializer):
76 slice = serializers.RelatedField(read_only=True)
77 #slice = serializers.PrimaryKeyRelatedField(read_only=True)
78
79 class Meta:
80 model = Sliver
81 fields = ('id',
82 'slice',
83 'name')
84
85class NodeSerializer(serializers.ModelSerializer):
86
87 class Meta:
88 model = Node
89 fields = ('id',
90 'name')
91
92
Tony Macka28f1cd2013-04-07 20:02:31 -040093serializerLookUp = {
94 Role: RoleSerializer,
95 Site: SiteSerializer,
Tony Mack7130ac32013-03-22 21:58:00 -040096 Slice: SliceSerializer,
97 Node: NodeSerializer,
98 Sliver: SliverSerializer,
99 DeploymentNetwork: DeploymentNetworkSerializer,
100 SiteDeploymentNetwork: SiteDeploymentNetworkSerializer,
101 None: None,
102 }