HPC service does not support deletion
[plstackapi.git] / planetstack / genapi.py
1 from rest_framework.decorators import api_view
2 from rest_framework.response import Response
3 from rest_framework.reverse import reverse
4 from rest_framework import serializers
5 from rest_framework import generics
6 from core.models import *
7 from django.forms import widgets
8
9 """
10         Schema of the generator object:
11                 all: Set of all Model objects
12                 all_if(regex): Set of Model objects that match regex
13         
14         Model object:
15                 plural: English plural of object name
16                 camel: CamelCase version of object name
17                 refs: list of references to other Model objects
18                 props: list of properties minus refs
19
20         TODO: Deal with subnets
21 """
22
23 # Based on api_root.py
24
25 @api_view(['GET'])
26 def api_root(request, format=None):
27     return Response({
28                 'serviceattributes': reverse('serviceattribute-list', request=request, format=format),
29                 'images': reverse('image-list', request=request, format=format),
30                 'networkparameters': reverse('networkparameter-list', request=request, format=format),
31                 'sites': reverse('site-list', request=request, format=format),
32                 'sliceroles': reverse('slicerole-list', request=request, format=format),
33                 'tags': reverse('tag-list', request=request, format=format),
34                 'invoices': reverse('invoice-list', request=request, format=format),
35                 'planetstackroles': reverse('planetstackrole-list', request=request, format=format),
36                 'sliceprivileges': reverse('sliceprivilege-list', request=request, format=format),
37                 'networkslivers': reverse('networksliver-list', request=request, format=format),
38                 'networkdeploymentses': reverse('networkdeployments-list', request=request, format=format),
39                 'slices': reverse('slice-list', request=request, format=format),
40                 'networks': reverse('network-list', request=request, format=format),
41                 'services': reverse('service-list', request=request, format=format),
42                 'serviceclasses': reverse('serviceclass-list', request=request, format=format),
43                 'payments': reverse('payment-list', request=request, format=format),
44                 'charges': reverse('charge-list', request=request, format=format),
45                 'roles': reverse('role-list', request=request, format=format),
46                 'usableobjects': reverse('usableobject-list', request=request, format=format),
47                 'siteroles': reverse('siterole-list', request=request, format=format),
48                 'slivers': reverse('sliver-list', request=request, format=format),
49                 'nodes': reverse('node-list', request=request, format=format),
50                 'dashboardviews': reverse('dashboardview-list', request=request, format=format),
51                 'imagedeploymentses': reverse('imagedeployments-list', request=request, format=format),
52                 'reservedresources': reverse('reservedresource-list', request=request, format=format),
53                 'networkslices': reverse('networkslice-list', request=request, format=format),
54                 'userdashboardviews': reverse('userdashboardview-list', request=request, format=format),
55                 'planetstackprivileges': reverse('planetstackprivilege-list', request=request, format=format),
56                 'users': reverse('user-list', request=request, format=format),
57                 'deployments': reverse('deployment-list', request=request, format=format),
58                 'reservations': reverse('reservation-list', request=request, format=format),
59                 'slicedeploymentses': reverse('slicedeployments-list', request=request, format=format),
60                 'siteprivileges': reverse('siteprivilege-list', request=request, format=format),
61                 'planetstacks': reverse('planetstack-list', request=request, format=format),
62                 'userdeploymentses': reverse('userdeployments-list', request=request, format=format),
63                 'accounts': reverse('account-list', request=request, format=format),
64                 'networkparametertypes': reverse('networkparametertype-list', request=request, format=format),
65                 'sitedeploymentses': reverse('sitedeployments-list', request=request, format=format),
66                 'deploymentprivileges': reverse('deploymentprivilege-list', request=request, format=format),
67                 'deploymentroles': reverse('deploymentrole-list', request=request, format=format),
68                 'projects': reverse('project-list', request=request, format=format),
69                 'slicetags': reverse('slicetag-list', request=request, format=format),
70                 'networktemplates': reverse('networktemplate-list', request=request, format=format),
71                 'routers': reverse('router-list', request=request, format=format),
72                 'serviceresources': reverse('serviceresource-list', request=request, format=format),
73                 
74     })
75
76 # Based on serializers.py
77
78
79
80 class ServiceAttributeSerializer(serializers.HyperlinkedModelSerializer):
81         id = serializers.Field()
82         
83         class Meta:
84                 model = ServiceAttribute
85                 fields = ('id','created','updated','enacted','name','value','service',)
86
87
88 class ImageSerializer(serializers.HyperlinkedModelSerializer):
89         id = serializers.Field()
90         
91         class Meta:
92                 model = Image
93                 fields = ('id','created','updated','enacted','name','disk_format','container_format','path',)
94
95
96 class NetworkParameterSerializer(serializers.HyperlinkedModelSerializer):
97         id = serializers.Field()
98         
99         class Meta:
100                 model = NetworkParameter
101                 fields = ('id','created','updated','enacted','parameter','value','content_type','object_id',)
102
103
104 class SiteSerializer(serializers.HyperlinkedModelSerializer):
105         id = serializers.Field()
106         
107         class Meta:
108                 model = Site
109                 fields = ('id','created','updated','enacted','name','site_url','enabled','location','longitude','latitude','login_base','is_public','abbreviated_name',)
110
111
112 class SliceRoleSerializer(serializers.HyperlinkedModelSerializer):
113         id = serializers.Field()
114         
115         class Meta:
116                 model = SliceRole
117                 fields = ('id','created','updated','enacted','role',)
118
119
120 class TagSerializer(serializers.HyperlinkedModelSerializer):
121         id = serializers.Field()
122         
123         
124         sites = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='site-detail')
125         
126         
127         
128         slices = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='slice-detail')
129         
130         
131         
132         slivers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='sliver-detail')
133         
134         
135         
136         nodes = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='node-detail')
137         
138         
139         class Meta:
140                 model = Tag
141                 fields = ('id','created','updated','enacted','service','name','value','content_type','object_id','sites','slices','slivers','nodes',)
142
143
144 class InvoiceSerializer(serializers.HyperlinkedModelSerializer):
145         id = serializers.Field()
146         
147         class Meta:
148                 model = Invoice
149                 fields = ('id','created','updated','enacted','date','account',)
150
151
152 class PlanetStackRoleSerializer(serializers.HyperlinkedModelSerializer):
153         id = serializers.Field()
154         
155         class Meta:
156                 model = PlanetStackRole
157                 fields = ('id','created','updated','enacted','role',)
158
159
160 class SlicePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
161         id = serializers.Field()
162         
163         class Meta:
164                 model = SlicePrivilege
165                 fields = ('id','created','updated','enacted','user','slice','role',)
166
167
168 class NetworkSliverSerializer(serializers.HyperlinkedModelSerializer):
169         id = serializers.Field()
170         
171         class Meta:
172                 model = NetworkSliver
173                 fields = ('id','created','updated','enacted','network','sliver','ip','port_id',)
174
175
176 class NetworkDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
177         id = serializers.Field()
178         
179         class Meta:
180                 model = NetworkDeployments
181                 fields = ('id','created','updated','enacted','network','deployment','net_id','router_id','subnet_id','subnet',)
182
183
184 class SliceSerializer(serializers.HyperlinkedModelSerializer):
185         id = serializers.Field()
186         
187         
188         networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
189         
190         
191         
192         availableNetworks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
193         
194         
195         
196         networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
197         
198         
199         
200         networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
201         
202         
203         class Meta:
204                 model = Slice
205                 fields = ('id','created','updated','enacted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','imagePreference','service','network','mountDataSets','serviceClass','creator','networks','availableNetworks','networks','networks',)
206
207
208 class NetworkSerializer(serializers.HyperlinkedModelSerializer):
209         id = serializers.Field()
210         
211         
212         routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
213         
214         
215         
216         availableRouters = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
217         
218         
219         
220         routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
221         
222         
223         
224         routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
225         
226         
227         class Meta:
228                 model = Network
229                 fields = ('id','created','updated','enacted','name','template','subnet','ports','labels','owner','guaranteedBandwidth','permitAllSlices','network_id','router_id','subnet_id','routers','availableRouters','routers','routers',)
230
231
232 class ServiceSerializer(serializers.HyperlinkedModelSerializer):
233         id = serializers.Field()
234         
235         class Meta:
236                 model = Service
237                 fields = ('id','created','updated','enacted','description','enabled','name','versionNumber','published',)
238
239
240 class ServiceClassSerializer(serializers.HyperlinkedModelSerializer):
241         id = serializers.Field()
242         
243         class Meta:
244                 model = ServiceClass
245                 fields = ('id','created','updated','enacted','name','description','commitment','membershipFee','membershipFeeMonths','upgradeRequiresApproval',)
246
247
248 class PaymentSerializer(serializers.HyperlinkedModelSerializer):
249         id = serializers.Field()
250         
251         class Meta:
252                 model = Payment
253                 fields = ('id','created','updated','enacted','account','amount','date',)
254
255
256 class ChargeSerializer(serializers.HyperlinkedModelSerializer):
257         id = serializers.Field()
258         
259         class Meta:
260                 model = Charge
261                 fields = ('id','created','updated','enacted','account','slice','kind','state','date','object','amount','coreHours','invoice',)
262
263
264 class RoleSerializer(serializers.HyperlinkedModelSerializer):
265         id = serializers.Field()
266         
267         class Meta:
268                 model = Role
269                 fields = ('id','created','updated','enacted','role_type','role','description','content_type',)
270
271
272 class UsableObjectSerializer(serializers.HyperlinkedModelSerializer):
273         id = serializers.Field()
274         
275         class Meta:
276                 model = UsableObject
277                 fields = ('id','created','updated','enacted','name',)
278
279
280 class SiteRoleSerializer(serializers.HyperlinkedModelSerializer):
281         id = serializers.Field()
282         
283         class Meta:
284                 model = SiteRole
285                 fields = ('id','created','updated','enacted','role',)
286
287
288 class SliverSerializer(serializers.HyperlinkedModelSerializer):
289         id = serializers.Field()
290         
291         
292         networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
293         
294         
295         
296         networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
297         
298         
299         
300 #       upgradeFrom_rel_+ = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='serviceclass-detail')
301         
302         
303         class Meta:
304                 model = Sliver
305                 fields = ('id','created','updated','enacted','instance_id','name','instance_name','ip','image','creator','slice','node','deploymentNetwork','numberCores','userData','networks','networks','upgradeFrom_rel_+',)
306
307
308 class NodeSerializer(serializers.HyperlinkedModelSerializer):
309         id = serializers.Field()
310         
311         class Meta:
312                 model = Node
313                 fields = ('id','created','updated','enacted','name','site','deployment',)
314
315
316 class DashboardViewSerializer(serializers.HyperlinkedModelSerializer):
317         id = serializers.Field()
318         
319         class Meta:
320                 model = DashboardView
321                 fields = ('id','created','updated','enacted','name','url',)
322
323
324 class ImageDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
325         id = serializers.Field()
326         
327         class Meta:
328                 model = ImageDeployments
329                 fields = ('id','created','updated','enacted','image','deployment','glance_image_id',)
330
331
332 class ReservedResourceSerializer(serializers.HyperlinkedModelSerializer):
333         id = serializers.Field()
334         
335         class Meta:
336                 model = ReservedResource
337                 fields = ('id','created','updated','enacted','sliver','resource','quantity','reservationSet',)
338
339
340 class NetworkSliceSerializer(serializers.HyperlinkedModelSerializer):
341         id = serializers.Field()
342         
343         class Meta:
344                 model = NetworkSlice
345                 fields = ('id','created','updated','enacted','network','slice',)
346
347
348 class UserDashboardViewSerializer(serializers.HyperlinkedModelSerializer):
349         id = serializers.Field()
350         
351         class Meta:
352                 model = UserDashboardView
353                 fields = ('id','created','updated','enacted','user','dashboardView','order',)
354
355
356 class PlanetStackPrivilegeSerializer(serializers.HyperlinkedModelSerializer):
357         id = serializers.Field()
358         
359         class Meta:
360                 model = PlanetStackPrivilege
361                 fields = ('id','created','updated','enacted','user','planetstack','role',)
362
363
364 class UserSerializer(serializers.HyperlinkedModelSerializer):
365         id = serializers.Field()
366         
367         class Meta:
368                 model = User
369                 fields = ('id','password','last_login','email','username','firstname','lastname','phone','user_url','site','public_key','is_active','is_admin','is_staff','is_readonly','created','updated','enacted','timezone',)
370
371
372 class DeploymentSerializer(serializers.HyperlinkedModelSerializer):
373         id = serializers.Field()
374         
375         
376         sites = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='site-detail')
377         
378         
379         
380         sites = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='site-detail')
381         
382         
383         class Meta:
384                 model = Deployment
385                 fields = ('id','created','updated','enacted','name','admin_user','admin_password','admin_tenant','auth_url','accessControl','sites','sites',)
386
387
388 class ReservationSerializer(serializers.HyperlinkedModelSerializer):
389         id = serializers.Field()
390         
391         class Meta:
392                 model = Reservation
393                 fields = ('id','created','updated','enacted','startTime','slice','duration',)
394
395
396 class SliceDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
397         id = serializers.Field()
398         
399         class Meta:
400                 model = SliceDeployments
401                 fields = ('id','created','updated','enacted','slice','deployment','tenant_id','network_id','router_id','subnet_id',)
402
403
404 class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
405         id = serializers.Field()
406         
407         class Meta:
408                 model = SitePrivilege
409                 fields = ('id','created','updated','enacted','user','site','role',)
410
411
412 class PlanetStackSerializer(serializers.HyperlinkedModelSerializer):
413         id = serializers.Field()
414         
415         class Meta:
416                 model = PlanetStack
417                 fields = ('id','created','updated','enacted','description',)
418
419
420 class UserDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
421         id = serializers.Field()
422         
423         class Meta:
424                 model = UserDeployments
425                 fields = ('id','created','updated','enacted','user','deployment','kuser_id',)
426
427
428 class AccountSerializer(serializers.HyperlinkedModelSerializer):
429         id = serializers.Field()
430         
431         class Meta:
432                 model = Account
433                 fields = ('id','created','updated','enacted','site',)
434
435
436 class NetworkParameterTypeSerializer(serializers.HyperlinkedModelSerializer):
437         id = serializers.Field()
438         
439         class Meta:
440                 model = NetworkParameterType
441                 fields = ('id','created','updated','enacted','name','description',)
442
443
444 class SiteDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
445         id = serializers.Field()
446         
447         class Meta:
448                 model = SiteDeployments
449                 fields = ('id','created','updated','enacted','site','deployment','tenant_id',)
450
451
452 class DeploymentPrivilegeSerializer(serializers.HyperlinkedModelSerializer):
453         id = serializers.Field()
454         
455         class Meta:
456                 model = DeploymentPrivilege
457                 fields = ('id','created','updated','enacted','user','deployment','role',)
458
459
460 class DeploymentRoleSerializer(serializers.HyperlinkedModelSerializer):
461         id = serializers.Field()
462         
463         class Meta:
464                 model = DeploymentRole
465                 fields = ('id','created','updated','enacted','role',)
466
467
468 class ProjectSerializer(serializers.HyperlinkedModelSerializer):
469         id = serializers.Field()
470         
471         class Meta:
472                 model = Project
473                 fields = ('id','created','updated','enacted','name',)
474
475
476 class SliceTagSerializer(serializers.HyperlinkedModelSerializer):
477         id = serializers.Field()
478         
479         class Meta:
480                 model = SliceTag
481                 fields = ('id','created','updated','enacted','slice','name','value',)
482
483
484 class NetworkTemplateSerializer(serializers.HyperlinkedModelSerializer):
485         id = serializers.Field()
486         
487         class Meta:
488                 model = NetworkTemplate
489                 fields = ('id','created','updated','enacted','name','description','guaranteedBandwidth','visibility','translation','sharedNetworkName','sharedNetworkId',)
490
491
492 class RouterSerializer(serializers.HyperlinkedModelSerializer):
493         id = serializers.Field()
494         
495         class Meta:
496                 model = Router
497                 fields = ('id','created','updated','enacted','name','owner',)
498
499
500 class ServiceResourceSerializer(serializers.HyperlinkedModelSerializer):
501         id = serializers.Field()
502         
503         class Meta:
504                 model = ServiceResource
505                 fields = ('id','created','updated','enacted','serviceClass','name','maxUnitsDeployment','maxUnitsNode','maxDuration','bucketInRate','bucketMaxSize','cost','calendarReservable',)
506
507
508 serializerLookUp = { 
509
510                  ServiceAttribute: ServiceAttributeSerializer,
511
512                  Image: ImageSerializer,
513
514                  NetworkParameter: NetworkParameterSerializer,
515
516                  Site: SiteSerializer,
517
518                  SliceRole: SliceRoleSerializer,
519
520                  Tag: TagSerializer,
521
522                  Invoice: InvoiceSerializer,
523
524                  PlanetStackRole: PlanetStackRoleSerializer,
525
526                  SlicePrivilege: SlicePrivilegeSerializer,
527
528                  NetworkSliver: NetworkSliverSerializer,
529
530                  NetworkDeployments: NetworkDeploymentsSerializer,
531
532                  Slice: SliceSerializer,
533
534                  Network: NetworkSerializer,
535
536                  Service: ServiceSerializer,
537
538                  ServiceClass: ServiceClassSerializer,
539
540                  Payment: PaymentSerializer,
541
542                  Charge: ChargeSerializer,
543
544                  Role: RoleSerializer,
545
546                  UsableObject: UsableObjectSerializer,
547
548                  SiteRole: SiteRoleSerializer,
549
550                  Sliver: SliverSerializer,
551
552                  Node: NodeSerializer,
553
554                  DashboardView: DashboardViewSerializer,
555
556                  ImageDeployments: ImageDeploymentsSerializer,
557
558                  ReservedResource: ReservedResourceSerializer,
559
560                  NetworkSlice: NetworkSliceSerializer,
561
562                  UserDashboardView: UserDashboardViewSerializer,
563
564                  PlanetStackPrivilege: PlanetStackPrivilegeSerializer,
565
566                  User: UserSerializer,
567
568                  Deployment: DeploymentSerializer,
569
570                  Reservation: ReservationSerializer,
571
572                  SliceDeployments: SliceDeploymentsSerializer,
573
574                  SitePrivilege: SitePrivilegeSerializer,
575
576                  PlanetStack: PlanetStackSerializer,
577
578                  UserDeployments: UserDeploymentsSerializer,
579
580                  Account: AccountSerializer,
581
582                  NetworkParameterType: NetworkParameterTypeSerializer,
583
584                  SiteDeployments: SiteDeploymentsSerializer,
585
586                  DeploymentPrivilege: DeploymentPrivilegeSerializer,
587
588                  DeploymentRole: DeploymentRoleSerializer,
589
590                  Project: ProjectSerializer,
591
592                  SliceTag: SliceTagSerializer,
593
594                  NetworkTemplate: NetworkTemplateSerializer,
595
596                  Router: RouterSerializer,
597
598                  ServiceResource: ServiceResourceSerializer,
599
600                  None: None,
601                 }
602
603 # Based on core/views/*.py
604
605
606 class ServiceAttributeList(generics.ListCreateAPIView):
607     queryset = ServiceAttribute.objects.select_related().all()
608     serializer_class = ServiceAttributeSerializer
609     
610     def get_queryset(self):
611         return ServiceAttribute.select_by_user(self.request.user)
612
613     def create(self, request, *args, **kwargs):
614         #obj = ServiceAttribute().update(request.DATA)
615         obj = self.get_object()
616         obj.caller = request.user
617         if obj.can_update(request.user):
618             return super(ServiceAttributeList, self).create(request, *args, **kwargs)
619         else:
620             return Response(status=status.HTTP_400_BAD_REQUEST)
621
622 class ServiceAttributeDetail(generics.RetrieveUpdateDestroyAPIView):
623     queryset = ServiceAttribute.objects.select_related().all()
624     serializer_class = ServiceAttributeSerializer
625     
626     def get_queryset(self):
627         return ServiceAttribute.select_by_user(self.request.user)
628
629     def update(self, request, *args, **kwargs):
630         obj = self.get_object()
631         if obj.can_update(request.user):
632             return super(ServiceAttributeDetail, self).update(request, *args, **kwargs)
633         else:
634             return Response(status=status.HTTP_400_BAD_REQUEST)
635
636     def destroy(self, request, *args, **kwargs):
637         obj = self.get_object()
638         if obj.can_update(request.user):
639             return super(ServiceAttributeDetail, self).destroy(request, *args, **kwargs)
640         else:
641             return Response(status=status.HTTP_400_BAD_REQUEST)
642      
643
644
645
646 class ImageList(generics.ListCreateAPIView):
647     queryset = Image.objects.select_related().all()
648     serializer_class = ImageSerializer
649     
650     def get_queryset(self):
651         return Image.select_by_user(self.request.user)
652
653     def create(self, request, *args, **kwargs):
654         #obj = Image().update(request.DATA)
655         obj = self.get_object()
656         obj.caller = request.user
657         if obj.can_update(request.user):
658             return super(ImageList, self).create(request, *args, **kwargs)
659         else:
660             return Response(status=status.HTTP_400_BAD_REQUEST)
661
662 class ImageDetail(generics.RetrieveUpdateDestroyAPIView):
663     queryset = Image.objects.select_related().all()
664     serializer_class = ImageSerializer
665     
666     def get_queryset(self):
667         return Image.select_by_user(self.request.user)
668
669     def update(self, request, *args, **kwargs):
670         obj = self.get_object()
671         if obj.can_update(request.user):
672             return super(ImageDetail, self).update(request, *args, **kwargs)
673         else:
674             return Response(status=status.HTTP_400_BAD_REQUEST)
675
676     def destroy(self, request, *args, **kwargs):
677         obj = self.get_object()
678         if obj.can_update(request.user):
679             return super(ImageDetail, self).destroy(request, *args, **kwargs)
680         else:
681             return Response(status=status.HTTP_400_BAD_REQUEST)
682      
683
684
685
686 class NetworkParameterList(generics.ListCreateAPIView):
687     queryset = NetworkParameter.objects.select_related().all()
688     serializer_class = NetworkParameterSerializer
689     
690     def get_queryset(self):
691         return NetworkParameter.select_by_user(self.request.user)
692
693     def create(self, request, *args, **kwargs):
694         #obj = NetworkParameter().update(request.DATA)
695         obj = self.get_object()
696         obj.caller = request.user
697         if obj.can_update(request.user):
698             return super(NetworkParameterList, self).create(request, *args, **kwargs)
699         else:
700             return Response(status=status.HTTP_400_BAD_REQUEST)
701
702 class NetworkParameterDetail(generics.RetrieveUpdateDestroyAPIView):
703     queryset = NetworkParameter.objects.select_related().all()
704     serializer_class = NetworkParameterSerializer
705     
706     def get_queryset(self):
707         return NetworkParameter.select_by_user(self.request.user)
708
709     def update(self, request, *args, **kwargs):
710         obj = self.get_object()
711         if obj.can_update(request.user):
712             return super(NetworkParameterDetail, self).update(request, *args, **kwargs)
713         else:
714             return Response(status=status.HTTP_400_BAD_REQUEST)
715
716     def destroy(self, request, *args, **kwargs):
717         obj = self.get_object()
718         if obj.can_update(request.user):
719             return super(NetworkParameterDetail, self).destroy(request, *args, **kwargs)
720         else:
721             return Response(status=status.HTTP_400_BAD_REQUEST)
722      
723
724
725
726 class SiteList(generics.ListCreateAPIView):
727     queryset = Site.objects.select_related().all()
728     serializer_class = SiteSerializer
729     
730     def get_queryset(self):
731         return Site.select_by_user(self.request.user)
732
733     def create(self, request, *args, **kwargs):
734         #obj = Site().update(request.DATA)
735         obj = self.get_object()
736         obj.caller = request.user
737         if obj.can_update(request.user):
738             return super(SiteList, self).create(request, *args, **kwargs)
739         else:
740             return Response(status=status.HTTP_400_BAD_REQUEST)
741
742 class SiteDetail(generics.RetrieveUpdateDestroyAPIView):
743     queryset = Site.objects.select_related().all()
744     serializer_class = SiteSerializer
745     
746     def get_queryset(self):
747         return Site.select_by_user(self.request.user)
748
749     def update(self, request, *args, **kwargs):
750         obj = self.get_object()
751         if obj.can_update(request.user):
752             return super(SiteDetail, self).update(request, *args, **kwargs)
753         else:
754             return Response(status=status.HTTP_400_BAD_REQUEST)
755
756     def destroy(self, request, *args, **kwargs):
757         obj = self.get_object()
758         if obj.can_update(request.user):
759             return super(SiteDetail, self).destroy(request, *args, **kwargs)
760         else:
761             return Response(status=status.HTTP_400_BAD_REQUEST)
762      
763
764
765
766 class SliceRoleList(generics.ListCreateAPIView):
767     queryset = SliceRole.objects.select_related().all()
768     serializer_class = SliceRoleSerializer
769     
770     def get_queryset(self):
771         return SliceRole.select_by_user(self.request.user)
772
773     def create(self, request, *args, **kwargs):
774         #obj = SliceRole().update(request.DATA)
775         obj = self.get_object()
776         obj.caller = request.user
777         if obj.can_update(request.user):
778             return super(SliceRoleList, self).create(request, *args, **kwargs)
779         else:
780             return Response(status=status.HTTP_400_BAD_REQUEST)
781
782 class SliceRoleDetail(generics.RetrieveUpdateDestroyAPIView):
783     queryset = SliceRole.objects.select_related().all()
784     serializer_class = SliceRoleSerializer
785     
786     def get_queryset(self):
787         return SliceRole.select_by_user(self.request.user)
788
789     def update(self, request, *args, **kwargs):
790         obj = self.get_object()
791         if obj.can_update(request.user):
792             return super(SliceRoleDetail, self).update(request, *args, **kwargs)
793         else:
794             return Response(status=status.HTTP_400_BAD_REQUEST)
795
796     def destroy(self, request, *args, **kwargs):
797         obj = self.get_object()
798         if obj.can_update(request.user):
799             return super(SliceRoleDetail, self).destroy(request, *args, **kwargs)
800         else:
801             return Response(status=status.HTTP_400_BAD_REQUEST)
802      
803
804
805
806 class TagList(generics.ListCreateAPIView):
807     queryset = Tag.objects.select_related().all()
808     serializer_class = TagSerializer
809     
810     def get_queryset(self):
811         return Tag.select_by_user(self.request.user)
812
813     def create(self, request, *args, **kwargs):
814         #obj = Tag().update(request.DATA)
815         obj = self.get_object()
816         obj.caller = request.user
817         if obj.can_update(request.user):
818             return super(TagList, self).create(request, *args, **kwargs)
819         else:
820             return Response(status=status.HTTP_400_BAD_REQUEST)
821
822 class TagDetail(generics.RetrieveUpdateDestroyAPIView):
823     queryset = Tag.objects.select_related().all()
824     serializer_class = TagSerializer
825     
826     def get_queryset(self):
827         return Tag.select_by_user(self.request.user)
828
829     def update(self, request, *args, **kwargs):
830         obj = self.get_object()
831         if obj.can_update(request.user):
832             return super(TagDetail, self).update(request, *args, **kwargs)
833         else:
834             return Response(status=status.HTTP_400_BAD_REQUEST)
835
836     def destroy(self, request, *args, **kwargs):
837         obj = self.get_object()
838         if obj.can_update(request.user):
839             return super(TagDetail, self).destroy(request, *args, **kwargs)
840         else:
841             return Response(status=status.HTTP_400_BAD_REQUEST)
842      
843
844
845
846 class InvoiceList(generics.ListCreateAPIView):
847     queryset = Invoice.objects.select_related().all()
848     serializer_class = InvoiceSerializer
849     
850     def get_queryset(self):
851         return Invoice.select_by_user(self.request.user)
852
853     def create(self, request, *args, **kwargs):
854         #obj = Invoice().update(request.DATA)
855         obj = self.get_object()
856         obj.caller = request.user
857         if obj.can_update(request.user):
858             return super(InvoiceList, self).create(request, *args, **kwargs)
859         else:
860             return Response(status=status.HTTP_400_BAD_REQUEST)
861
862 class InvoiceDetail(generics.RetrieveUpdateDestroyAPIView):
863     queryset = Invoice.objects.select_related().all()
864     serializer_class = InvoiceSerializer
865     
866     def get_queryset(self):
867         return Invoice.select_by_user(self.request.user)
868
869     def update(self, request, *args, **kwargs):
870         obj = self.get_object()
871         if obj.can_update(request.user):
872             return super(InvoiceDetail, self).update(request, *args, **kwargs)
873         else:
874             return Response(status=status.HTTP_400_BAD_REQUEST)
875
876     def destroy(self, request, *args, **kwargs):
877         obj = self.get_object()
878         if obj.can_update(request.user):
879             return super(InvoiceDetail, self).destroy(request, *args, **kwargs)
880         else:
881             return Response(status=status.HTTP_400_BAD_REQUEST)
882      
883
884
885
886 class PlanetStackRoleList(generics.ListCreateAPIView):
887     queryset = PlanetStackRole.objects.select_related().all()
888     serializer_class = PlanetStackRoleSerializer
889     
890     def get_queryset(self):
891         return PlanetStackRole.select_by_user(self.request.user)
892
893     def create(self, request, *args, **kwargs):
894         #obj = PlanetStackRole().update(request.DATA)
895         obj = self.get_object()
896         obj.caller = request.user
897         if obj.can_update(request.user):
898             return super(PlanetStackRoleList, self).create(request, *args, **kwargs)
899         else:
900             return Response(status=status.HTTP_400_BAD_REQUEST)
901
902 class PlanetStackRoleDetail(generics.RetrieveUpdateDestroyAPIView):
903     queryset = PlanetStackRole.objects.select_related().all()
904     serializer_class = PlanetStackRoleSerializer
905     
906     def get_queryset(self):
907         return PlanetStackRole.select_by_user(self.request.user)
908
909     def update(self, request, *args, **kwargs):
910         obj = self.get_object()
911         if obj.can_update(request.user):
912             return super(PlanetStackRoleDetail, self).update(request, *args, **kwargs)
913         else:
914             return Response(status=status.HTTP_400_BAD_REQUEST)
915
916     def destroy(self, request, *args, **kwargs):
917         obj = self.get_object()
918         if obj.can_update(request.user):
919             return super(PlanetStackRoleDetail, self).destroy(request, *args, **kwargs)
920         else:
921             return Response(status=status.HTTP_400_BAD_REQUEST)
922      
923
924
925
926 class SlicePrivilegeList(generics.ListCreateAPIView):
927     queryset = SlicePrivilege.objects.select_related().all()
928     serializer_class = SlicePrivilegeSerializer
929     
930     def get_queryset(self):
931         return SlicePrivilege.select_by_user(self.request.user)
932
933     def create(self, request, *args, **kwargs):
934         #obj = SlicePrivilege().update(request.DATA)
935         obj = self.get_object()
936         obj.caller = request.user
937         if obj.can_update(request.user):
938             return super(SlicePrivilegeList, self).create(request, *args, **kwargs)
939         else:
940             return Response(status=status.HTTP_400_BAD_REQUEST)
941
942 class SlicePrivilegeDetail(generics.RetrieveUpdateDestroyAPIView):
943     queryset = SlicePrivilege.objects.select_related().all()
944     serializer_class = SlicePrivilegeSerializer
945     
946     def get_queryset(self):
947         return SlicePrivilege.select_by_user(self.request.user)
948
949     def update(self, request, *args, **kwargs):
950         obj = self.get_object()
951         if obj.can_update(request.user):
952             return super(SlicePrivilegeDetail, self).update(request, *args, **kwargs)
953         else:
954             return Response(status=status.HTTP_400_BAD_REQUEST)
955
956     def destroy(self, request, *args, **kwargs):
957         obj = self.get_object()
958         if obj.can_update(request.user):
959             return super(SlicePrivilegeDetail, self).destroy(request, *args, **kwargs)
960         else:
961             return Response(status=status.HTTP_400_BAD_REQUEST)
962      
963
964
965
966 class NetworkSliverList(generics.ListCreateAPIView):
967     queryset = NetworkSliver.objects.select_related().all()
968     serializer_class = NetworkSliverSerializer
969     
970     def get_queryset(self):
971         return NetworkSliver.select_by_user(self.request.user)
972
973     def create(self, request, *args, **kwargs):
974         #obj = NetworkSliver().update(request.DATA)
975         obj = self.get_object()
976         obj.caller = request.user
977         if obj.can_update(request.user):
978             return super(NetworkSliverList, self).create(request, *args, **kwargs)
979         else:
980             return Response(status=status.HTTP_400_BAD_REQUEST)
981
982 class NetworkSliverDetail(generics.RetrieveUpdateDestroyAPIView):
983     queryset = NetworkSliver.objects.select_related().all()
984     serializer_class = NetworkSliverSerializer
985     
986     def get_queryset(self):
987         return NetworkSliver.select_by_user(self.request.user)
988
989     def update(self, request, *args, **kwargs):
990         obj = self.get_object()
991         if obj.can_update(request.user):
992             return super(NetworkSliverDetail, self).update(request, *args, **kwargs)
993         else:
994             return Response(status=status.HTTP_400_BAD_REQUEST)
995
996     def destroy(self, request, *args, **kwargs):
997         obj = self.get_object()
998         if obj.can_update(request.user):
999             return super(NetworkSliverDetail, self).destroy(request, *args, **kwargs)
1000         else:
1001             return Response(status=status.HTTP_400_BAD_REQUEST)
1002      
1003
1004
1005
1006 class NetworkDeploymentsList(generics.ListCreateAPIView):
1007     queryset = NetworkDeployments.objects.select_related().all()
1008     serializer_class = NetworkDeploymentsSerializer
1009     
1010     def get_queryset(self):
1011         return NetworkDeployments.select_by_user(self.request.user)
1012
1013     def create(self, request, *args, **kwargs):
1014         #obj = NetworkDeployments().update(request.DATA)
1015         obj = self.get_object()
1016         obj.caller = request.user
1017         if obj.can_update(request.user):
1018             return super(NetworkDeploymentsList, self).create(request, *args, **kwargs)
1019         else:
1020             return Response(status=status.HTTP_400_BAD_REQUEST)
1021
1022 class NetworkDeploymentsDetail(generics.RetrieveUpdateDestroyAPIView):
1023     queryset = NetworkDeployments.objects.select_related().all()
1024     serializer_class = NetworkDeploymentsSerializer
1025     
1026     def get_queryset(self):
1027         return NetworkDeployments.select_by_user(self.request.user)
1028
1029     def update(self, request, *args, **kwargs):
1030         obj = self.get_object()
1031         if obj.can_update(request.user):
1032             return super(NetworkDeploymentsDetail, self).update(request, *args, **kwargs)
1033         else:
1034             return Response(status=status.HTTP_400_BAD_REQUEST)
1035
1036     def destroy(self, request, *args, **kwargs):
1037         obj = self.get_object()
1038         if obj.can_update(request.user):
1039             return super(NetworkDeploymentsDetail, self).destroy(request, *args, **kwargs)
1040         else:
1041             return Response(status=status.HTTP_400_BAD_REQUEST)
1042      
1043
1044
1045
1046 class SliceList(generics.ListCreateAPIView):
1047     queryset = Slice.objects.select_related().all()
1048     serializer_class = SliceSerializer
1049     
1050     def get_queryset(self):
1051         return Slice.select_by_user(self.request.user)
1052
1053     def create(self, request, *args, **kwargs):
1054         #obj = Slice().update(request.DATA)
1055         obj = self.get_object()
1056         obj.caller = request.user
1057         if obj.can_update(request.user):
1058             return super(SliceList, self).create(request, *args, **kwargs)
1059         else:
1060             return Response(status=status.HTTP_400_BAD_REQUEST)
1061
1062 class SliceDetail(generics.RetrieveUpdateDestroyAPIView):
1063     queryset = Slice.objects.select_related().all()
1064     serializer_class = SliceSerializer
1065     
1066     def get_queryset(self):
1067         return Slice.select_by_user(self.request.user)
1068
1069     def update(self, request, *args, **kwargs):
1070         obj = self.get_object()
1071         if obj.can_update(request.user):
1072             return super(SliceDetail, self).update(request, *args, **kwargs)
1073         else:
1074             return Response(status=status.HTTP_400_BAD_REQUEST)
1075
1076     def destroy(self, request, *args, **kwargs):
1077         obj = self.get_object()
1078         if obj.can_update(request.user):
1079             return super(SliceDetail, self).destroy(request, *args, **kwargs)
1080         else:
1081             return Response(status=status.HTTP_400_BAD_REQUEST)
1082      
1083
1084
1085
1086 class NetworkList(generics.ListCreateAPIView):
1087     queryset = Network.objects.select_related().all()
1088     serializer_class = NetworkSerializer
1089     
1090     def get_queryset(self):
1091         return Network.select_by_user(self.request.user)
1092
1093     def create(self, request, *args, **kwargs):
1094         #obj = Network().update(request.DATA)
1095         obj = self.get_object()
1096         obj.caller = request.user
1097         if obj.can_update(request.user):
1098             return super(NetworkList, self).create(request, *args, **kwargs)
1099         else:
1100             return Response(status=status.HTTP_400_BAD_REQUEST)
1101
1102 class NetworkDetail(generics.RetrieveUpdateDestroyAPIView):
1103     queryset = Network.objects.select_related().all()
1104     serializer_class = NetworkSerializer
1105     
1106     def get_queryset(self):
1107         return Network.select_by_user(self.request.user)
1108
1109     def update(self, request, *args, **kwargs):
1110         obj = self.get_object()
1111         if obj.can_update(request.user):
1112             return super(NetworkDetail, self).update(request, *args, **kwargs)
1113         else:
1114             return Response(status=status.HTTP_400_BAD_REQUEST)
1115
1116     def destroy(self, request, *args, **kwargs):
1117         obj = self.get_object()
1118         if obj.can_update(request.user):
1119             return super(NetworkDetail, self).destroy(request, *args, **kwargs)
1120         else:
1121             return Response(status=status.HTTP_400_BAD_REQUEST)
1122      
1123
1124
1125
1126 class ServiceList(generics.ListCreateAPIView):
1127     queryset = Service.objects.select_related().all()
1128     serializer_class = ServiceSerializer
1129     
1130     def get_queryset(self):
1131         return Service.select_by_user(self.request.user)
1132
1133     def create(self, request, *args, **kwargs):
1134         #obj = Service().update(request.DATA)
1135         obj = self.get_object()
1136         obj.caller = request.user
1137         if obj.can_update(request.user):
1138             return super(ServiceList, self).create(request, *args, **kwargs)
1139         else:
1140             return Response(status=status.HTTP_400_BAD_REQUEST)
1141
1142 class ServiceDetail(generics.RetrieveUpdateDestroyAPIView):
1143     queryset = Service.objects.select_related().all()
1144     serializer_class = ServiceSerializer
1145     
1146     def get_queryset(self):
1147         return Service.select_by_user(self.request.user)
1148
1149     def update(self, request, *args, **kwargs):
1150         obj = self.get_object()
1151         if obj.can_update(request.user):
1152             return super(ServiceDetail, self).update(request, *args, **kwargs)
1153         else:
1154             return Response(status=status.HTTP_400_BAD_REQUEST)
1155
1156     def destroy(self, request, *args, **kwargs):
1157         obj = self.get_object()
1158         if obj.can_update(request.user):
1159             return super(ServiceDetail, self).destroy(request, *args, **kwargs)
1160         else:
1161             return Response(status=status.HTTP_400_BAD_REQUEST)
1162      
1163
1164
1165
1166 class ServiceClassList(generics.ListCreateAPIView):
1167     queryset = ServiceClass.objects.select_related().all()
1168     serializer_class = ServiceClassSerializer
1169     
1170     def get_queryset(self):
1171         return ServiceClass.select_by_user(self.request.user)
1172
1173     def create(self, request, *args, **kwargs):
1174         #obj = ServiceClass().update(request.DATA)
1175         obj = self.get_object()
1176         obj.caller = request.user
1177         if obj.can_update(request.user):
1178             return super(ServiceClassList, self).create(request, *args, **kwargs)
1179         else:
1180             return Response(status=status.HTTP_400_BAD_REQUEST)
1181
1182 class ServiceClassDetail(generics.RetrieveUpdateDestroyAPIView):
1183     queryset = ServiceClass.objects.select_related().all()
1184     serializer_class = ServiceClassSerializer
1185     
1186     def get_queryset(self):
1187         return ServiceClass.select_by_user(self.request.user)
1188
1189     def update(self, request, *args, **kwargs):
1190         obj = self.get_object()
1191         if obj.can_update(request.user):
1192             return super(ServiceClassDetail, self).update(request, *args, **kwargs)
1193         else:
1194             return Response(status=status.HTTP_400_BAD_REQUEST)
1195
1196     def destroy(self, request, *args, **kwargs):
1197         obj = self.get_object()
1198         if obj.can_update(request.user):
1199             return super(ServiceClassDetail, self).destroy(request, *args, **kwargs)
1200         else:
1201             return Response(status=status.HTTP_400_BAD_REQUEST)
1202      
1203
1204
1205
1206 class PaymentList(generics.ListCreateAPIView):
1207     queryset = Payment.objects.select_related().all()
1208     serializer_class = PaymentSerializer
1209     
1210     def get_queryset(self):
1211         return Payment.select_by_user(self.request.user)
1212
1213     def create(self, request, *args, **kwargs):
1214         #obj = Payment().update(request.DATA)
1215         obj = self.get_object()
1216         obj.caller = request.user
1217         if obj.can_update(request.user):
1218             return super(PaymentList, self).create(request, *args, **kwargs)
1219         else:
1220             return Response(status=status.HTTP_400_BAD_REQUEST)
1221
1222 class PaymentDetail(generics.RetrieveUpdateDestroyAPIView):
1223     queryset = Payment.objects.select_related().all()
1224     serializer_class = PaymentSerializer
1225     
1226     def get_queryset(self):
1227         return Payment.select_by_user(self.request.user)
1228
1229     def update(self, request, *args, **kwargs):
1230         obj = self.get_object()
1231         if obj.can_update(request.user):
1232             return super(PaymentDetail, self).update(request, *args, **kwargs)
1233         else:
1234             return Response(status=status.HTTP_400_BAD_REQUEST)
1235
1236     def destroy(self, request, *args, **kwargs):
1237         obj = self.get_object()
1238         if obj.can_update(request.user):
1239             return super(PaymentDetail, self).destroy(request, *args, **kwargs)
1240         else:
1241             return Response(status=status.HTTP_400_BAD_REQUEST)
1242      
1243
1244
1245
1246 class ChargeList(generics.ListCreateAPIView):
1247     queryset = Charge.objects.select_related().all()
1248     serializer_class = ChargeSerializer
1249     
1250     def get_queryset(self):
1251         return Charge.select_by_user(self.request.user)
1252
1253     def create(self, request, *args, **kwargs):
1254         #obj = Charge().update(request.DATA)
1255         obj = self.get_object()
1256         obj.caller = request.user
1257         if obj.can_update(request.user):
1258             return super(ChargeList, self).create(request, *args, **kwargs)
1259         else:
1260             return Response(status=status.HTTP_400_BAD_REQUEST)
1261
1262 class ChargeDetail(generics.RetrieveUpdateDestroyAPIView):
1263     queryset = Charge.objects.select_related().all()
1264     serializer_class = ChargeSerializer
1265     
1266     def get_queryset(self):
1267         return Charge.select_by_user(self.request.user)
1268
1269     def update(self, request, *args, **kwargs):
1270         obj = self.get_object()
1271         if obj.can_update(request.user):
1272             return super(ChargeDetail, self).update(request, *args, **kwargs)
1273         else:
1274             return Response(status=status.HTTP_400_BAD_REQUEST)
1275
1276     def destroy(self, request, *args, **kwargs):
1277         obj = self.get_object()
1278         if obj.can_update(request.user):
1279             return super(ChargeDetail, self).destroy(request, *args, **kwargs)
1280         else:
1281             return Response(status=status.HTTP_400_BAD_REQUEST)
1282      
1283
1284
1285
1286 class RoleList(generics.ListCreateAPIView):
1287     queryset = Role.objects.select_related().all()
1288     serializer_class = RoleSerializer
1289     
1290     def get_queryset(self):
1291         return Role.select_by_user(self.request.user)
1292
1293     def create(self, request, *args, **kwargs):
1294         #obj = Role().update(request.DATA)
1295         obj = self.get_object()
1296         obj.caller = request.user
1297         if obj.can_update(request.user):
1298             return super(RoleList, self).create(request, *args, **kwargs)
1299         else:
1300             return Response(status=status.HTTP_400_BAD_REQUEST)
1301
1302 class RoleDetail(generics.RetrieveUpdateDestroyAPIView):
1303     queryset = Role.objects.select_related().all()
1304     serializer_class = RoleSerializer
1305     
1306     def get_queryset(self):
1307         return Role.select_by_user(self.request.user)
1308
1309     def update(self, request, *args, **kwargs):
1310         obj = self.get_object()
1311         if obj.can_update(request.user):
1312             return super(RoleDetail, self).update(request, *args, **kwargs)
1313         else:
1314             return Response(status=status.HTTP_400_BAD_REQUEST)
1315
1316     def destroy(self, request, *args, **kwargs):
1317         obj = self.get_object()
1318         if obj.can_update(request.user):
1319             return super(RoleDetail, self).destroy(request, *args, **kwargs)
1320         else:
1321             return Response(status=status.HTTP_400_BAD_REQUEST)
1322      
1323
1324
1325
1326 class UsableObjectList(generics.ListCreateAPIView):
1327     queryset = UsableObject.objects.select_related().all()
1328     serializer_class = UsableObjectSerializer
1329     
1330     def get_queryset(self):
1331         return UsableObject.select_by_user(self.request.user)
1332
1333     def create(self, request, *args, **kwargs):
1334         #obj = UsableObject().update(request.DATA)
1335         obj = self.get_object()
1336         obj.caller = request.user
1337         if obj.can_update(request.user):
1338             return super(UsableObjectList, self).create(request, *args, **kwargs)
1339         else:
1340             return Response(status=status.HTTP_400_BAD_REQUEST)
1341
1342 class UsableObjectDetail(generics.RetrieveUpdateDestroyAPIView):
1343     queryset = UsableObject.objects.select_related().all()
1344     serializer_class = UsableObjectSerializer
1345     
1346     def get_queryset(self):
1347         return UsableObject.select_by_user(self.request.user)
1348
1349     def update(self, request, *args, **kwargs):
1350         obj = self.get_object()
1351         if obj.can_update(request.user):
1352             return super(UsableObjectDetail, self).update(request, *args, **kwargs)
1353         else:
1354             return Response(status=status.HTTP_400_BAD_REQUEST)
1355
1356     def destroy(self, request, *args, **kwargs):
1357         obj = self.get_object()
1358         if obj.can_update(request.user):
1359             return super(UsableObjectDetail, self).destroy(request, *args, **kwargs)
1360         else:
1361             return Response(status=status.HTTP_400_BAD_REQUEST)
1362      
1363
1364
1365
1366 class SiteRoleList(generics.ListCreateAPIView):
1367     queryset = SiteRole.objects.select_related().all()
1368     serializer_class = SiteRoleSerializer
1369     
1370     def get_queryset(self):
1371         return SiteRole.select_by_user(self.request.user)
1372
1373     def create(self, request, *args, **kwargs):
1374         #obj = SiteRole().update(request.DATA)
1375         obj = self.get_object()
1376         obj.caller = request.user
1377         if obj.can_update(request.user):
1378             return super(SiteRoleList, self).create(request, *args, **kwargs)
1379         else:
1380             return Response(status=status.HTTP_400_BAD_REQUEST)
1381
1382 class SiteRoleDetail(generics.RetrieveUpdateDestroyAPIView):
1383     queryset = SiteRole.objects.select_related().all()
1384     serializer_class = SiteRoleSerializer
1385     
1386     def get_queryset(self):
1387         return SiteRole.select_by_user(self.request.user)
1388
1389     def update(self, request, *args, **kwargs):
1390         obj = self.get_object()
1391         if obj.can_update(request.user):
1392             return super(SiteRoleDetail, self).update(request, *args, **kwargs)
1393         else:
1394             return Response(status=status.HTTP_400_BAD_REQUEST)
1395
1396     def destroy(self, request, *args, **kwargs):
1397         obj = self.get_object()
1398         if obj.can_update(request.user):
1399             return super(SiteRoleDetail, self).destroy(request, *args, **kwargs)
1400         else:
1401             return Response(status=status.HTTP_400_BAD_REQUEST)
1402      
1403
1404
1405
1406 class SliverList(generics.ListCreateAPIView):
1407     queryset = Sliver.objects.select_related().all()
1408     serializer_class = SliverSerializer
1409     
1410     def get_queryset(self):
1411         return Sliver.select_by_user(self.request.user)
1412
1413     def create(self, request, *args, **kwargs):
1414         #obj = Sliver().update(request.DATA)
1415         obj = self.get_object()
1416         obj.caller = request.user
1417         if obj.can_update(request.user):
1418             return super(SliverList, self).create(request, *args, **kwargs)
1419         else:
1420             return Response(status=status.HTTP_400_BAD_REQUEST)
1421
1422 class SliverDetail(generics.RetrieveUpdateDestroyAPIView):
1423     queryset = Sliver.objects.select_related().all()
1424     serializer_class = SliverSerializer
1425     
1426     def get_queryset(self):
1427         return Sliver.select_by_user(self.request.user)
1428
1429     def update(self, request, *args, **kwargs):
1430         obj = self.get_object()
1431         if obj.can_update(request.user):
1432             return super(SliverDetail, self).update(request, *args, **kwargs)
1433         else:
1434             return Response(status=status.HTTP_400_BAD_REQUEST)
1435
1436     def destroy(self, request, *args, **kwargs):
1437         obj = self.get_object()
1438         if obj.can_update(request.user):
1439             return super(SliverDetail, self).destroy(request, *args, **kwargs)
1440         else:
1441             return Response(status=status.HTTP_400_BAD_REQUEST)
1442      
1443
1444
1445
1446 class NodeList(generics.ListCreateAPIView):
1447     queryset = Node.objects.select_related().all()
1448     serializer_class = NodeSerializer
1449     
1450     def get_queryset(self):
1451         return Node.select_by_user(self.request.user)
1452
1453     def create(self, request, *args, **kwargs):
1454         #obj = Node().update(request.DATA)
1455         obj = self.get_object()
1456         obj.caller = request.user
1457         if obj.can_update(request.user):
1458             return super(NodeList, self).create(request, *args, **kwargs)
1459         else:
1460             return Response(status=status.HTTP_400_BAD_REQUEST)
1461
1462 class NodeDetail(generics.RetrieveUpdateDestroyAPIView):
1463     queryset = Node.objects.select_related().all()
1464     serializer_class = NodeSerializer
1465     
1466     def get_queryset(self):
1467         return Node.select_by_user(self.request.user)
1468
1469     def update(self, request, *args, **kwargs):
1470         obj = self.get_object()
1471         if obj.can_update(request.user):
1472             return super(NodeDetail, self).update(request, *args, **kwargs)
1473         else:
1474             return Response(status=status.HTTP_400_BAD_REQUEST)
1475
1476     def destroy(self, request, *args, **kwargs):
1477         obj = self.get_object()
1478         if obj.can_update(request.user):
1479             return super(NodeDetail, self).destroy(request, *args, **kwargs)
1480         else:
1481             return Response(status=status.HTTP_400_BAD_REQUEST)
1482      
1483
1484
1485
1486 class DashboardViewList(generics.ListCreateAPIView):
1487     queryset = DashboardView.objects.select_related().all()
1488     serializer_class = DashboardViewSerializer
1489     
1490     def get_queryset(self):
1491         return DashboardView.select_by_user(self.request.user)
1492
1493     def create(self, request, *args, **kwargs):
1494         #obj = DashboardView().update(request.DATA)
1495         obj = self.get_object()
1496         obj.caller = request.user
1497         if obj.can_update(request.user):
1498             return super(DashboardViewList, self).create(request, *args, **kwargs)
1499         else:
1500             return Response(status=status.HTTP_400_BAD_REQUEST)
1501
1502 class DashboardViewDetail(generics.RetrieveUpdateDestroyAPIView):
1503     queryset = DashboardView.objects.select_related().all()
1504     serializer_class = DashboardViewSerializer
1505     
1506     def get_queryset(self):
1507         return DashboardView.select_by_user(self.request.user)
1508
1509     def update(self, request, *args, **kwargs):
1510         obj = self.get_object()
1511         if obj.can_update(request.user):
1512             return super(DashboardViewDetail, self).update(request, *args, **kwargs)
1513         else:
1514             return Response(status=status.HTTP_400_BAD_REQUEST)
1515
1516     def destroy(self, request, *args, **kwargs):
1517         obj = self.get_object()
1518         if obj.can_update(request.user):
1519             return super(DashboardViewDetail, self).destroy(request, *args, **kwargs)
1520         else:
1521             return Response(status=status.HTTP_400_BAD_REQUEST)
1522      
1523
1524
1525
1526 class ImageDeploymentsList(generics.ListCreateAPIView):
1527     queryset = ImageDeployments.objects.select_related().all()
1528     serializer_class = ImageDeploymentsSerializer
1529     
1530     def get_queryset(self):
1531         return ImageDeployments.select_by_user(self.request.user)
1532
1533     def create(self, request, *args, **kwargs):
1534         #obj = ImageDeployments().update(request.DATA)
1535         obj = self.get_object()
1536         obj.caller = request.user
1537         if obj.can_update(request.user):
1538             return super(ImageDeploymentsList, self).create(request, *args, **kwargs)
1539         else:
1540             return Response(status=status.HTTP_400_BAD_REQUEST)
1541
1542 class ImageDeploymentsDetail(generics.RetrieveUpdateDestroyAPIView):
1543     queryset = ImageDeployments.objects.select_related().all()
1544     serializer_class = ImageDeploymentsSerializer
1545     
1546     def get_queryset(self):
1547         return ImageDeployments.select_by_user(self.request.user)
1548
1549     def update(self, request, *args, **kwargs):
1550         obj = self.get_object()
1551         if obj.can_update(request.user):
1552             return super(ImageDeploymentsDetail, self).update(request, *args, **kwargs)
1553         else:
1554             return Response(status=status.HTTP_400_BAD_REQUEST)
1555
1556     def destroy(self, request, *args, **kwargs):
1557         obj = self.get_object()
1558         if obj.can_update(request.user):
1559             return super(ImageDeploymentsDetail, self).destroy(request, *args, **kwargs)
1560         else:
1561             return Response(status=status.HTTP_400_BAD_REQUEST)
1562      
1563
1564
1565
1566 class ReservedResourceList(generics.ListCreateAPIView):
1567     queryset = ReservedResource.objects.select_related().all()
1568     serializer_class = ReservedResourceSerializer
1569     
1570     def get_queryset(self):
1571         return ReservedResource.select_by_user(self.request.user)
1572
1573     def create(self, request, *args, **kwargs):
1574         #obj = ReservedResource().update(request.DATA)
1575         obj = self.get_object()
1576         obj.caller = request.user
1577         if obj.can_update(request.user):
1578             return super(ReservedResourceList, self).create(request, *args, **kwargs)
1579         else:
1580             return Response(status=status.HTTP_400_BAD_REQUEST)
1581
1582 class ReservedResourceDetail(generics.RetrieveUpdateDestroyAPIView):
1583     queryset = ReservedResource.objects.select_related().all()
1584     serializer_class = ReservedResourceSerializer
1585     
1586     def get_queryset(self):
1587         return ReservedResource.select_by_user(self.request.user)
1588
1589     def update(self, request, *args, **kwargs):
1590         obj = self.get_object()
1591         if obj.can_update(request.user):
1592             return super(ReservedResourceDetail, self).update(request, *args, **kwargs)
1593         else:
1594             return Response(status=status.HTTP_400_BAD_REQUEST)
1595
1596     def destroy(self, request, *args, **kwargs):
1597         obj = self.get_object()
1598         if obj.can_update(request.user):
1599             return super(ReservedResourceDetail, self).destroy(request, *args, **kwargs)
1600         else:
1601             return Response(status=status.HTTP_400_BAD_REQUEST)
1602      
1603
1604
1605
1606 class NetworkSliceList(generics.ListCreateAPIView):
1607     queryset = NetworkSlice.objects.select_related().all()
1608     serializer_class = NetworkSliceSerializer
1609     
1610     def get_queryset(self):
1611         return NetworkSlice.select_by_user(self.request.user)
1612
1613     def create(self, request, *args, **kwargs):
1614         #obj = NetworkSlice().update(request.DATA)
1615         obj = self.get_object()
1616         obj.caller = request.user
1617         if obj.can_update(request.user):
1618             return super(NetworkSliceList, self).create(request, *args, **kwargs)
1619         else:
1620             return Response(status=status.HTTP_400_BAD_REQUEST)
1621
1622 class NetworkSliceDetail(generics.RetrieveUpdateDestroyAPIView):
1623     queryset = NetworkSlice.objects.select_related().all()
1624     serializer_class = NetworkSliceSerializer
1625     
1626     def get_queryset(self):
1627         return NetworkSlice.select_by_user(self.request.user)
1628
1629     def update(self, request, *args, **kwargs):
1630         obj = self.get_object()
1631         if obj.can_update(request.user):
1632             return super(NetworkSliceDetail, self).update(request, *args, **kwargs)
1633         else:
1634             return Response(status=status.HTTP_400_BAD_REQUEST)
1635
1636     def destroy(self, request, *args, **kwargs):
1637         obj = self.get_object()
1638         if obj.can_update(request.user):
1639             return super(NetworkSliceDetail, self).destroy(request, *args, **kwargs)
1640         else:
1641             return Response(status=status.HTTP_400_BAD_REQUEST)
1642      
1643
1644
1645
1646 class UserDashboardViewList(generics.ListCreateAPIView):
1647     queryset = UserDashboardView.objects.select_related().all()
1648     serializer_class = UserDashboardViewSerializer
1649     
1650     def get_queryset(self):
1651         return UserDashboardView.select_by_user(self.request.user)
1652
1653     def create(self, request, *args, **kwargs):
1654         #obj = UserDashboardView().update(request.DATA)
1655         obj = self.get_object()
1656         obj.caller = request.user
1657         if obj.can_update(request.user):
1658             return super(UserDashboardViewList, self).create(request, *args, **kwargs)
1659         else:
1660             return Response(status=status.HTTP_400_BAD_REQUEST)
1661
1662 class UserDashboardViewDetail(generics.RetrieveUpdateDestroyAPIView):
1663     queryset = UserDashboardView.objects.select_related().all()
1664     serializer_class = UserDashboardViewSerializer
1665     
1666     def get_queryset(self):
1667         return UserDashboardView.select_by_user(self.request.user)
1668
1669     def update(self, request, *args, **kwargs):
1670         obj = self.get_object()
1671         if obj.can_update(request.user):
1672             return super(UserDashboardViewDetail, self).update(request, *args, **kwargs)
1673         else:
1674             return Response(status=status.HTTP_400_BAD_REQUEST)
1675
1676     def destroy(self, request, *args, **kwargs):
1677         obj = self.get_object()
1678         if obj.can_update(request.user):
1679             return super(UserDashboardViewDetail, self).destroy(request, *args, **kwargs)
1680         else:
1681             return Response(status=status.HTTP_400_BAD_REQUEST)
1682      
1683
1684
1685
1686 class PlanetStackPrivilegeList(generics.ListCreateAPIView):
1687     queryset = PlanetStackPrivilege.objects.select_related().all()
1688     serializer_class = PlanetStackPrivilegeSerializer
1689     
1690     def get_queryset(self):
1691         return PlanetStackPrivilege.select_by_user(self.request.user)
1692
1693     def create(self, request, *args, **kwargs):
1694         #obj = PlanetStackPrivilege().update(request.DATA)
1695         obj = self.get_object()
1696         obj.caller = request.user
1697         if obj.can_update(request.user):
1698             return super(PlanetStackPrivilegeList, self).create(request, *args, **kwargs)
1699         else:
1700             return Response(status=status.HTTP_400_BAD_REQUEST)
1701
1702 class PlanetStackPrivilegeDetail(generics.RetrieveUpdateDestroyAPIView):
1703     queryset = PlanetStackPrivilege.objects.select_related().all()
1704     serializer_class = PlanetStackPrivilegeSerializer
1705     
1706     def get_queryset(self):
1707         return PlanetStackPrivilege.select_by_user(self.request.user)
1708
1709     def update(self, request, *args, **kwargs):
1710         obj = self.get_object()
1711         if obj.can_update(request.user):
1712             return super(PlanetStackPrivilegeDetail, self).update(request, *args, **kwargs)
1713         else:
1714             return Response(status=status.HTTP_400_BAD_REQUEST)
1715
1716     def destroy(self, request, *args, **kwargs):
1717         obj = self.get_object()
1718         if obj.can_update(request.user):
1719             return super(PlanetStackPrivilegeDetail, self).destroy(request, *args, **kwargs)
1720         else:
1721             return Response(status=status.HTTP_400_BAD_REQUEST)
1722      
1723
1724
1725
1726 class UserList(generics.ListCreateAPIView):
1727     queryset = User.objects.select_related().all()
1728     serializer_class = UserSerializer
1729     
1730     def get_queryset(self):
1731         return User.select_by_user(self.request.user)
1732
1733     def create(self, request, *args, **kwargs):
1734         #obj = User().update(request.DATA)
1735         obj = self.get_object()
1736         obj.caller = request.user
1737         if obj.can_update(request.user):
1738             return super(UserList, self).create(request, *args, **kwargs)
1739         else:
1740             return Response(status=status.HTTP_400_BAD_REQUEST)
1741
1742 class UserDetail(generics.RetrieveUpdateDestroyAPIView):
1743     queryset = User.objects.select_related().all()
1744     serializer_class = UserSerializer
1745     
1746     def get_queryset(self):
1747         return User.select_by_user(self.request.user)
1748
1749     def update(self, request, *args, **kwargs):
1750         obj = self.get_object()
1751         if obj.can_update(request.user):
1752             return super(UserDetail, self).update(request, *args, **kwargs)
1753         else:
1754             return Response(status=status.HTTP_400_BAD_REQUEST)
1755
1756     def destroy(self, request, *args, **kwargs):
1757         obj = self.get_object()
1758         if obj.can_update(request.user):
1759             return super(UserDetail, self).destroy(request, *args, **kwargs)
1760         else:
1761             return Response(status=status.HTTP_400_BAD_REQUEST)
1762      
1763
1764
1765
1766 class DeploymentList(generics.ListCreateAPIView):
1767     queryset = Deployment.objects.select_related().all()
1768     serializer_class = DeploymentSerializer
1769     
1770     def get_queryset(self):
1771         return Deployment.select_by_user(self.request.user)
1772
1773     def create(self, request, *args, **kwargs):
1774         #obj = Deployment().update(request.DATA)
1775         obj = self.get_object()
1776         obj.caller = request.user
1777         if obj.can_update(request.user):
1778             return super(DeploymentList, self).create(request, *args, **kwargs)
1779         else:
1780             return Response(status=status.HTTP_400_BAD_REQUEST)
1781
1782 class DeploymentDetail(generics.RetrieveUpdateDestroyAPIView):
1783     queryset = Deployment.objects.select_related().all()
1784     serializer_class = DeploymentSerializer
1785     
1786     def get_queryset(self):
1787         return Deployment.select_by_user(self.request.user)
1788
1789     def update(self, request, *args, **kwargs):
1790         obj = self.get_object()
1791         if obj.can_update(request.user):
1792             return super(DeploymentDetail, self).update(request, *args, **kwargs)
1793         else:
1794             return Response(status=status.HTTP_400_BAD_REQUEST)
1795
1796     def destroy(self, request, *args, **kwargs):
1797         obj = self.get_object()
1798         if obj.can_update(request.user):
1799             return super(DeploymentDetail, self).destroy(request, *args, **kwargs)
1800         else:
1801             return Response(status=status.HTTP_400_BAD_REQUEST)
1802      
1803
1804
1805
1806 class ReservationList(generics.ListCreateAPIView):
1807     queryset = Reservation.objects.select_related().all()
1808     serializer_class = ReservationSerializer
1809     
1810     def get_queryset(self):
1811         return Reservation.select_by_user(self.request.user)
1812
1813     def create(self, request, *args, **kwargs):
1814         #obj = Reservation().update(request.DATA)
1815         obj = self.get_object()
1816         obj.caller = request.user
1817         if obj.can_update(request.user):
1818             return super(ReservationList, self).create(request, *args, **kwargs)
1819         else:
1820             return Response(status=status.HTTP_400_BAD_REQUEST)
1821
1822 class ReservationDetail(generics.RetrieveUpdateDestroyAPIView):
1823     queryset = Reservation.objects.select_related().all()
1824     serializer_class = ReservationSerializer
1825     
1826     def get_queryset(self):
1827         return Reservation.select_by_user(self.request.user)
1828
1829     def update(self, request, *args, **kwargs):
1830         obj = self.get_object()
1831         if obj.can_update(request.user):
1832             return super(ReservationDetail, self).update(request, *args, **kwargs)
1833         else:
1834             return Response(status=status.HTTP_400_BAD_REQUEST)
1835
1836     def destroy(self, request, *args, **kwargs):
1837         obj = self.get_object()
1838         if obj.can_update(request.user):
1839             return super(ReservationDetail, self).destroy(request, *args, **kwargs)
1840         else:
1841             return Response(status=status.HTTP_400_BAD_REQUEST)
1842      
1843
1844
1845
1846 class SliceDeploymentsList(generics.ListCreateAPIView):
1847     queryset = SliceDeployments.objects.select_related().all()
1848     serializer_class = SliceDeploymentsSerializer
1849     
1850     def get_queryset(self):
1851         return SliceDeployments.select_by_user(self.request.user)
1852
1853     def create(self, request, *args, **kwargs):
1854         #obj = SliceDeployments().update(request.DATA)
1855         obj = self.get_object()
1856         obj.caller = request.user
1857         if obj.can_update(request.user):
1858             return super(SliceDeploymentsList, self).create(request, *args, **kwargs)
1859         else:
1860             return Response(status=status.HTTP_400_BAD_REQUEST)
1861
1862 class SliceDeploymentsDetail(generics.RetrieveUpdateDestroyAPIView):
1863     queryset = SliceDeployments.objects.select_related().all()
1864     serializer_class = SliceDeploymentsSerializer
1865     
1866     def get_queryset(self):
1867         return SliceDeployments.select_by_user(self.request.user)
1868
1869     def update(self, request, *args, **kwargs):
1870         obj = self.get_object()
1871         if obj.can_update(request.user):
1872             return super(SliceDeploymentsDetail, self).update(request, *args, **kwargs)
1873         else:
1874             return Response(status=status.HTTP_400_BAD_REQUEST)
1875
1876     def destroy(self, request, *args, **kwargs):
1877         obj = self.get_object()
1878         if obj.can_update(request.user):
1879             return super(SliceDeploymentsDetail, self).destroy(request, *args, **kwargs)
1880         else:
1881             return Response(status=status.HTTP_400_BAD_REQUEST)
1882      
1883
1884
1885
1886 class SitePrivilegeList(generics.ListCreateAPIView):
1887     queryset = SitePrivilege.objects.select_related().all()
1888     serializer_class = SitePrivilegeSerializer
1889     
1890     def get_queryset(self):
1891         return SitePrivilege.select_by_user(self.request.user)
1892
1893     def create(self, request, *args, **kwargs):
1894         #obj = SitePrivilege().update(request.DATA)
1895         obj = self.get_object()
1896         obj.caller = request.user
1897         if obj.can_update(request.user):
1898             return super(SitePrivilegeList, self).create(request, *args, **kwargs)
1899         else:
1900             return Response(status=status.HTTP_400_BAD_REQUEST)
1901
1902 class SitePrivilegeDetail(generics.RetrieveUpdateDestroyAPIView):
1903     queryset = SitePrivilege.objects.select_related().all()
1904     serializer_class = SitePrivilegeSerializer
1905     
1906     def get_queryset(self):
1907         return SitePrivilege.select_by_user(self.request.user)
1908
1909     def update(self, request, *args, **kwargs):
1910         obj = self.get_object()
1911         if obj.can_update(request.user):
1912             return super(SitePrivilegeDetail, self).update(request, *args, **kwargs)
1913         else:
1914             return Response(status=status.HTTP_400_BAD_REQUEST)
1915
1916     def destroy(self, request, *args, **kwargs):
1917         obj = self.get_object()
1918         if obj.can_update(request.user):
1919             return super(SitePrivilegeDetail, self).destroy(request, *args, **kwargs)
1920         else:
1921             return Response(status=status.HTTP_400_BAD_REQUEST)
1922      
1923
1924
1925
1926 class PlanetStackList(generics.ListCreateAPIView):
1927     queryset = PlanetStack.objects.select_related().all()
1928     serializer_class = PlanetStackSerializer
1929     
1930     def get_queryset(self):
1931         return PlanetStack.select_by_user(self.request.user)
1932
1933     def create(self, request, *args, **kwargs):
1934         #obj = PlanetStack().update(request.DATA)
1935         obj = self.get_object()
1936         obj.caller = request.user
1937         if obj.can_update(request.user):
1938             return super(PlanetStackList, self).create(request, *args, **kwargs)
1939         else:
1940             return Response(status=status.HTTP_400_BAD_REQUEST)
1941
1942 class PlanetStackDetail(generics.RetrieveUpdateDestroyAPIView):
1943     queryset = PlanetStack.objects.select_related().all()
1944     serializer_class = PlanetStackSerializer
1945     
1946     def get_queryset(self):
1947         return PlanetStack.select_by_user(self.request.user)
1948
1949     def update(self, request, *args, **kwargs):
1950         obj = self.get_object()
1951         if obj.can_update(request.user):
1952             return super(PlanetStackDetail, self).update(request, *args, **kwargs)
1953         else:
1954             return Response(status=status.HTTP_400_BAD_REQUEST)
1955
1956     def destroy(self, request, *args, **kwargs):
1957         obj = self.get_object()
1958         if obj.can_update(request.user):
1959             return super(PlanetStackDetail, self).destroy(request, *args, **kwargs)
1960         else:
1961             return Response(status=status.HTTP_400_BAD_REQUEST)
1962      
1963
1964
1965
1966 class UserDeploymentsList(generics.ListCreateAPIView):
1967     queryset = UserDeployments.objects.select_related().all()
1968     serializer_class = UserDeploymentsSerializer
1969     
1970     def get_queryset(self):
1971         return UserDeployments.select_by_user(self.request.user)
1972
1973     def create(self, request, *args, **kwargs):
1974         #obj = UserDeployments().update(request.DATA)
1975         obj = self.get_object()
1976         obj.caller = request.user
1977         if obj.can_update(request.user):
1978             return super(UserDeploymentsList, self).create(request, *args, **kwargs)
1979         else:
1980             return Response(status=status.HTTP_400_BAD_REQUEST)
1981
1982 class UserDeploymentsDetail(generics.RetrieveUpdateDestroyAPIView):
1983     queryset = UserDeployments.objects.select_related().all()
1984     serializer_class = UserDeploymentsSerializer
1985     
1986     def get_queryset(self):
1987         return UserDeployments.select_by_user(self.request.user)
1988
1989     def update(self, request, *args, **kwargs):
1990         obj = self.get_object()
1991         if obj.can_update(request.user):
1992             return super(UserDeploymentsDetail, self).update(request, *args, **kwargs)
1993         else:
1994             return Response(status=status.HTTP_400_BAD_REQUEST)
1995
1996     def destroy(self, request, *args, **kwargs):
1997         obj = self.get_object()
1998         if obj.can_update(request.user):
1999             return super(UserDeploymentsDetail, self).destroy(request, *args, **kwargs)
2000         else:
2001             return Response(status=status.HTTP_400_BAD_REQUEST)
2002      
2003
2004
2005
2006 class AccountList(generics.ListCreateAPIView):
2007     queryset = Account.objects.select_related().all()
2008     serializer_class = AccountSerializer
2009     
2010     def get_queryset(self):
2011         return Account.select_by_user(self.request.user)
2012
2013     def create(self, request, *args, **kwargs):
2014         #obj = Account().update(request.DATA)
2015         obj = self.get_object()
2016         obj.caller = request.user
2017         if obj.can_update(request.user):
2018             return super(AccountList, self).create(request, *args, **kwargs)
2019         else:
2020             return Response(status=status.HTTP_400_BAD_REQUEST)
2021
2022 class AccountDetail(generics.RetrieveUpdateDestroyAPIView):
2023     queryset = Account.objects.select_related().all()
2024     serializer_class = AccountSerializer
2025     
2026     def get_queryset(self):
2027         return Account.select_by_user(self.request.user)
2028
2029     def update(self, request, *args, **kwargs):
2030         obj = self.get_object()
2031         if obj.can_update(request.user):
2032             return super(AccountDetail, self).update(request, *args, **kwargs)
2033         else:
2034             return Response(status=status.HTTP_400_BAD_REQUEST)
2035
2036     def destroy(self, request, *args, **kwargs):
2037         obj = self.get_object()
2038         if obj.can_update(request.user):
2039             return super(AccountDetail, self).destroy(request, *args, **kwargs)
2040         else:
2041             return Response(status=status.HTTP_400_BAD_REQUEST)
2042      
2043
2044
2045
2046 class NetworkParameterTypeList(generics.ListCreateAPIView):
2047     queryset = NetworkParameterType.objects.select_related().all()
2048     serializer_class = NetworkParameterTypeSerializer
2049     
2050     def get_queryset(self):
2051         return NetworkParameterType.select_by_user(self.request.user)
2052
2053     def create(self, request, *args, **kwargs):
2054         #obj = NetworkParameterType().update(request.DATA)
2055         obj = self.get_object()
2056         obj.caller = request.user
2057         if obj.can_update(request.user):
2058             return super(NetworkParameterTypeList, self).create(request, *args, **kwargs)
2059         else:
2060             return Response(status=status.HTTP_400_BAD_REQUEST)
2061
2062 class NetworkParameterTypeDetail(generics.RetrieveUpdateDestroyAPIView):
2063     queryset = NetworkParameterType.objects.select_related().all()
2064     serializer_class = NetworkParameterTypeSerializer
2065     
2066     def get_queryset(self):
2067         return NetworkParameterType.select_by_user(self.request.user)
2068
2069     def update(self, request, *args, **kwargs):
2070         obj = self.get_object()
2071         if obj.can_update(request.user):
2072             return super(NetworkParameterTypeDetail, self).update(request, *args, **kwargs)
2073         else:
2074             return Response(status=status.HTTP_400_BAD_REQUEST)
2075
2076     def destroy(self, request, *args, **kwargs):
2077         obj = self.get_object()
2078         if obj.can_update(request.user):
2079             return super(NetworkParameterTypeDetail, self).destroy(request, *args, **kwargs)
2080         else:
2081             return Response(status=status.HTTP_400_BAD_REQUEST)
2082      
2083
2084
2085
2086 class SiteDeploymentsList(generics.ListCreateAPIView):
2087     queryset = SiteDeployments.objects.select_related().all()
2088     serializer_class = SiteDeploymentsSerializer
2089     
2090     def get_queryset(self):
2091         return SiteDeployments.select_by_user(self.request.user)
2092
2093     def create(self, request, *args, **kwargs):
2094         #obj = SiteDeployments().update(request.DATA)
2095         obj = self.get_object()
2096         obj.caller = request.user
2097         if obj.can_update(request.user):
2098             return super(SiteDeploymentsList, self).create(request, *args, **kwargs)
2099         else:
2100             return Response(status=status.HTTP_400_BAD_REQUEST)
2101
2102 class SiteDeploymentsDetail(generics.RetrieveUpdateDestroyAPIView):
2103     queryset = SiteDeployments.objects.select_related().all()
2104     serializer_class = SiteDeploymentsSerializer
2105     
2106     def get_queryset(self):
2107         return SiteDeployments.select_by_user(self.request.user)
2108
2109     def update(self, request, *args, **kwargs):
2110         obj = self.get_object()
2111         if obj.can_update(request.user):
2112             return super(SiteDeploymentsDetail, self).update(request, *args, **kwargs)
2113         else:
2114             return Response(status=status.HTTP_400_BAD_REQUEST)
2115
2116     def destroy(self, request, *args, **kwargs):
2117         obj = self.get_object()
2118         if obj.can_update(request.user):
2119             return super(SiteDeploymentsDetail, self).destroy(request, *args, **kwargs)
2120         else:
2121             return Response(status=status.HTTP_400_BAD_REQUEST)
2122      
2123
2124
2125
2126 class DeploymentPrivilegeList(generics.ListCreateAPIView):
2127     queryset = DeploymentPrivilege.objects.select_related().all()
2128     serializer_class = DeploymentPrivilegeSerializer
2129     
2130     def get_queryset(self):
2131         return DeploymentPrivilege.select_by_user(self.request.user)
2132
2133     def create(self, request, *args, **kwargs):
2134         #obj = DeploymentPrivilege().update(request.DATA)
2135         obj = self.get_object()
2136         obj.caller = request.user
2137         if obj.can_update(request.user):
2138             return super(DeploymentPrivilegeList, self).create(request, *args, **kwargs)
2139         else:
2140             return Response(status=status.HTTP_400_BAD_REQUEST)
2141
2142 class DeploymentPrivilegeDetail(generics.RetrieveUpdateDestroyAPIView):
2143     queryset = DeploymentPrivilege.objects.select_related().all()
2144     serializer_class = DeploymentPrivilegeSerializer
2145     
2146     def get_queryset(self):
2147         return DeploymentPrivilege.select_by_user(self.request.user)
2148
2149     def update(self, request, *args, **kwargs):
2150         obj = self.get_object()
2151         if obj.can_update(request.user):
2152             return super(DeploymentPrivilegeDetail, self).update(request, *args, **kwargs)
2153         else:
2154             return Response(status=status.HTTP_400_BAD_REQUEST)
2155
2156     def destroy(self, request, *args, **kwargs):
2157         obj = self.get_object()
2158         if obj.can_update(request.user):
2159             return super(DeploymentPrivilegeDetail, self).destroy(request, *args, **kwargs)
2160         else:
2161             return Response(status=status.HTTP_400_BAD_REQUEST)
2162      
2163
2164
2165
2166 class DeploymentRoleList(generics.ListCreateAPIView):
2167     queryset = DeploymentRole.objects.select_related().all()
2168     serializer_class = DeploymentRoleSerializer
2169     
2170     def get_queryset(self):
2171         return DeploymentRole.select_by_user(self.request.user)
2172
2173     def create(self, request, *args, **kwargs):
2174         #obj = DeploymentRole().update(request.DATA)
2175         obj = self.get_object()
2176         obj.caller = request.user
2177         if obj.can_update(request.user):
2178             return super(DeploymentRoleList, self).create(request, *args, **kwargs)
2179         else:
2180             return Response(status=status.HTTP_400_BAD_REQUEST)
2181
2182 class DeploymentRoleDetail(generics.RetrieveUpdateDestroyAPIView):
2183     queryset = DeploymentRole.objects.select_related().all()
2184     serializer_class = DeploymentRoleSerializer
2185     
2186     def get_queryset(self):
2187         return DeploymentRole.select_by_user(self.request.user)
2188
2189     def update(self, request, *args, **kwargs):
2190         obj = self.get_object()
2191         if obj.can_update(request.user):
2192             return super(DeploymentRoleDetail, self).update(request, *args, **kwargs)
2193         else:
2194             return Response(status=status.HTTP_400_BAD_REQUEST)
2195
2196     def destroy(self, request, *args, **kwargs):
2197         obj = self.get_object()
2198         if obj.can_update(request.user):
2199             return super(DeploymentRoleDetail, self).destroy(request, *args, **kwargs)
2200         else:
2201             return Response(status=status.HTTP_400_BAD_REQUEST)
2202      
2203
2204
2205
2206 class ProjectList(generics.ListCreateAPIView):
2207     queryset = Project.objects.select_related().all()
2208     serializer_class = ProjectSerializer
2209     
2210     def get_queryset(self):
2211         return Project.select_by_user(self.request.user)
2212
2213     def create(self, request, *args, **kwargs):
2214         #obj = Project().update(request.DATA)
2215         obj = self.get_object()
2216         obj.caller = request.user
2217         if obj.can_update(request.user):
2218             return super(ProjectList, self).create(request, *args, **kwargs)
2219         else:
2220             return Response(status=status.HTTP_400_BAD_REQUEST)
2221
2222 class ProjectDetail(generics.RetrieveUpdateDestroyAPIView):
2223     queryset = Project.objects.select_related().all()
2224     serializer_class = ProjectSerializer
2225     
2226     def get_queryset(self):
2227         return Project.select_by_user(self.request.user)
2228
2229     def update(self, request, *args, **kwargs):
2230         obj = self.get_object()
2231         if obj.can_update(request.user):
2232             return super(ProjectDetail, self).update(request, *args, **kwargs)
2233         else:
2234             return Response(status=status.HTTP_400_BAD_REQUEST)
2235
2236     def destroy(self, request, *args, **kwargs):
2237         obj = self.get_object()
2238         if obj.can_update(request.user):
2239             return super(ProjectDetail, self).destroy(request, *args, **kwargs)
2240         else:
2241             return Response(status=status.HTTP_400_BAD_REQUEST)
2242      
2243
2244
2245
2246 class SliceTagList(generics.ListCreateAPIView):
2247     queryset = SliceTag.objects.select_related().all()
2248     serializer_class = SliceTagSerializer
2249     
2250     def get_queryset(self):
2251         return SliceTag.select_by_user(self.request.user)
2252
2253     def create(self, request, *args, **kwargs):
2254         #obj = SliceTag().update(request.DATA)
2255         obj = self.get_object()
2256         obj.caller = request.user
2257         if obj.can_update(request.user):
2258             return super(SliceTagList, self).create(request, *args, **kwargs)
2259         else:
2260             return Response(status=status.HTTP_400_BAD_REQUEST)
2261
2262 class SliceTagDetail(generics.RetrieveUpdateDestroyAPIView):
2263     queryset = SliceTag.objects.select_related().all()
2264     serializer_class = SliceTagSerializer
2265     
2266     def get_queryset(self):
2267         return SliceTag.select_by_user(self.request.user)
2268
2269     def update(self, request, *args, **kwargs):
2270         obj = self.get_object()
2271         if obj.can_update(request.user):
2272             return super(SliceTagDetail, self).update(request, *args, **kwargs)
2273         else:
2274             return Response(status=status.HTTP_400_BAD_REQUEST)
2275
2276     def destroy(self, request, *args, **kwargs):
2277         obj = self.get_object()
2278         if obj.can_update(request.user):
2279             return super(SliceTagDetail, self).destroy(request, *args, **kwargs)
2280         else:
2281             return Response(status=status.HTTP_400_BAD_REQUEST)
2282      
2283
2284
2285
2286 class NetworkTemplateList(generics.ListCreateAPIView):
2287     queryset = NetworkTemplate.objects.select_related().all()
2288     serializer_class = NetworkTemplateSerializer
2289     
2290     def get_queryset(self):
2291         return NetworkTemplate.select_by_user(self.request.user)
2292
2293     def create(self, request, *args, **kwargs):
2294         #obj = NetworkTemplate().update(request.DATA)
2295         obj = self.get_object()
2296         obj.caller = request.user
2297         if obj.can_update(request.user):
2298             return super(NetworkTemplateList, self).create(request, *args, **kwargs)
2299         else:
2300             return Response(status=status.HTTP_400_BAD_REQUEST)
2301
2302 class NetworkTemplateDetail(generics.RetrieveUpdateDestroyAPIView):
2303     queryset = NetworkTemplate.objects.select_related().all()
2304     serializer_class = NetworkTemplateSerializer
2305     
2306     def get_queryset(self):
2307         return NetworkTemplate.select_by_user(self.request.user)
2308
2309     def update(self, request, *args, **kwargs):
2310         obj = self.get_object()
2311         if obj.can_update(request.user):
2312             return super(NetworkTemplateDetail, self).update(request, *args, **kwargs)
2313         else:
2314             return Response(status=status.HTTP_400_BAD_REQUEST)
2315
2316     def destroy(self, request, *args, **kwargs):
2317         obj = self.get_object()
2318         if obj.can_update(request.user):
2319             return super(NetworkTemplateDetail, self).destroy(request, *args, **kwargs)
2320         else:
2321             return Response(status=status.HTTP_400_BAD_REQUEST)
2322      
2323
2324
2325
2326 class RouterList(generics.ListCreateAPIView):
2327     queryset = Router.objects.select_related().all()
2328     serializer_class = RouterSerializer
2329     
2330     def get_queryset(self):
2331         return Router.select_by_user(self.request.user)
2332
2333     def create(self, request, *args, **kwargs):
2334         #obj = Router().update(request.DATA)
2335         obj = self.get_object()
2336         obj.caller = request.user
2337         if obj.can_update(request.user):
2338             return super(RouterList, self).create(request, *args, **kwargs)
2339         else:
2340             return Response(status=status.HTTP_400_BAD_REQUEST)
2341
2342 class RouterDetail(generics.RetrieveUpdateDestroyAPIView):
2343     queryset = Router.objects.select_related().all()
2344     serializer_class = RouterSerializer
2345     
2346     def get_queryset(self):
2347         return Router.select_by_user(self.request.user)
2348
2349     def update(self, request, *args, **kwargs):
2350         obj = self.get_object()
2351         if obj.can_update(request.user):
2352             return super(RouterDetail, self).update(request, *args, **kwargs)
2353         else:
2354             return Response(status=status.HTTP_400_BAD_REQUEST)
2355
2356     def destroy(self, request, *args, **kwargs):
2357         obj = self.get_object()
2358         if obj.can_update(request.user):
2359             return super(RouterDetail, self).destroy(request, *args, **kwargs)
2360         else:
2361             return Response(status=status.HTTP_400_BAD_REQUEST)
2362      
2363
2364
2365
2366 class ServiceResourceList(generics.ListCreateAPIView):
2367     queryset = ServiceResource.objects.select_related().all()
2368     serializer_class = ServiceResourceSerializer
2369     
2370     def get_queryset(self):
2371         return ServiceResource.select_by_user(self.request.user)
2372
2373     def create(self, request, *args, **kwargs):
2374         #obj = ServiceResource().update(request.DATA)
2375         obj = self.get_object()
2376         obj.caller = request.user
2377         if obj.can_update(request.user):
2378             return super(ServiceResourceList, self).create(request, *args, **kwargs)
2379         else:
2380             return Response(status=status.HTTP_400_BAD_REQUEST)
2381
2382 class ServiceResourceDetail(generics.RetrieveUpdateDestroyAPIView):
2383     queryset = ServiceResource.objects.select_related().all()
2384     serializer_class = ServiceResourceSerializer
2385     
2386     def get_queryset(self):
2387         return ServiceResource.select_by_user(self.request.user)
2388
2389     def update(self, request, *args, **kwargs):
2390         obj = self.get_object()
2391         if obj.can_update(request.user):
2392             return super(ServiceResourceDetail, self).update(request, *args, **kwargs)
2393         else:
2394             return Response(status=status.HTTP_400_BAD_REQUEST)
2395
2396     def destroy(self, request, *args, **kwargs):
2397         obj = self.get_object()
2398         if obj.can_update(request.user):
2399             return super(ServiceResourceDetail, self).destroy(request, *args, **kwargs)
2400         else:
2401             return Response(status=status.HTTP_400_BAD_REQUEST)
2402      
2403
2404
2405