Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 1 | from django.forms import widgets |
| 2 | from rest_framework import serializers |
| 3 | from models import * |
| 4 | |
| 5 | |
| 6 | class 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 | |
| 22 | class 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 | |
| 47 | class 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 | |
| 57 | class 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 | |
| 68 | class 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 | |
| 78 | class NodeSerializer(serializers.ModelSerializer): |
| 79 | |
| 80 | class Meta: |
| 81 | model = Node |
| 82 | fields = ('id', |
| 83 | 'name') |
| 84 | |
| 85 | |
| 86 | serializerLookUp = { Site: SiteSerializer, |
| 87 | Slice: SliceSerializer, |
| 88 | Node: NodeSerializer, |
| 89 | Sliver: SliverSerializer, |
| 90 | DeploymentNetwork: DeploymentNetworkSerializer, |
| 91 | SiteDeploymentNetwork: SiteDeploymentNetworkSerializer, |
| 92 | None: None, |
| 93 | } |