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', |
| 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 | |
| 54 | class 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 | |
| 64 | class 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 | |
| 75 | class 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 | |
| 85 | class NodeSerializer(serializers.ModelSerializer): |
| 86 | |
| 87 | class Meta: |
| 88 | model = Node |
| 89 | fields = ('id', |
| 90 | 'name') |
| 91 | |
| 92 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 93 | serializerLookUp = { |
| 94 | Role: RoleSerializer, |
| 95 | Site: SiteSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 96 | Slice: SliceSerializer, |
| 97 | Node: NodeSerializer, |
| 98 | Sliver: SliverSerializer, |
| 99 | DeploymentNetwork: DeploymentNetworkSerializer, |
| 100 | SiteDeploymentNetwork: SiteDeploymentNetworkSerializer, |
| 101 | None: None, |
| 102 | } |