Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 1 | from django.forms import widgets |
| 2 | from rest_framework import serializers |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 3 | from core.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): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 7 | # HyperlinkedModelSerializer doesn't include the id by default |
| 8 | id = serializers.Field() |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 9 | class Meta: |
| 10 | model = Role |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 11 | fields = ('id', |
| 12 | 'role_id', |
Siobhan Tully | 47ae1b5 | 2013-05-10 15:53:14 -0400 | [diff] [blame] | 13 | 'role', |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 14 | 'role_type') |
| 15 | |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 16 | |
| 17 | class UserSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 18 | # HyperlinkedModelSerializer doesn't include the id by default |
| 19 | id = serializers.Field() |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 20 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
| 21 | slice_memberships = serializers.HyperlinkedRelatedField(view_name='slice-membership-detail') |
| 22 | site_privileges = serializers.HyperlinkedRelatedField(view_name='site-privilege-detail') |
| 23 | class Meta: |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 24 | model = User |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 25 | fields = ('id', |
| 26 | 'user_id', |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 27 | 'kuser_id', |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 28 | 'firstname', |
| 29 | 'lastname', |
| 30 | 'email', |
Tony Mack | b0d9742 | 2013-06-10 09:57:45 -0400 | [diff] [blame] | 31 | 'password', |
| 32 | 'phone', |
| 33 | 'public_key', |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 34 | 'user_url', |
| 35 | 'is_admin', |
| 36 | 'site', |
| 37 | 'slice_memberships', |
| 38 | 'site_privileges') |
| 39 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 40 | class SliceSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 41 | # HyperlinkedModelSerializer doesn't include the id by default |
| 42 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 43 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 44 | slivers = serializers.HyperlinkedRelatedField(view_name='sliver-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 45 | class Meta: |
| 46 | model = Slice |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 47 | fields = ('id', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 48 | 'tenant_id', |
| 49 | 'enabled', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 50 | 'name', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 51 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 52 | 'omf_friendly', |
| 53 | 'description', |
| 54 | 'slice_url', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 55 | 'network_id', |
| 56 | 'router_id', |
Tony Mack | 1e7169e | 2013-05-07 11:09:57 -0400 | [diff] [blame] | 57 | 'subnet_id', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 58 | 'site', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 59 | 'slivers', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 60 | 'updated', |
| 61 | 'created') |
| 62 | |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 63 | class SliceMembershipSerializer(serializers.HyperlinkedModelSerializer): |
| 64 | id = serializers.Field() |
| 65 | slice = serializers.HyperlinkedRelatedField(view_name='slice-detail') |
| 66 | user = serializers.HyperlinkedRelatedField(view_name='user-detail') |
| 67 | role = serializers.HyperlinkedRelatedField(view_name='role-detail') |
| 68 | class Meta: |
| 69 | model = SitePrivilege |
| 70 | fields = ('id', |
| 71 | 'user', |
| 72 | 'slice', |
| 73 | 'role') |
| 74 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 75 | class SiteSerializer(serializers.HyperlinkedModelSerializer): |
| 76 | |
| 77 | #Experimenting with whether to use ids, hyperlinks, or nested includes |
| 78 | #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True) |
| 79 | #slices = serializers.RelatedField(many=True, read_only=True) |
| 80 | #slices = SliceSerializer(many=True) |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 81 | # HyperlinkedModelSerializer doesn't include the id by default |
| 82 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 83 | slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 84 | |
| 85 | class Meta: |
| 86 | model = Site |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 87 | fields = ('id', |
| 88 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 89 | 'name', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 90 | 'slices', |
| 91 | 'site_url', |
| 92 | 'enabled', |
| 93 | 'longitude', |
| 94 | 'latitude', |
| 95 | 'login_base', |
Tony Mack | e87bffa | 2013-04-08 23:18:04 -0400 | [diff] [blame] | 96 | 'tenant_id', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 97 | 'is_public', |
| 98 | 'abbreviated_name', |
| 99 | 'updated', |
| 100 | 'created') |
| 101 | |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 102 | class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer): |
| 103 | id = serializers.Field() |
| 104 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
| 105 | user = serializers.HyperlinkedRelatedField(view_name='user-detail') |
| 106 | role = serializers.HyperlinkedRelatedField(view_name='role-detail') |
| 107 | class Meta: |
| 108 | model = SitePrivilege |
| 109 | fields = ('id', |
| 110 | 'user', |
| 111 | 'site', |
| 112 | 'role') |
| 113 | |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 114 | class DeploymentSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 115 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 116 | # HyperlinkedModelSerializer doesn't include the id by default |
| 117 | id = serializers.Field() |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 118 | sites = serializers.HyperlinkedRelatedField(view_name='deploymentnetwork-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 119 | class Meta: |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 120 | model = Deployment |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 121 | fields = ('id', |
| 122 | 'name', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 123 | 'sites' |
| 124 | ) |
| 125 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 126 | class SliverSerializer(serializers.HyperlinkedModelSerializer): |
| 127 | # HyperlinkedModelSerializer doesn't include the id by default |
| 128 | id = serializers.Field() |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 129 | image = serializers.HyperlinkedRelatedField(view_name='image-detail') |
| 130 | key = serializers.HyperlinkedRelatedField(view_name='key-detail') |
| 131 | slice = serializers.HyperlinkedRelatedField(view_name='slice-detail') |
| 132 | deployment_network = serializers.HyperlinkedRelatedField(view_name='deployment_network-detail') |
| 133 | node = serializers.HyperlinkedRelatedField(view_name='node-detail') |
| 134 | |
| 135 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 136 | #slice = serializers.PrimaryKeyRelatedField(read_only=True) |
| 137 | |
| 138 | class Meta: |
| 139 | model = Sliver |
| 140 | fields = ('id', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 141 | 'instance_id', |
Tony Mack | 5d6598c | 2013-04-12 12:45:02 -0400 | [diff] [blame] | 142 | 'name', |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 143 | 'instance_name', |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 144 | 'ip', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 145 | 'image', |
Tony Mack | 5d6598c | 2013-04-12 12:45:02 -0400 | [diff] [blame] | 146 | 'key', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 147 | 'slice', |
Tony Mack | 5d6598c | 2013-04-12 12:45:02 -0400 | [diff] [blame] | 148 | 'deploymentNetwork', |
| 149 | 'node') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 150 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 151 | class NodeSerializer(serializers.HyperlinkedModelSerializer): |
| 152 | # HyperlinkedModelSerializer doesn't include the id by default |
| 153 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 154 | class Meta: |
| 155 | model = Node |
| 156 | fields = ('id', |
| 157 | 'name') |
| 158 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 159 | class ImageSerializer(serializers.HyperlinkedModelSerializer): |
| 160 | # HyperlinkedModelSerializer doesn't include the id by default |
| 161 | id = serializers.Field() |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 162 | class Meta: |
| 163 | model = Image |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 164 | fields = ('id', |
| 165 | 'image_id', |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 166 | 'name', |
| 167 | 'disk_format', |
| 168 | 'container_format') |
| 169 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 170 | serializerLookUp = { |
| 171 | Role: RoleSerializer, |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 172 | User: UserSerializer, |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 173 | Site: SiteSerializer, |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 174 | SitePrivilege: SitePrivilegeSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 175 | Slice: SliceSerializer, |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 176 | SliceMembership: SliceMembershipSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 177 | Node: NodeSerializer, |
| 178 | Sliver: SliverSerializer, |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 179 | Deployment: DeploymentSerializer, |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 180 | Image: ImageSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 181 | None: None, |
| 182 | } |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 183 | |