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', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 127 | 'site', |
Tony Mack | 3a1af41 | 2013-04-09 22:36:27 -0400 | [diff] [blame] | 128 | 'slivers', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 129 | 'updated', |
| 130 | 'created') |
| 131 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 132 | class SlicePrivilegeSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 133 | id = serializers.Field() |
| 134 | slice = serializers.HyperlinkedRelatedField(view_name='slice-detail') |
| 135 | user = serializers.HyperlinkedRelatedField(view_name='user-detail') |
| 136 | role = serializers.HyperlinkedRelatedField(view_name='role-detail') |
| 137 | class Meta: |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 138 | model = SlicePrivilege |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 139 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 140 | 'url', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 141 | 'user', |
| 142 | 'slice', |
| 143 | 'role') |
| 144 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 145 | class SiteSerializer(serializers.HyperlinkedModelSerializer): |
| 146 | |
| 147 | #Experimenting with whether to use ids, hyperlinks, or nested includes |
| 148 | #slices = serializers.PrimaryKeyRelatedField(many=True, read_only=True) |
| 149 | #slices = serializers.RelatedField(many=True, read_only=True) |
| 150 | #slices = SliceSerializer(many=True) |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 151 | # HyperlinkedModelSerializer doesn't include the id by default |
| 152 | id = serializers.Field() |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 153 | slices = serializers.HyperlinkedRelatedField(many=True, read_only=True,view_name='slice-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 154 | |
| 155 | class Meta: |
| 156 | model = Site |
Tony Mack | 879d14a | 2013-04-09 09:34:19 -0400 | [diff] [blame] | 157 | fields = ('id', |
| 158 | 'url', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 159 | 'name', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 160 | 'slices', |
| 161 | 'site_url', |
| 162 | 'enabled', |
| 163 | 'longitude', |
| 164 | 'latitude', |
| 165 | 'login_base', |
Tony Mack | e87bffa | 2013-04-08 23:18:04 -0400 | [diff] [blame] | 166 | 'tenant_id', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 167 | 'is_public', |
| 168 | 'abbreviated_name', |
| 169 | 'updated', |
| 170 | 'created') |
| 171 | |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 172 | class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer): |
| 173 | id = serializers.Field() |
| 174 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
| 175 | user = serializers.HyperlinkedRelatedField(view_name='user-detail') |
| 176 | role = serializers.HyperlinkedRelatedField(view_name='role-detail') |
| 177 | class Meta: |
| 178 | model = SitePrivilege |
| 179 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 180 | 'url', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 181 | 'user', |
| 182 | 'site', |
| 183 | 'role') |
| 184 | |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 185 | class SliverSerializer(serializers.HyperlinkedModelSerializer): |
| 186 | # HyperlinkedModelSerializer doesn't include the id by default |
| 187 | id = serializers.Field() |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 188 | image = serializers.HyperlinkedRelatedField(view_name='image-detail') |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 189 | slice = serializers.HyperlinkedRelatedField(view_name='slice-detail') |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 190 | deploymentNetwork = serializers.HyperlinkedRelatedField(view_name='deployment-detail') |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 191 | node = serializers.HyperlinkedRelatedField(view_name='node-detail') |
| 192 | |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 193 | #slice = serializers.PrimaryKeyRelatedField(read_only=True) |
| 194 | |
| 195 | class Meta: |
| 196 | model = Sliver |
| 197 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 198 | 'url', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 199 | 'instance_id', |
Tony Mack | 5d6598c | 2013-04-12 12:45:02 -0400 | [diff] [blame] | 200 | 'name', |
Tony Mack | 7974861 | 2013-05-01 14:52:03 -0400 | [diff] [blame] | 201 | 'instance_name', |
Tony Mack | d90cdbf | 2013-04-16 22:48:40 -0400 | [diff] [blame] | 202 | 'ip', |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 203 | 'image', |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 204 | 'slice', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 205 | 'deploymentNetwork', |
Tony Mack | 5d6598c | 2013-04-12 12:45:02 -0400 | [diff] [blame] | 206 | 'node') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 207 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 208 | class UserSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 209 | # HyperlinkedModelSerializer doesn't include the id by default |
| 210 | id = serializers.Field() |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 211 | site = serializers.HyperlinkedRelatedField(view_name='site-detail') |
| 212 | slice_privileges = serializers.HyperlinkedRelatedField(view_name='sliceprivilege-detail') |
| 213 | site_privileges = serializers.HyperlinkedRelatedField(view_name='siteprivilege-detail') |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 214 | class Meta: |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 215 | model = User |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 216 | fields = ('id', |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 217 | 'url', |
| 218 | 'kuser_id', |
| 219 | 'firstname', |
| 220 | 'lastname', |
| 221 | 'email', |
| 222 | 'password', |
| 223 | 'phone', |
| 224 | 'public_key', |
| 225 | 'user_url', |
| 226 | 'is_admin', |
| 227 | 'slice_privileges', |
| 228 | 'site_privileges') |
| 229 | |
| 230 | class TagSerializer(serializers.HyperlinkedModelSerializer): |
Tony Mack | a2dfb37 | 2013-04-09 11:02:32 -0400 | [diff] [blame] | 231 | # HyperlinkedModelSerializer doesn't include the id by default |
| 232 | id = serializers.Field() |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 233 | project = serializers.HyperlinkedRelatedField(view_name='project-detail') |
| 234 | #content_type = serializers.PrimaryKeyRelatedField(read_only=True) |
| 235 | content_type = serializers.RelatedField(source = "content_type") |
| 236 | content_object = serializers.RelatedField(source='content_object') |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 237 | class Meta: |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 238 | model = Tag |
| 239 | fields = ('id', |
| 240 | 'url', |
| 241 | 'project', |
| 242 | 'value', |
| 243 | 'content_type', |
| 244 | 'object_id', |
| 245 | 'content_object', |
| 246 | 'name') |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 247 | |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 248 | serializerLookUp = { |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 249 | Deployment: DeploymentSerializer, |
| 250 | Image: ImageSerializer, |
| 251 | Node: NodeSerializer, |
| 252 | Project: ProjectSerializer, |
| 253 | Reservation: ReservationSerializer, |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 254 | Role: RoleSerializer, |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 255 | ServiceClass: ServiceClassSerializer, |
| 256 | ServiceResource: ServiceResourceSerializer, |
Tony Mack | a28f1cd | 2013-04-07 20:02:31 -0400 | [diff] [blame] | 257 | Site: SiteSerializer, |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 258 | SitePrivilege: SitePrivilegeSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 259 | Slice: SliceSerializer, |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 260 | SlicePrivilege: SlicePrivilegeSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 261 | Sliver: SliverSerializer, |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 262 | Tag: TagSerializer, |
| 263 | User: UserSerializer, |
Tony Mack | 7130ac3 | 2013-03-22 21:58:00 -0400 | [diff] [blame] | 264 | None: None, |
| 265 | } |
Tony Mack | 5331008 | 2013-04-09 09:26:12 -0400 | [diff] [blame] | 266 | |