base class stuff for xoslib methods from genapi
diff --git a/planetstack/core/xoslib/methods/plus.py b/planetstack/core/xoslib/methods/plus.py
index ca89c79..3a6f858 100644
--- a/planetstack/core/xoslib/methods/plus.py
+++ b/planetstack/core/xoslib/methods/plus.py
@@ -25,6 +25,28 @@
def getBackendHtml(self, obj):
return obj.getBackendHtml()
+# XXX this was lifted and hacked up a bit from genapi.py
+class PlusListCreateAPIView(generics.ListCreateAPIView):
+ def create(self, request, *args, **kwargs):
+ serializer = self.get_serializer(data=request.DATA, files=request.FILES)
+ if not (serializer.is_valid()):
+ response = {"error": "validation",
+ "specific_error": "not serializer.is_valid()",
+ "reasons": serializer.errors}
+ return Response(response, status=status.HTTP_400_BAD_REQUEST)
+ obj = serializer.object
+ obj.caller = request.user
+ if obj.can_update(request.user):
+ return super(PlusListCreateAPIView, self).create(request, *args, **kwargs)
+ else:
+ raise Exception("failed obj.can_update")
+
+ ret = super(PlusListCreateAPIView, self).create(request, *args, **kwargs)
+ if (ret.status_code%100 != 200):
+ raise Exception(ret.data)
+
+ return ret
+
# XXX this is taken from genapi.py
# XXX find a better way to re-use the code
class PlusRetrieveUpdateDestroyAPIView(generics.RetrieveUpdateDestroyAPIView):
diff --git a/planetstack/core/xoslib/methods/sliceplus.py b/planetstack/core/xoslib/methods/sliceplus.py
index f29e200..fa17c1c 100644
--- a/planetstack/core/xoslib/methods/sliceplus.py
+++ b/planetstack/core/xoslib/methods/sliceplus.py
@@ -6,7 +6,7 @@
from core.models import *
from django.forms import widgets
from core.xoslib.objects.sliceplus import SlicePlus
-from plus import PlusSerializerMixin, PlusRetrieveUpdateDestroyAPIView
+from plus import PlusSerializerMixin, PlusRetrieveUpdateDestroyAPIView, PlusListCreateAPIView
if hasattr(serializers, "ReadOnlyField"):
# rest_framework 3.x
@@ -51,7 +51,7 @@
fields = ('humanReadableName', 'id','created','updated','enacted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','image_preference','service','network','mount_data_sets',
'serviceClass','creator','networks','sliceInfo','network_ports','backendIcon','backendHtml','site_allocation')
-class SlicePlusList(generics.ListCreateAPIView):
+class SlicePlusList(PlusListCreateAPIView): #generics.ListCreateAPIView):
queryset = SlicePlus.objects.select_related().all()
serializer_class = SlicePlusIdSerializer
@@ -61,14 +61,6 @@
def get_queryset(self):
return SlicePlus.select_by_user(self.request.user)
- def create(self, request, *args, **kwargs):
- obj = self.get_object()
- obj.caller = request.user
- if obj.can_update(request.user):
- return super(SliceList, self).create(request, *args, **kwargs)
- else:
- return Response(status=status.HTTP_400_BAD_REQUEST)
-
class SlicePlusDetail(PlusRetrieveUpdateDestroyAPIView):
queryset = SlicePlus.objects.select_related().all()
serializer_class = SlicePlusIdSerializer