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') |
Tony Mack | 6bdc475 | 2013-04-09 01:05:37 -0400 | [diff] [blame] | 36 | deployment_networks = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='sitedeploymentnetwork-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 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 |
Tony Mack | 2d81e63 | 2013-04-09 02:34:10 -0400 | [diff] [blame^] | 60 | fields = ('name', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 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 | } |