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