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
10 Schema of the generator object:
11 all: Set of all Model objects
12 all_if(regex): Set of Model objects that match regex
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
20 TODO: Deal with subnets
23 # Based on api_root.py
26 def api_root(request, format=None):
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),
76 # Based on serializers.py
80 class ServiceAttributeSerializer(serializers.HyperlinkedModelSerializer):
81 id = serializers.Field()
84 model = ServiceAttribute
85 fields = ('id','created','updated','enacted','name','value','service',)
88 class ImageSerializer(serializers.HyperlinkedModelSerializer):
89 id = serializers.Field()
93 fields = ('id','created','updated','enacted','name','disk_format','container_format','path',)
96 class NetworkParameterSerializer(serializers.HyperlinkedModelSerializer):
97 id = serializers.Field()
100 model = NetworkParameter
101 fields = ('id','created','updated','enacted','parameter','value','content_type','object_id',)
104 class SiteSerializer(serializers.HyperlinkedModelSerializer):
105 id = serializers.Field()
109 fields = ('id','created','updated','enacted','name','site_url','enabled','location','longitude','latitude','login_base','is_public','abbreviated_name',)
112 class SliceRoleSerializer(serializers.HyperlinkedModelSerializer):
113 id = serializers.Field()
117 fields = ('id','created','updated','enacted','role',)
120 class TagSerializer(serializers.HyperlinkedModelSerializer):
121 id = serializers.Field()
124 sites = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='site-detail')
128 slices = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='slice-detail')
132 slivers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='sliver-detail')
136 nodes = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='node-detail')
141 fields = ('id','created','updated','enacted','service','name','value','content_type','object_id','sites','slices','slivers','nodes',)
144 class InvoiceSerializer(serializers.HyperlinkedModelSerializer):
145 id = serializers.Field()
149 fields = ('id','created','updated','enacted','date','account',)
152 class PlanetStackRoleSerializer(serializers.HyperlinkedModelSerializer):
153 id = serializers.Field()
156 model = PlanetStackRole
157 fields = ('id','created','updated','enacted','role',)
160 class SlicePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
161 id = serializers.Field()
164 model = SlicePrivilege
165 fields = ('id','created','updated','enacted','user','slice','role',)
168 class NetworkSliverSerializer(serializers.HyperlinkedModelSerializer):
169 id = serializers.Field()
172 model = NetworkSliver
173 fields = ('id','created','updated','enacted','network','sliver','ip','port_id',)
176 class NetworkDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
177 id = serializers.Field()
180 model = NetworkDeployments
181 fields = ('id','created','updated','enacted','network','deployment','net_id','router_id','subnet_id','subnet',)
184 class SliceSerializer(serializers.HyperlinkedModelSerializer):
185 id = serializers.Field()
188 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
192 availableNetworks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
196 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
200 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
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',)
208 class NetworkSerializer(serializers.HyperlinkedModelSerializer):
209 id = serializers.Field()
212 routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
216 availableRouters = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
220 routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
224 routers = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='router-detail')
229 fields = ('id','created','updated','enacted','name','template','subnet','ports','labels','owner','guaranteedBandwidth','permitAllSlices','network_id','router_id','subnet_id','routers','availableRouters','routers','routers',)
232 class ServiceSerializer(serializers.HyperlinkedModelSerializer):
233 id = serializers.Field()
237 fields = ('id','created','updated','enacted','description','enabled','name','versionNumber','published',)
240 class ServiceClassSerializer(serializers.HyperlinkedModelSerializer):
241 id = serializers.Field()
245 fields = ('id','created','updated','enacted','name','description','commitment','membershipFee','membershipFeeMonths','upgradeRequiresApproval',)
248 class PaymentSerializer(serializers.HyperlinkedModelSerializer):
249 id = serializers.Field()
253 fields = ('id','created','updated','enacted','account','amount','date',)
256 class ChargeSerializer(serializers.HyperlinkedModelSerializer):
257 id = serializers.Field()
261 fields = ('id','created','updated','enacted','account','slice','kind','state','date','object','amount','coreHours','invoice',)
264 class RoleSerializer(serializers.HyperlinkedModelSerializer):
265 id = serializers.Field()
269 fields = ('id','created','updated','enacted','role_type','role','description','content_type',)
272 class UsableObjectSerializer(serializers.HyperlinkedModelSerializer):
273 id = serializers.Field()
277 fields = ('id','created','updated','enacted','name',)
280 class SiteRoleSerializer(serializers.HyperlinkedModelSerializer):
281 id = serializers.Field()
285 fields = ('id','created','updated','enacted','role',)
288 class SliverSerializer(serializers.HyperlinkedModelSerializer):
289 id = serializers.Field()
292 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
296 networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
300 # upgradeFrom_rel_+ = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='serviceclass-detail')
305 fields = ('id','created','updated','enacted','instance_id','name','instance_name','ip','image','creator','slice','node','deploymentNetwork','numberCores','userData','networks','networks','upgradeFrom_rel_+',)
308 class NodeSerializer(serializers.HyperlinkedModelSerializer):
309 id = serializers.Field()
313 fields = ('id','created','updated','enacted','name','site','deployment',)
316 class DashboardViewSerializer(serializers.HyperlinkedModelSerializer):
317 id = serializers.Field()
320 model = DashboardView
321 fields = ('id','created','updated','enacted','name','url',)
324 class ImageDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
325 id = serializers.Field()
328 model = ImageDeployments
329 fields = ('id','created','updated','enacted','image','deployment','glance_image_id',)
332 class ReservedResourceSerializer(serializers.HyperlinkedModelSerializer):
333 id = serializers.Field()
336 model = ReservedResource
337 fields = ('id','created','updated','enacted','sliver','resource','quantity','reservationSet',)
340 class NetworkSliceSerializer(serializers.HyperlinkedModelSerializer):
341 id = serializers.Field()
345 fields = ('id','created','updated','enacted','network','slice',)
348 class UserDashboardViewSerializer(serializers.HyperlinkedModelSerializer):
349 id = serializers.Field()
352 model = UserDashboardView
353 fields = ('id','created','updated','enacted','user','dashboardView','order',)
356 class PlanetStackPrivilegeSerializer(serializers.HyperlinkedModelSerializer):
357 id = serializers.Field()
360 model = PlanetStackPrivilege
361 fields = ('id','created','updated','enacted','user','planetstack','role',)
364 class UserSerializer(serializers.HyperlinkedModelSerializer):
365 id = serializers.Field()
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',)
372 class DeploymentSerializer(serializers.HyperlinkedModelSerializer):
373 id = serializers.Field()
376 sites = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='site-detail')
380 sites = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='site-detail')
385 fields = ('id','created','updated','enacted','name','admin_user','admin_password','admin_tenant','auth_url','accessControl','sites','sites',)
388 class ReservationSerializer(serializers.HyperlinkedModelSerializer):
389 id = serializers.Field()
393 fields = ('id','created','updated','enacted','startTime','slice','duration',)
396 class SliceDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
397 id = serializers.Field()
400 model = SliceDeployments
401 fields = ('id','created','updated','enacted','slice','deployment','tenant_id','network_id','router_id','subnet_id',)
404 class SitePrivilegeSerializer(serializers.HyperlinkedModelSerializer):
405 id = serializers.Field()
408 model = SitePrivilege
409 fields = ('id','created','updated','enacted','user','site','role',)
412 class PlanetStackSerializer(serializers.HyperlinkedModelSerializer):
413 id = serializers.Field()
417 fields = ('id','created','updated','enacted','description',)
420 class UserDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
421 id = serializers.Field()
424 model = UserDeployments
425 fields = ('id','created','updated','enacted','user','deployment','kuser_id',)
428 class AccountSerializer(serializers.HyperlinkedModelSerializer):
429 id = serializers.Field()
433 fields = ('id','created','updated','enacted','site',)
436 class NetworkParameterTypeSerializer(serializers.HyperlinkedModelSerializer):
437 id = serializers.Field()
440 model = NetworkParameterType
441 fields = ('id','created','updated','enacted','name','description',)
444 class SiteDeploymentsSerializer(serializers.HyperlinkedModelSerializer):
445 id = serializers.Field()
448 model = SiteDeployments
449 fields = ('id','created','updated','enacted','site','deployment','tenant_id',)
452 class DeploymentPrivilegeSerializer(serializers.HyperlinkedModelSerializer):
453 id = serializers.Field()
456 model = DeploymentPrivilege
457 fields = ('id','created','updated','enacted','user','deployment','role',)
460 class DeploymentRoleSerializer(serializers.HyperlinkedModelSerializer):
461 id = serializers.Field()
464 model = DeploymentRole
465 fields = ('id','created','updated','enacted','role',)
468 class ProjectSerializer(serializers.HyperlinkedModelSerializer):
469 id = serializers.Field()
473 fields = ('id','created','updated','enacted','name',)
476 class SliceTagSerializer(serializers.HyperlinkedModelSerializer):
477 id = serializers.Field()
481 fields = ('id','created','updated','enacted','slice','name','value',)
484 class NetworkTemplateSerializer(serializers.HyperlinkedModelSerializer):
485 id = serializers.Field()
488 model = NetworkTemplate
489 fields = ('id','created','updated','enacted','name','description','guaranteedBandwidth','visibility','translation','sharedNetworkName','sharedNetworkId',)
492 class RouterSerializer(serializers.HyperlinkedModelSerializer):
493 id = serializers.Field()
497 fields = ('id','created','updated','enacted','name','owner',)
500 class ServiceResourceSerializer(serializers.HyperlinkedModelSerializer):
501 id = serializers.Field()
504 model = ServiceResource
505 fields = ('id','created','updated','enacted','serviceClass','name','maxUnitsDeployment','maxUnitsNode','maxDuration','bucketInRate','bucketMaxSize','cost','calendarReservable',)
510 ServiceAttribute: ServiceAttributeSerializer,
512 Image: ImageSerializer,
514 NetworkParameter: NetworkParameterSerializer,
516 Site: SiteSerializer,
518 SliceRole: SliceRoleSerializer,
522 Invoice: InvoiceSerializer,
524 PlanetStackRole: PlanetStackRoleSerializer,
526 SlicePrivilege: SlicePrivilegeSerializer,
528 NetworkSliver: NetworkSliverSerializer,
530 NetworkDeployments: NetworkDeploymentsSerializer,
532 Slice: SliceSerializer,
534 Network: NetworkSerializer,
536 Service: ServiceSerializer,
538 ServiceClass: ServiceClassSerializer,
540 Payment: PaymentSerializer,
542 Charge: ChargeSerializer,
544 Role: RoleSerializer,
546 UsableObject: UsableObjectSerializer,
548 SiteRole: SiteRoleSerializer,
550 Sliver: SliverSerializer,
552 Node: NodeSerializer,
554 DashboardView: DashboardViewSerializer,
556 ImageDeployments: ImageDeploymentsSerializer,
558 ReservedResource: ReservedResourceSerializer,
560 NetworkSlice: NetworkSliceSerializer,
562 UserDashboardView: UserDashboardViewSerializer,
564 PlanetStackPrivilege: PlanetStackPrivilegeSerializer,
566 User: UserSerializer,
568 Deployment: DeploymentSerializer,
570 Reservation: ReservationSerializer,
572 SliceDeployments: SliceDeploymentsSerializer,
574 SitePrivilege: SitePrivilegeSerializer,
576 PlanetStack: PlanetStackSerializer,
578 UserDeployments: UserDeploymentsSerializer,
580 Account: AccountSerializer,
582 NetworkParameterType: NetworkParameterTypeSerializer,
584 SiteDeployments: SiteDeploymentsSerializer,
586 DeploymentPrivilege: DeploymentPrivilegeSerializer,
588 DeploymentRole: DeploymentRoleSerializer,
590 Project: ProjectSerializer,
592 SliceTag: SliceTagSerializer,
594 NetworkTemplate: NetworkTemplateSerializer,
596 Router: RouterSerializer,
598 ServiceResource: ServiceResourceSerializer,
603 # Based on core/views/*.py
606 class ServiceAttributeList(generics.ListCreateAPIView):
607 queryset = ServiceAttribute.objects.select_related().all()
608 serializer_class = ServiceAttributeSerializer
610 def get_queryset(self):
611 return ServiceAttribute.select_by_user(self.request.user)
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)
620 return Response(status=status.HTTP_400_BAD_REQUEST)
622 class ServiceAttributeDetail(generics.RetrieveUpdateDestroyAPIView):
623 queryset = ServiceAttribute.objects.select_related().all()
624 serializer_class = ServiceAttributeSerializer
626 def get_queryset(self):
627 return ServiceAttribute.select_by_user(self.request.user)
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)
634 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
641 return Response(status=status.HTTP_400_BAD_REQUEST)
646 class ImageList(generics.ListCreateAPIView):
647 queryset = Image.objects.select_related().all()
648 serializer_class = ImageSerializer
650 def get_queryset(self):
651 return Image.select_by_user(self.request.user)
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)
660 return Response(status=status.HTTP_400_BAD_REQUEST)
662 class ImageDetail(generics.RetrieveUpdateDestroyAPIView):
663 queryset = Image.objects.select_related().all()
664 serializer_class = ImageSerializer
666 def get_queryset(self):
667 return Image.select_by_user(self.request.user)
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)
674 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
681 return Response(status=status.HTTP_400_BAD_REQUEST)
686 class NetworkParameterList(generics.ListCreateAPIView):
687 queryset = NetworkParameter.objects.select_related().all()
688 serializer_class = NetworkParameterSerializer
690 def get_queryset(self):
691 return NetworkParameter.select_by_user(self.request.user)
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)
700 return Response(status=status.HTTP_400_BAD_REQUEST)
702 class NetworkParameterDetail(generics.RetrieveUpdateDestroyAPIView):
703 queryset = NetworkParameter.objects.select_related().all()
704 serializer_class = NetworkParameterSerializer
706 def get_queryset(self):
707 return NetworkParameter.select_by_user(self.request.user)
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)
714 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
721 return Response(status=status.HTTP_400_BAD_REQUEST)
726 class SiteList(generics.ListCreateAPIView):
727 queryset = Site.objects.select_related().all()
728 serializer_class = SiteSerializer
730 def get_queryset(self):
731 return Site.select_by_user(self.request.user)
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)
740 return Response(status=status.HTTP_400_BAD_REQUEST)
742 class SiteDetail(generics.RetrieveUpdateDestroyAPIView):
743 queryset = Site.objects.select_related().all()
744 serializer_class = SiteSerializer
746 def get_queryset(self):
747 return Site.select_by_user(self.request.user)
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)
754 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
761 return Response(status=status.HTTP_400_BAD_REQUEST)
766 class SliceRoleList(generics.ListCreateAPIView):
767 queryset = SliceRole.objects.select_related().all()
768 serializer_class = SliceRoleSerializer
770 def get_queryset(self):
771 return SliceRole.select_by_user(self.request.user)
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)
780 return Response(status=status.HTTP_400_BAD_REQUEST)
782 class SliceRoleDetail(generics.RetrieveUpdateDestroyAPIView):
783 queryset = SliceRole.objects.select_related().all()
784 serializer_class = SliceRoleSerializer
786 def get_queryset(self):
787 return SliceRole.select_by_user(self.request.user)
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)
794 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
801 return Response(status=status.HTTP_400_BAD_REQUEST)
806 class TagList(generics.ListCreateAPIView):
807 queryset = Tag.objects.select_related().all()
808 serializer_class = TagSerializer
810 def get_queryset(self):
811 return Tag.select_by_user(self.request.user)
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)
820 return Response(status=status.HTTP_400_BAD_REQUEST)
822 class TagDetail(generics.RetrieveUpdateDestroyAPIView):
823 queryset = Tag.objects.select_related().all()
824 serializer_class = TagSerializer
826 def get_queryset(self):
827 return Tag.select_by_user(self.request.user)
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)
834 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
841 return Response(status=status.HTTP_400_BAD_REQUEST)
846 class InvoiceList(generics.ListCreateAPIView):
847 queryset = Invoice.objects.select_related().all()
848 serializer_class = InvoiceSerializer
850 def get_queryset(self):
851 return Invoice.select_by_user(self.request.user)
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)
860 return Response(status=status.HTTP_400_BAD_REQUEST)
862 class InvoiceDetail(generics.RetrieveUpdateDestroyAPIView):
863 queryset = Invoice.objects.select_related().all()
864 serializer_class = InvoiceSerializer
866 def get_queryset(self):
867 return Invoice.select_by_user(self.request.user)
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)
874 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
881 return Response(status=status.HTTP_400_BAD_REQUEST)
886 class PlanetStackRoleList(generics.ListCreateAPIView):
887 queryset = PlanetStackRole.objects.select_related().all()
888 serializer_class = PlanetStackRoleSerializer
890 def get_queryset(self):
891 return PlanetStackRole.select_by_user(self.request.user)
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)
900 return Response(status=status.HTTP_400_BAD_REQUEST)
902 class PlanetStackRoleDetail(generics.RetrieveUpdateDestroyAPIView):
903 queryset = PlanetStackRole.objects.select_related().all()
904 serializer_class = PlanetStackRoleSerializer
906 def get_queryset(self):
907 return PlanetStackRole.select_by_user(self.request.user)
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)
914 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
921 return Response(status=status.HTTP_400_BAD_REQUEST)
926 class SlicePrivilegeList(generics.ListCreateAPIView):
927 queryset = SlicePrivilege.objects.select_related().all()
928 serializer_class = SlicePrivilegeSerializer
930 def get_queryset(self):
931 return SlicePrivilege.select_by_user(self.request.user)
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)
940 return Response(status=status.HTTP_400_BAD_REQUEST)
942 class SlicePrivilegeDetail(generics.RetrieveUpdateDestroyAPIView):
943 queryset = SlicePrivilege.objects.select_related().all()
944 serializer_class = SlicePrivilegeSerializer
946 def get_queryset(self):
947 return SlicePrivilege.select_by_user(self.request.user)
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)
954 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
961 return Response(status=status.HTTP_400_BAD_REQUEST)
966 class NetworkSliverList(generics.ListCreateAPIView):
967 queryset = NetworkSliver.objects.select_related().all()
968 serializer_class = NetworkSliverSerializer
970 def get_queryset(self):
971 return NetworkSliver.select_by_user(self.request.user)
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)
980 return Response(status=status.HTTP_400_BAD_REQUEST)
982 class NetworkSliverDetail(generics.RetrieveUpdateDestroyAPIView):
983 queryset = NetworkSliver.objects.select_related().all()
984 serializer_class = NetworkSliverSerializer
986 def get_queryset(self):
987 return NetworkSliver.select_by_user(self.request.user)
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)
994 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1001 return Response(status=status.HTTP_400_BAD_REQUEST)
1006 class NetworkDeploymentsList(generics.ListCreateAPIView):
1007 queryset = NetworkDeployments.objects.select_related().all()
1008 serializer_class = NetworkDeploymentsSerializer
1010 def get_queryset(self):
1011 return NetworkDeployments.select_by_user(self.request.user)
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)
1020 return Response(status=status.HTTP_400_BAD_REQUEST)
1022 class NetworkDeploymentsDetail(generics.RetrieveUpdateDestroyAPIView):
1023 queryset = NetworkDeployments.objects.select_related().all()
1024 serializer_class = NetworkDeploymentsSerializer
1026 def get_queryset(self):
1027 return NetworkDeployments.select_by_user(self.request.user)
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)
1034 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1041 return Response(status=status.HTTP_400_BAD_REQUEST)
1046 class SliceList(generics.ListCreateAPIView):
1047 queryset = Slice.objects.select_related().all()
1048 serializer_class = SliceSerializer
1050 def get_queryset(self):
1051 return Slice.select_by_user(self.request.user)
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)
1060 return Response(status=status.HTTP_400_BAD_REQUEST)
1062 class SliceDetail(generics.RetrieveUpdateDestroyAPIView):
1063 queryset = Slice.objects.select_related().all()
1064 serializer_class = SliceSerializer
1066 def get_queryset(self):
1067 return Slice.select_by_user(self.request.user)
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)
1074 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1081 return Response(status=status.HTTP_400_BAD_REQUEST)
1086 class NetworkList(generics.ListCreateAPIView):
1087 queryset = Network.objects.select_related().all()
1088 serializer_class = NetworkSerializer
1090 def get_queryset(self):
1091 return Network.select_by_user(self.request.user)
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)
1100 return Response(status=status.HTTP_400_BAD_REQUEST)
1102 class NetworkDetail(generics.RetrieveUpdateDestroyAPIView):
1103 queryset = Network.objects.select_related().all()
1104 serializer_class = NetworkSerializer
1106 def get_queryset(self):
1107 return Network.select_by_user(self.request.user)
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)
1114 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1121 return Response(status=status.HTTP_400_BAD_REQUEST)
1126 class ServiceList(generics.ListCreateAPIView):
1127 queryset = Service.objects.select_related().all()
1128 serializer_class = ServiceSerializer
1130 def get_queryset(self):
1131 return Service.select_by_user(self.request.user)
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)
1140 return Response(status=status.HTTP_400_BAD_REQUEST)
1142 class ServiceDetail(generics.RetrieveUpdateDestroyAPIView):
1143 queryset = Service.objects.select_related().all()
1144 serializer_class = ServiceSerializer
1146 def get_queryset(self):
1147 return Service.select_by_user(self.request.user)
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)
1154 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1161 return Response(status=status.HTTP_400_BAD_REQUEST)
1166 class ServiceClassList(generics.ListCreateAPIView):
1167 queryset = ServiceClass.objects.select_related().all()
1168 serializer_class = ServiceClassSerializer
1170 def get_queryset(self):
1171 return ServiceClass.select_by_user(self.request.user)
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)
1180 return Response(status=status.HTTP_400_BAD_REQUEST)
1182 class ServiceClassDetail(generics.RetrieveUpdateDestroyAPIView):
1183 queryset = ServiceClass.objects.select_related().all()
1184 serializer_class = ServiceClassSerializer
1186 def get_queryset(self):
1187 return ServiceClass.select_by_user(self.request.user)
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)
1194 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1201 return Response(status=status.HTTP_400_BAD_REQUEST)
1206 class PaymentList(generics.ListCreateAPIView):
1207 queryset = Payment.objects.select_related().all()
1208 serializer_class = PaymentSerializer
1210 def get_queryset(self):
1211 return Payment.select_by_user(self.request.user)
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)
1220 return Response(status=status.HTTP_400_BAD_REQUEST)
1222 class PaymentDetail(generics.RetrieveUpdateDestroyAPIView):
1223 queryset = Payment.objects.select_related().all()
1224 serializer_class = PaymentSerializer
1226 def get_queryset(self):
1227 return Payment.select_by_user(self.request.user)
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)
1234 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1241 return Response(status=status.HTTP_400_BAD_REQUEST)
1246 class ChargeList(generics.ListCreateAPIView):
1247 queryset = Charge.objects.select_related().all()
1248 serializer_class = ChargeSerializer
1250 def get_queryset(self):
1251 return Charge.select_by_user(self.request.user)
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)
1260 return Response(status=status.HTTP_400_BAD_REQUEST)
1262 class ChargeDetail(generics.RetrieveUpdateDestroyAPIView):
1263 queryset = Charge.objects.select_related().all()
1264 serializer_class = ChargeSerializer
1266 def get_queryset(self):
1267 return Charge.select_by_user(self.request.user)
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)
1274 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1281 return Response(status=status.HTTP_400_BAD_REQUEST)
1286 class RoleList(generics.ListCreateAPIView):
1287 queryset = Role.objects.select_related().all()
1288 serializer_class = RoleSerializer
1290 def get_queryset(self):
1291 return Role.select_by_user(self.request.user)
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)
1300 return Response(status=status.HTTP_400_BAD_REQUEST)
1302 class RoleDetail(generics.RetrieveUpdateDestroyAPIView):
1303 queryset = Role.objects.select_related().all()
1304 serializer_class = RoleSerializer
1306 def get_queryset(self):
1307 return Role.select_by_user(self.request.user)
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)
1314 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1321 return Response(status=status.HTTP_400_BAD_REQUEST)
1326 class UsableObjectList(generics.ListCreateAPIView):
1327 queryset = UsableObject.objects.select_related().all()
1328 serializer_class = UsableObjectSerializer
1330 def get_queryset(self):
1331 return UsableObject.select_by_user(self.request.user)
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)
1340 return Response(status=status.HTTP_400_BAD_REQUEST)
1342 class UsableObjectDetail(generics.RetrieveUpdateDestroyAPIView):
1343 queryset = UsableObject.objects.select_related().all()
1344 serializer_class = UsableObjectSerializer
1346 def get_queryset(self):
1347 return UsableObject.select_by_user(self.request.user)
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)
1354 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1361 return Response(status=status.HTTP_400_BAD_REQUEST)
1366 class SiteRoleList(generics.ListCreateAPIView):
1367 queryset = SiteRole.objects.select_related().all()
1368 serializer_class = SiteRoleSerializer
1370 def get_queryset(self):
1371 return SiteRole.select_by_user(self.request.user)
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)
1380 return Response(status=status.HTTP_400_BAD_REQUEST)
1382 class SiteRoleDetail(generics.RetrieveUpdateDestroyAPIView):
1383 queryset = SiteRole.objects.select_related().all()
1384 serializer_class = SiteRoleSerializer
1386 def get_queryset(self):
1387 return SiteRole.select_by_user(self.request.user)
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)
1394 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1401 return Response(status=status.HTTP_400_BAD_REQUEST)
1406 class SliverList(generics.ListCreateAPIView):
1407 queryset = Sliver.objects.select_related().all()
1408 serializer_class = SliverSerializer
1410 def get_queryset(self):
1411 return Sliver.select_by_user(self.request.user)
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)
1420 return Response(status=status.HTTP_400_BAD_REQUEST)
1422 class SliverDetail(generics.RetrieveUpdateDestroyAPIView):
1423 queryset = Sliver.objects.select_related().all()
1424 serializer_class = SliverSerializer
1426 def get_queryset(self):
1427 return Sliver.select_by_user(self.request.user)
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)
1434 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1441 return Response(status=status.HTTP_400_BAD_REQUEST)
1446 class NodeList(generics.ListCreateAPIView):
1447 queryset = Node.objects.select_related().all()
1448 serializer_class = NodeSerializer
1450 def get_queryset(self):
1451 return Node.select_by_user(self.request.user)
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)
1460 return Response(status=status.HTTP_400_BAD_REQUEST)
1462 class NodeDetail(generics.RetrieveUpdateDestroyAPIView):
1463 queryset = Node.objects.select_related().all()
1464 serializer_class = NodeSerializer
1466 def get_queryset(self):
1467 return Node.select_by_user(self.request.user)
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)
1474 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1481 return Response(status=status.HTTP_400_BAD_REQUEST)
1486 class DashboardViewList(generics.ListCreateAPIView):
1487 queryset = DashboardView.objects.select_related().all()
1488 serializer_class = DashboardViewSerializer
1490 def get_queryset(self):
1491 return DashboardView.select_by_user(self.request.user)
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)
1500 return Response(status=status.HTTP_400_BAD_REQUEST)
1502 class DashboardViewDetail(generics.RetrieveUpdateDestroyAPIView):
1503 queryset = DashboardView.objects.select_related().all()
1504 serializer_class = DashboardViewSerializer
1506 def get_queryset(self):
1507 return DashboardView.select_by_user(self.request.user)
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)
1514 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1521 return Response(status=status.HTTP_400_BAD_REQUEST)
1526 class ImageDeploymentsList(generics.ListCreateAPIView):
1527 queryset = ImageDeployments.objects.select_related().all()
1528 serializer_class = ImageDeploymentsSerializer
1530 def get_queryset(self):
1531 return ImageDeployments.select_by_user(self.request.user)
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)
1540 return Response(status=status.HTTP_400_BAD_REQUEST)
1542 class ImageDeploymentsDetail(generics.RetrieveUpdateDestroyAPIView):
1543 queryset = ImageDeployments.objects.select_related().all()
1544 serializer_class = ImageDeploymentsSerializer
1546 def get_queryset(self):
1547 return ImageDeployments.select_by_user(self.request.user)
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)
1554 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1561 return Response(status=status.HTTP_400_BAD_REQUEST)
1566 class ReservedResourceList(generics.ListCreateAPIView):
1567 queryset = ReservedResource.objects.select_related().all()
1568 serializer_class = ReservedResourceSerializer
1570 def get_queryset(self):
1571 return ReservedResource.select_by_user(self.request.user)
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)
1580 return Response(status=status.HTTP_400_BAD_REQUEST)
1582 class ReservedResourceDetail(generics.RetrieveUpdateDestroyAPIView):
1583 queryset = ReservedResource.objects.select_related().all()
1584 serializer_class = ReservedResourceSerializer
1586 def get_queryset(self):
1587 return ReservedResource.select_by_user(self.request.user)
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)
1594 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1601 return Response(status=status.HTTP_400_BAD_REQUEST)
1606 class NetworkSliceList(generics.ListCreateAPIView):
1607 queryset = NetworkSlice.objects.select_related().all()
1608 serializer_class = NetworkSliceSerializer
1610 def get_queryset(self):
1611 return NetworkSlice.select_by_user(self.request.user)
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)
1620 return Response(status=status.HTTP_400_BAD_REQUEST)
1622 class NetworkSliceDetail(generics.RetrieveUpdateDestroyAPIView):
1623 queryset = NetworkSlice.objects.select_related().all()
1624 serializer_class = NetworkSliceSerializer
1626 def get_queryset(self):
1627 return NetworkSlice.select_by_user(self.request.user)
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)
1634 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1641 return Response(status=status.HTTP_400_BAD_REQUEST)
1646 class UserDashboardViewList(generics.ListCreateAPIView):
1647 queryset = UserDashboardView.objects.select_related().all()
1648 serializer_class = UserDashboardViewSerializer
1650 def get_queryset(self):
1651 return UserDashboardView.select_by_user(self.request.user)
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)
1660 return Response(status=status.HTTP_400_BAD_REQUEST)
1662 class UserDashboardViewDetail(generics.RetrieveUpdateDestroyAPIView):
1663 queryset = UserDashboardView.objects.select_related().all()
1664 serializer_class = UserDashboardViewSerializer
1666 def get_queryset(self):
1667 return UserDashboardView.select_by_user(self.request.user)
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)
1674 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1681 return Response(status=status.HTTP_400_BAD_REQUEST)
1686 class PlanetStackPrivilegeList(generics.ListCreateAPIView):
1687 queryset = PlanetStackPrivilege.objects.select_related().all()
1688 serializer_class = PlanetStackPrivilegeSerializer
1690 def get_queryset(self):
1691 return PlanetStackPrivilege.select_by_user(self.request.user)
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)
1700 return Response(status=status.HTTP_400_BAD_REQUEST)
1702 class PlanetStackPrivilegeDetail(generics.RetrieveUpdateDestroyAPIView):
1703 queryset = PlanetStackPrivilege.objects.select_related().all()
1704 serializer_class = PlanetStackPrivilegeSerializer
1706 def get_queryset(self):
1707 return PlanetStackPrivilege.select_by_user(self.request.user)
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)
1714 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1721 return Response(status=status.HTTP_400_BAD_REQUEST)
1726 class UserList(generics.ListCreateAPIView):
1727 queryset = User.objects.select_related().all()
1728 serializer_class = UserSerializer
1730 def get_queryset(self):
1731 return User.select_by_user(self.request.user)
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)
1740 return Response(status=status.HTTP_400_BAD_REQUEST)
1742 class UserDetail(generics.RetrieveUpdateDestroyAPIView):
1743 queryset = User.objects.select_related().all()
1744 serializer_class = UserSerializer
1746 def get_queryset(self):
1747 return User.select_by_user(self.request.user)
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)
1754 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1761 return Response(status=status.HTTP_400_BAD_REQUEST)
1766 class DeploymentList(generics.ListCreateAPIView):
1767 queryset = Deployment.objects.select_related().all()
1768 serializer_class = DeploymentSerializer
1770 def get_queryset(self):
1771 return Deployment.select_by_user(self.request.user)
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)
1780 return Response(status=status.HTTP_400_BAD_REQUEST)
1782 class DeploymentDetail(generics.RetrieveUpdateDestroyAPIView):
1783 queryset = Deployment.objects.select_related().all()
1784 serializer_class = DeploymentSerializer
1786 def get_queryset(self):
1787 return Deployment.select_by_user(self.request.user)
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)
1794 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1801 return Response(status=status.HTTP_400_BAD_REQUEST)
1806 class ReservationList(generics.ListCreateAPIView):
1807 queryset = Reservation.objects.select_related().all()
1808 serializer_class = ReservationSerializer
1810 def get_queryset(self):
1811 return Reservation.select_by_user(self.request.user)
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)
1820 return Response(status=status.HTTP_400_BAD_REQUEST)
1822 class ReservationDetail(generics.RetrieveUpdateDestroyAPIView):
1823 queryset = Reservation.objects.select_related().all()
1824 serializer_class = ReservationSerializer
1826 def get_queryset(self):
1827 return Reservation.select_by_user(self.request.user)
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)
1834 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1841 return Response(status=status.HTTP_400_BAD_REQUEST)
1846 class SliceDeploymentsList(generics.ListCreateAPIView):
1847 queryset = SliceDeployments.objects.select_related().all()
1848 serializer_class = SliceDeploymentsSerializer
1850 def get_queryset(self):
1851 return SliceDeployments.select_by_user(self.request.user)
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)
1860 return Response(status=status.HTTP_400_BAD_REQUEST)
1862 class SliceDeploymentsDetail(generics.RetrieveUpdateDestroyAPIView):
1863 queryset = SliceDeployments.objects.select_related().all()
1864 serializer_class = SliceDeploymentsSerializer
1866 def get_queryset(self):
1867 return SliceDeployments.select_by_user(self.request.user)
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)
1874 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1881 return Response(status=status.HTTP_400_BAD_REQUEST)
1886 class SitePrivilegeList(generics.ListCreateAPIView):
1887 queryset = SitePrivilege.objects.select_related().all()
1888 serializer_class = SitePrivilegeSerializer
1890 def get_queryset(self):
1891 return SitePrivilege.select_by_user(self.request.user)
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)
1900 return Response(status=status.HTTP_400_BAD_REQUEST)
1902 class SitePrivilegeDetail(generics.RetrieveUpdateDestroyAPIView):
1903 queryset = SitePrivilege.objects.select_related().all()
1904 serializer_class = SitePrivilegeSerializer
1906 def get_queryset(self):
1907 return SitePrivilege.select_by_user(self.request.user)
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)
1914 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1921 return Response(status=status.HTTP_400_BAD_REQUEST)
1926 class PlanetStackList(generics.ListCreateAPIView):
1927 queryset = PlanetStack.objects.select_related().all()
1928 serializer_class = PlanetStackSerializer
1930 def get_queryset(self):
1931 return PlanetStack.select_by_user(self.request.user)
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)
1940 return Response(status=status.HTTP_400_BAD_REQUEST)
1942 class PlanetStackDetail(generics.RetrieveUpdateDestroyAPIView):
1943 queryset = PlanetStack.objects.select_related().all()
1944 serializer_class = PlanetStackSerializer
1946 def get_queryset(self):
1947 return PlanetStack.select_by_user(self.request.user)
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)
1954 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
1961 return Response(status=status.HTTP_400_BAD_REQUEST)
1966 class UserDeploymentsList(generics.ListCreateAPIView):
1967 queryset = UserDeployments.objects.select_related().all()
1968 serializer_class = UserDeploymentsSerializer
1970 def get_queryset(self):
1971 return UserDeployments.select_by_user(self.request.user)
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)
1980 return Response(status=status.HTTP_400_BAD_REQUEST)
1982 class UserDeploymentsDetail(generics.RetrieveUpdateDestroyAPIView):
1983 queryset = UserDeployments.objects.select_related().all()
1984 serializer_class = UserDeploymentsSerializer
1986 def get_queryset(self):
1987 return UserDeployments.select_by_user(self.request.user)
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)
1994 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2001 return Response(status=status.HTTP_400_BAD_REQUEST)
2006 class AccountList(generics.ListCreateAPIView):
2007 queryset = Account.objects.select_related().all()
2008 serializer_class = AccountSerializer
2010 def get_queryset(self):
2011 return Account.select_by_user(self.request.user)
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)
2020 return Response(status=status.HTTP_400_BAD_REQUEST)
2022 class AccountDetail(generics.RetrieveUpdateDestroyAPIView):
2023 queryset = Account.objects.select_related().all()
2024 serializer_class = AccountSerializer
2026 def get_queryset(self):
2027 return Account.select_by_user(self.request.user)
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)
2034 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2041 return Response(status=status.HTTP_400_BAD_REQUEST)
2046 class NetworkParameterTypeList(generics.ListCreateAPIView):
2047 queryset = NetworkParameterType.objects.select_related().all()
2048 serializer_class = NetworkParameterTypeSerializer
2050 def get_queryset(self):
2051 return NetworkParameterType.select_by_user(self.request.user)
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)
2060 return Response(status=status.HTTP_400_BAD_REQUEST)
2062 class NetworkParameterTypeDetail(generics.RetrieveUpdateDestroyAPIView):
2063 queryset = NetworkParameterType.objects.select_related().all()
2064 serializer_class = NetworkParameterTypeSerializer
2066 def get_queryset(self):
2067 return NetworkParameterType.select_by_user(self.request.user)
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)
2074 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2081 return Response(status=status.HTTP_400_BAD_REQUEST)
2086 class SiteDeploymentsList(generics.ListCreateAPIView):
2087 queryset = SiteDeployments.objects.select_related().all()
2088 serializer_class = SiteDeploymentsSerializer
2090 def get_queryset(self):
2091 return SiteDeployments.select_by_user(self.request.user)
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)
2100 return Response(status=status.HTTP_400_BAD_REQUEST)
2102 class SiteDeploymentsDetail(generics.RetrieveUpdateDestroyAPIView):
2103 queryset = SiteDeployments.objects.select_related().all()
2104 serializer_class = SiteDeploymentsSerializer
2106 def get_queryset(self):
2107 return SiteDeployments.select_by_user(self.request.user)
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)
2114 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2121 return Response(status=status.HTTP_400_BAD_REQUEST)
2126 class DeploymentPrivilegeList(generics.ListCreateAPIView):
2127 queryset = DeploymentPrivilege.objects.select_related().all()
2128 serializer_class = DeploymentPrivilegeSerializer
2130 def get_queryset(self):
2131 return DeploymentPrivilege.select_by_user(self.request.user)
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)
2140 return Response(status=status.HTTP_400_BAD_REQUEST)
2142 class DeploymentPrivilegeDetail(generics.RetrieveUpdateDestroyAPIView):
2143 queryset = DeploymentPrivilege.objects.select_related().all()
2144 serializer_class = DeploymentPrivilegeSerializer
2146 def get_queryset(self):
2147 return DeploymentPrivilege.select_by_user(self.request.user)
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)
2154 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2161 return Response(status=status.HTTP_400_BAD_REQUEST)
2166 class DeploymentRoleList(generics.ListCreateAPIView):
2167 queryset = DeploymentRole.objects.select_related().all()
2168 serializer_class = DeploymentRoleSerializer
2170 def get_queryset(self):
2171 return DeploymentRole.select_by_user(self.request.user)
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)
2180 return Response(status=status.HTTP_400_BAD_REQUEST)
2182 class DeploymentRoleDetail(generics.RetrieveUpdateDestroyAPIView):
2183 queryset = DeploymentRole.objects.select_related().all()
2184 serializer_class = DeploymentRoleSerializer
2186 def get_queryset(self):
2187 return DeploymentRole.select_by_user(self.request.user)
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)
2194 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2201 return Response(status=status.HTTP_400_BAD_REQUEST)
2206 class ProjectList(generics.ListCreateAPIView):
2207 queryset = Project.objects.select_related().all()
2208 serializer_class = ProjectSerializer
2210 def get_queryset(self):
2211 return Project.select_by_user(self.request.user)
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)
2220 return Response(status=status.HTTP_400_BAD_REQUEST)
2222 class ProjectDetail(generics.RetrieveUpdateDestroyAPIView):
2223 queryset = Project.objects.select_related().all()
2224 serializer_class = ProjectSerializer
2226 def get_queryset(self):
2227 return Project.select_by_user(self.request.user)
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)
2234 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2241 return Response(status=status.HTTP_400_BAD_REQUEST)
2246 class SliceTagList(generics.ListCreateAPIView):
2247 queryset = SliceTag.objects.select_related().all()
2248 serializer_class = SliceTagSerializer
2250 def get_queryset(self):
2251 return SliceTag.select_by_user(self.request.user)
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)
2260 return Response(status=status.HTTP_400_BAD_REQUEST)
2262 class SliceTagDetail(generics.RetrieveUpdateDestroyAPIView):
2263 queryset = SliceTag.objects.select_related().all()
2264 serializer_class = SliceTagSerializer
2266 def get_queryset(self):
2267 return SliceTag.select_by_user(self.request.user)
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)
2274 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2281 return Response(status=status.HTTP_400_BAD_REQUEST)
2286 class NetworkTemplateList(generics.ListCreateAPIView):
2287 queryset = NetworkTemplate.objects.select_related().all()
2288 serializer_class = NetworkTemplateSerializer
2290 def get_queryset(self):
2291 return NetworkTemplate.select_by_user(self.request.user)
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)
2300 return Response(status=status.HTTP_400_BAD_REQUEST)
2302 class NetworkTemplateDetail(generics.RetrieveUpdateDestroyAPIView):
2303 queryset = NetworkTemplate.objects.select_related().all()
2304 serializer_class = NetworkTemplateSerializer
2306 def get_queryset(self):
2307 return NetworkTemplate.select_by_user(self.request.user)
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)
2314 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2321 return Response(status=status.HTTP_400_BAD_REQUEST)
2326 class RouterList(generics.ListCreateAPIView):
2327 queryset = Router.objects.select_related().all()
2328 serializer_class = RouterSerializer
2330 def get_queryset(self):
2331 return Router.select_by_user(self.request.user)
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)
2340 return Response(status=status.HTTP_400_BAD_REQUEST)
2342 class RouterDetail(generics.RetrieveUpdateDestroyAPIView):
2343 queryset = Router.objects.select_related().all()
2344 serializer_class = RouterSerializer
2346 def get_queryset(self):
2347 return Router.select_by_user(self.request.user)
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)
2354 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2361 return Response(status=status.HTTP_400_BAD_REQUEST)
2366 class ServiceResourceList(generics.ListCreateAPIView):
2367 queryset = ServiceResource.objects.select_related().all()
2368 serializer_class = ServiceResourceSerializer
2370 def get_queryset(self):
2371 return ServiceResource.select_by_user(self.request.user)
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)
2380 return Response(status=status.HTTP_400_BAD_REQUEST)
2382 class ServiceResourceDetail(generics.RetrieveUpdateDestroyAPIView):
2383 queryset = ServiceResource.objects.select_related().all()
2384 serializer_class = ServiceResourceSerializer
2386 def get_queryset(self):
2387 return ServiceResource.select_by_user(self.request.user)
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)
2394 return Response(status=status.HTTP_400_BAD_REQUEST)
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)
2401 return Response(status=status.HTTP_400_BAD_REQUEST)