Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 1 | from django.forms import widgets |
| 2 | from rest_framework import serializers |
Tony Mack | 0e17ee2 | 2013-04-06 20:04:02 -0400 | [diff] [blame] | 3 | from plstackapi.planetstack.models import * |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 4 | |
| 5 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 6 | class RoleSerializer(serializers.HyperlinkedModelSerializer): |
| 7 | |
| 8 | class Meta: |
| 9 | model = Role |
| 10 | fields = ('role_id', |
| 11 | 'role_type') |
| 12 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 13 | class 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 | |
| 29 | class 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', |
Tony Mack | e1ed6c7 | 2013-04-09 00:34:37 -0400 | [diff] [blame] | 42 | 'deployment_networks', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 43 | 'slices', |
| 44 | 'site_url', |
| 45 | 'enabled', |
| 46 | 'longitude', |
| 47 | 'latitude', |
| 48 | 'login_base', |
Tony Mack | e87bffa | 2013-04-08 23:18:04 -0400 | [diff] [blame] | 49 | 'tenant_id', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 50 | 'is_public', |
| 51 | 'abbreviated_name', |
| 52 | 'updated', |
| 53 | 'created') |
| 54 | |
| 55 | class DeploymentNetworkSerializer(serializers.HyperlinkedModelSerializer): |
| 56 | |
| 57 | sites = serializers.HyperlinkedRelatedField(view_name='sitedeploymentnetwork-detail') |
| 58 | class Meta: |
| 59 | model = DeploymentNetwork |
| 60 | fields = ('url', |
| 61 | 'name', |
| 62 | 'sites' |
| 63 | ) |
| 64 | |
| 65 | class SiteDeploymentNetworkSerializer(serializers.HyperlinkedModelSerializer): |
| 66 | |
| 67 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
| 68 | deploymentNetwork = serializers.HyperlinkedRelatedField(view_name='deploymentnetwork-detail') |
| 69 | |
| 70 | class Meta: |
| 71 | model = SiteDeploymentNetwork |
| 72 | fields = ('url', |
| 73 | 'site', |
| 74 | 'deploymentNetwork') |
| 75 | |
| 76 | class SliverSerializer(serializers.ModelSerializer): |
| 77 | slice = serializers.RelatedField(read_only=True) |
| 78 | #slice = serializers.PrimaryKeyRelatedField(read_only=True) |
| 79 | |
| 80 | class Meta: |
| 81 | model = Sliver |
| 82 | fields = ('id', |
| 83 | 'slice', |
| 84 | 'name') |
| 85 | |
| 86 | class NodeSerializer(serializers.ModelSerializer): |
| 87 | |
| 88 | class Meta: |
| 89 | model = Node |
| 90 | fields = ('id', |
| 91 | 'name') |
| 92 | |
| 93 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 94 | serializerLookUp = { |
| 95 | Role: RoleSerializer, |
| 96 | Site: SiteSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 97 | Slice: SliceSerializer, |
| 98 | Node: NodeSerializer, |
| 99 | Sliver: SliverSerializer, |
| 100 | DeploymentNetwork: DeploymentNetworkSerializer, |
| 101 | SiteDeploymentNetwork: SiteDeploymentNetworkSerializer, |
| 102 | None: None, |
| 103 | } |