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 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 6 | class DeploymentSerializer(serializers.HyperlinkedModelSerializer): |
| 7 | |
| 8 | # HyperlinkedModelSerializer doesn't include the id by default |
| 9 | id = serializers.Field() |
| 10 | sites = serializers.HyperlinkedRelatedField(view_name='site-detail') |
| 11 | class Meta: |
| 12 | model = Deployment |
| 13 | fields = ('id', |
| 14 | 'url', |
| 15 | 'name', |
| 16 | 'sites' |
| 17 | ) |
| 18 | |
| 19 | class ImageSerializer(serializers.HyperlinkedModelSerializer): |
| 20 | # HyperlinkedModelSerializer doesn't include the id by default |
| 21 | id = serializers.Field() |
| 22 | class Meta: |
| 23 | model = Image |
| 24 | fields = ('id', |
| 25 | 'url', |
| 26 | 'image_id', |
| 27 | 'name', |
| 28 | 'disk_format', |
| 29 | 'container_format') |
| 30 | |
| 31 | class NodeSerializer(serializers.HyperlinkedModelSerializer): |
| 32 | # HyperlinkedModelSerializer doesn't include the id by default |
| 33 | id = serializers.Field() |
| 34 | class Meta: |
| 35 | model = Node |
| 36 | fields = ('id', |
| 37 | 'url', |
| 38 | 'name') |
| 39 | |
| 40 | class ProjectSerializer(serializers.HyperlinkedModelSerializer): |
| 41 | # HyperlinkedModelSerializer doesn't include the id by default |
| 42 | id = serializers.Field() |
| 43 | class Meta: |
| 44 | model = Project |
| 45 | fields = ('id', |
| 46 | 'url', |
| 47 | 'name') |
| 48 | |
| 49 | class ReservationSerializer(serializers.HyperlinkedModelSerializer): |
| 50 | # HyperlinkedModelSerializer doesn't include the id by default |
| 51 | id = serializers.Field() |
| 52 | class Meta: |
| 53 | model = Reservation |
| 54 | fields = ('id', |
| 55 | 'url', |
| 56 | 'startTime', |
| 57 | 'slice', |
| 58 | 'duration', |
| 59 | 'endTime', |
| 60 | ) |
| 61 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 62 | class RoleSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 63 | # HyperlinkedModelSerializer doesn't include the id by default |
| 64 | id = serializers.Field() |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 65 | class Meta: |
| 66 | model = Role |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 67 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 68 | 'url', |
| 69 | 'role', |
| 70 | 'role_type') |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 71 | |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 72 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 73 | class ServiceClassSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 74 | # HyperlinkedModelSerializer doesn't include the id by default |
| 75 | id = serializers.Field() |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 76 | class Meta: |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 77 | model = ServiceClass |
Tony Mack | 5cc16ba | 2013-04-09 10:30:45 -0400 | [diff] [blame] | 78 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 79 | 'url', |
| 80 | 'name', |
| 81 | 'description', |
| 82 | 'commitment', |
| 83 | 'membershipFee', |
| 84 | 'membershipFeeMonths', |
| 85 | 'upgradeRequiresApproval', |
| 86 | 'upgradeFrom', |
| 87 | ) |
| 88 | |
| 89 | class ServiceResourceSerializer(serializers.HyperlinkedModelSerializer): |
| 90 | # HyperlinkedModelSerializer doesn't include the id by default |
| 91 | id = serializers.Field() |
| 92 | serviceClass = serializers.HyperlinkedRelatedField(view_name='serviceclass-detail') |
| 93 | class Meta: |
| 94 | model = ServiceResource |
| 95 | fields = ('id', |
| 96 | 'url', |
| 97 | 'name', |
| 98 | 'serviceClass', |
| 99 | 'maxUnitsDeployment', |
| 100 | 'maxUnitsNode', |
| 101 | 'maxDuration', |
| 102 | 'bucketInRate', |
| 103 | 'bucketMaxSize', |
| 104 | 'cost', |
| 105 | 'calendarReservable', |
| 106 | ) |
| 107 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 108 | class SliceSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 109 | # HyperlinkedModelSerializer doesn't include the id by default |
| 110 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 111 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 112 | slivers = serializers.HyperlinkedRelatedField(view_name='sliver-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 113 | class Meta: |
| 114 | model = Slice |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 115 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 116 | 'url', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 117 | 'tenant_id', |
| 118 | 'enabled', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 119 | 'name', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 120 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 121 | 'omf_friendly', |
| 122 | 'description', |
| 123 | 'slice_url', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 124 | 'network_id', |
| 125 | 'router_id', |
Tony Mack | 1e7169e | 2013-05-07 11:09:57 -0400 | [diff] [blame] | 126 | 'subnet_id', |
Scott Baker | 537d823 | 2014-04-08 23:40:56 -0700 | [diff] [blame] | 127 | 'imagePreference', |
Scott Baker | 4b0cedd | 2014-04-22 21:01:21 -0700 | [diff] [blame] | 128 | 'network', |
| 129 | 'mountDataSets', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 130 | 'site', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 131 | 'slivers', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 132 | 'updated', |
| 133 | 'created') |
| 134 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 135 | class SlicePrivilegeSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 136 | id = serializers.Field() |
| 137 | slice = serializers.HyperlinkedRelatedField(view_name='slice-detail') |
| 138 | user = serializers.HyperlinkedRelatedField(view_name='user-detail') |
| 139 | role = serializers.HyperlinkedRelatedField(view_name='role-detail') |
| 140 | class Meta: |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 141 | model = SlicePrivilege |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 142 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 143 | 'url', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 144 | 'user', |
| 145 | 'slice', |
| 146 | 'role') |
| 147 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 148 | class SiteSerializer(serializers.HyperlinkedModelSerializer): |
| 149 | |
| 150 | #Experimenting with whether to use ids, hyperlinks, or nested includes |
| 151 | #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True) |
| 152 | #slices = serializers.RelatedField(many=True, read_only=True) |
| 153 | #slices = SliceSerializer(many=True) |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 154 | # HyperlinkedModelSerializer doesn't include the id by default |
| 155 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 156 | slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 157 | |
| 158 | class Meta: |
| 159 | model = Site |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 160 | fields = ('id', |
| 161 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 162 | 'name', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 163 | 'slices', |
| 164 | 'site_url', |
| 165 | 'enabled', |
| 166 | 'longitude', |
| 167 | 'latitude', |
| 168 | 'login_base', |
Tony Mack | e87bffa | 2013-04-08 23:18:04 -0400 | [diff] [blame] | 169 | 'tenant_id', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 170 | 'is_public', |
| 171 | 'abbreviated_name', |
| 172 | 'updated', |
| 173 | 'created') |
| 174 | |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 175 | class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer): |
| 176 | id = serializers.Field() |
| 177 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
| 178 | user = serializers.HyperlinkedRelatedField(view_name='user-detail') |
| 179 | role = serializers.HyperlinkedRelatedField(view_name='role-detail') |
| 180 | class Meta: |
| 181 | model = SitePrivilege |
| 182 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 183 | 'url', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 184 | 'user', |
| 185 | 'site', |
| 186 | 'role') |
| 187 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 188 | class SliverSerializer(serializers.HyperlinkedModelSerializer): |
| 189 | # HyperlinkedModelSerializer doesn't include the id by default |
| 190 | id = serializers.Field() |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 191 | image = serializers.HyperlinkedRelatedField(view_name='image-detail') |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 192 | slice = serializers.HyperlinkedRelatedField(view_name='slice-detail') |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 193 | deploymentNetwork = serializers.HyperlinkedRelatedField(view_name='deployment-detail') |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 194 | node = serializers.HyperlinkedRelatedField(view_name='node-detail') |
| 195 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 196 | #slice = serializers.PrimaryKeyRelatedField(read_only=True) |
| 197 | |
| 198 | class Meta: |
| 199 | model = Sliver |
| 200 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 201 | 'url', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 202 | 'instance_id', |
Tony Mack | 5d6598c | 2013-04-12 12:45:02 -0400 | [diff] [blame] | 203 | 'name', |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 204 | 'instance_name', |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 205 | 'ip', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 206 | 'image', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 207 | 'slice', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 208 | 'deploymentNetwork', |
Tony Mack | 5d6598c | 2013-04-12 12:45:02 -0400 | [diff] [blame] | 209 | 'node') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 210 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 211 | class UserSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 212 | # HyperlinkedModelSerializer doesn't include the id by default |
| 213 | id = serializers.Field() |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 214 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
| 215 | slice_privileges = serializers.HyperlinkedRelatedField(view_name='sliceprivilege-detail') |
| 216 | site_privileges = serializers.HyperlinkedRelatedField(view_name='siteprivilege-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 217 | class Meta: |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 218 | model = User |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 219 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 220 | 'url', |
| 221 | 'kuser_id', |
| 222 | 'firstname', |
| 223 | 'lastname', |
| 224 | 'email', |
| 225 | 'password', |
| 226 | 'phone', |
| 227 | 'public_key', |
| 228 | 'user_url', |
| 229 | 'is_admin', |
| 230 | 'slice_privileges', |
| 231 | 'site_privileges') |
| 232 | |
| 233 | class TagSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 234 | # HyperlinkedModelSerializer doesn't include the id by default |
| 235 | id = serializers.Field() |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 236 | project = serializers.HyperlinkedRelatedField(view_name='project-detail') |
| 237 | #content_type = serializers.PrimaryKeyRelatedField(read_only=True) |
| 238 | content_type = serializers.RelatedField(source = "content_type") |
| 239 | content_object = serializers.RelatedField(source='content_object') |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 240 | class Meta: |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 241 | model = Tag |
| 242 | fields = ('id', |
| 243 | 'url', |
| 244 | 'project', |
| 245 | 'value', |
| 246 | 'content_type', |
| 247 | 'object_id', |
| 248 | 'content_object', |
| 249 | 'name') |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 250 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 251 | serializerLookUp = { |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 252 | Deployment: DeploymentSerializer, |
| 253 | Image: ImageSerializer, |
| 254 | Node: NodeSerializer, |
| 255 | Project: ProjectSerializer, |
| 256 | Reservation: ReservationSerializer, |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 257 | Role: RoleSerializer, |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 258 | ServiceClass: ServiceClassSerializer, |
| 259 | ServiceResource: ServiceResourceSerializer, |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 260 | Site: SiteSerializer, |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 261 | SitePrivilege: SitePrivilegeSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 262 | Slice: SliceSerializer, |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 263 | SlicePrivilege: SlicePrivilegeSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 264 | Sliver: SliverSerializer, |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 265 | Tag: TagSerializer, |
| 266 | User: UserSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 267 | None: None, |
| 268 | } |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 269 | |