Re-implemented REST API and urls.
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index 8debfb2..114382f 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -402,9 +402,9 @@
class SliverAdmin(PlanetStackBaseAdmin):
form = SliverForm
fieldsets = [
- ('Sliver', {'fields': ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'key', 'node', 'deploymentNetwork']})
+ ('Sliver', {'fields': ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'node', 'deploymentNetwork']})
]
- list_display = ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'key', 'node', 'deploymentNetwork']
+ list_display = ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'node', 'deploymentNetwork']
inlines = [TagInline]
def formfield_for_foreignkey(self, db_field, request, **kwargs):
diff --git a/planetstack/core/api_root.py b/planetstack/core/api_root.py
index 61e76da..87e8924 100644
--- a/planetstack/core/api_root.py
+++ b/planetstack/core/api_root.py
@@ -5,14 +5,12 @@
@api_view(['GET'])
def api_root(request, format=None):
return Response({
- 'roles': reverse('role-list', request=request, format=format),
- 'users': reverse('user-list', request=request, format=format),
- 'keys': reverse('key-list', request=request, format=format),
- #'nodes': reverse('node-list', request=request, format=format),
+ 'deployments': reverse('deployment-list', request=request, format=format),
'sites': reverse('site-list', request=request, format=format),
- 'deploymentNetworks': reverse('deploymentnetwork-list', request=request, format=format),
+ 'users': reverse('user-list', request=request, format=format),
'slices': reverse('slice-list', request=request, format=format),
- 'subnets': reverse('subnet-list', request=request, format=format),
+ 'roles': reverse('role-list', request=request, format=format),
+ 'nodes': reverse('node-list', request=request, format=format),
'slivers': reverse('sliver-list', request=request, format=format),
'images': reverse('image-list', request=request, format=format),
})
diff --git a/planetstack/core/models/role.py b/planetstack/core/models/role.py
index f6c2f2c..fd29848 100644
--- a/planetstack/core/models/role.py
+++ b/planetstack/core/models/role.py
@@ -5,8 +5,8 @@
class Role(PlCoreBase):
- #ROLE_CHOICES = (('admin', 'Admin'), ('pi', 'Principle Investigator'), ('user','User'))
- role = models.CharField(null=True, blank=True,max_length=256, unique=True)
+ ROLE_CHOICES = (('admin', 'Admin'), ('pi', 'Principle Investigator'), ('tech', 'Technician'), ('user','User'))
+ role = models.CharField(null=True, blank=True,max_length=256, unique=True, choices=ROLE_CHOICES)
role_type = models.CharField(max_length=80, unique=True)
def __unicode__(self): return u'%s' % (self.role_type)
diff --git a/planetstack/core/serializers.py b/planetstack/core/serializers.py
index 00d7160..94f5c3c 100644
--- a/planetstack/core/serializers.py
+++ b/planetstack/core/serializers.py
@@ -9,7 +9,6 @@
class Meta:
model = Role
fields = ('id',
- 'role_id',
'role',
'role_type')
@@ -19,11 +18,10 @@
id = serializers.Field()
site = serializers.HyperlinkedRelatedField(view_name='site-detail')
slice_memberships = serializers.HyperlinkedRelatedField(view_name='slice-membership-detail')
- site_privileges = serializers.HyperlinkedRelatedField(view_name='site-privilege-detail')
+ site_privileges = serializers.HyperlinkedRelatedField(view_name='siteprivilege-detail')
class Meta:
model = User
fields = ('id',
- 'user_id',
'kuser_id',
'firstname',
'lastname',
@@ -66,7 +64,7 @@
user = serializers.HyperlinkedRelatedField(view_name='user-detail')
role = serializers.HyperlinkedRelatedField(view_name='role-detail')
class Meta:
- model = SitePrivilege
+ model = SliceMembership
fields = ('id',
'user',
'slice',
@@ -115,7 +113,7 @@
# HyperlinkedModelSerializer doesn't include the id by default
id = serializers.Field()
- sites = serializers.HyperlinkedRelatedField(view_name='deploymentnetwork-detail')
+ sites = serializers.HyperlinkedRelatedField(view_name='site-detail')
class Meta:
model = Deployment
fields = ('id',
@@ -127,9 +125,8 @@
# HyperlinkedModelSerializer doesn't include the id by default
id = serializers.Field()
image = serializers.HyperlinkedRelatedField(view_name='image-detail')
- key = serializers.HyperlinkedRelatedField(view_name='key-detail')
slice = serializers.HyperlinkedRelatedField(view_name='slice-detail')
- deployment_network = serializers.HyperlinkedRelatedField(view_name='deployment_network-detail')
+ deployment = serializers.HyperlinkedRelatedField(view_name='deployment-detail')
node = serializers.HyperlinkedRelatedField(view_name='node-detail')
@@ -143,9 +140,8 @@
'instance_name',
'ip',
'image',
- 'key',
'slice',
- 'deploymentNetwork',
+ 'deployment',
'node')
class NodeSerializer(serializers.HyperlinkedModelSerializer):
diff --git a/planetstack/core/views/deployment_networks.py b/planetstack/core/views/deployment_networks.py
index ef569ac..285a53a 100644
--- a/planetstack/core/views/deployment_networks.py
+++ b/planetstack/core/views/deployment_networks.py
@@ -1,59 +1,12 @@
-from django.http import Http404
-from rest_framework.views import APIView
-from rest_framework.response import Response
-from rest_framework import status
-
-from core.api.deployment_networks import add_deployment_network, delete_deployment_network, get_deployment_networks
from core.serializers import DeploymentSerializer
-from util.request import parse_request
+from rest_framework import generics
+from core.models import Deployment
+class DeploymentList(generics.ListCreateAPIView):
+ queryset = Deployment.objects.all()
+ serializer_class = DeploymentSerializer
-class DeploymentListCreate(APIView):
- """
- List all deployment networks or create a new role.
- """
+class DeploymentDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = Deployment.objects.all()
+ serializer_class = DeploymentSerializer
- def post(self, request, format = None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'deploymentNetwork' in data:
-
- deployment = add_deployment_network(data['auth'], data['deploymentNetwork'].get('name'))
- serializer = DeploymentSerializer(deployment)
- return Response(serializer.data, status=status.HTTP_201_CREATED)
- else:
- deployment_networks = get_deployment_networks(data['auth'])
- serializer = DeploymentSerializer(deployment_networks, many=True)
- return Response(serializer.data)
-
-
-class DeploymentRetrieveUpdateDestroy(APIView):
- """
- Retrieve, update or delete a deployment network
- """
-
- def post(self, request, pk, format=None):
- """Retrieve a deployment network"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- deployment_networks = get_deployment_networks(data['auth'], pk)
- if not deployment_networks:
- return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = DeploymentSerializer(deployment_networks[0])
- return Response(serializer.data)
-
- def put(self, request, pk, format=None):
- """deployment network update not implemnted"""
- return Response(status=status.HTTP_404_NOT_FOUND)
-
- def delete(self, request, pk, format=None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_deployment_network(data['auth'], pk)
- return Response(status=status.HTTP_204_NO_CONTENT)
-
-
-
diff --git a/planetstack/core/views/images.py b/planetstack/core/views/images.py
index 7e0ab59..5ea5d76 100644
--- a/planetstack/core/views/images.py
+++ b/planetstack/core/views/images.py
@@ -1,55 +1,12 @@
-from django.http import Http404
-from rest_framework.views import APIView
-from rest_framework.response import Response
-from rest_framework import status
-
-from core.api.images import add_image, delete_image, get_images
from core.serializers import ImageSerializer
-from util.request import parse_request
+from rest_framework import generics
+from core.models import Image
+class ImageList(generics.ListCreateAPIView):
+ queryset = Image.objects.all()
+ serializer_class = ImageSerializer
-class ImageListCreate(APIView):
- """
- List all images or create a new image.
- """
+class ImageDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = Image.objects.all()
+ serializer_class = ImageSerializer
- def post(self, request, format = None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'image' in data:
- """Not Implemented"""
- return Response(status=status.HTTP_404_NOT_FOUND)
- else:
- images = get_images(data['auth'])
- serializer = ImageSerializer(images, many=True)
- return Response(serializer.data)
-
-
-class ImageRetrieveUpdateDestroy(APIView):
- """
- Retrieve, update or delete an image
- """
-
- def post(self, request, pk, format=None):
- """Retrieve an image """
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- images = get_images(data['auth'], pk)
- if not images:
- return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = ImageSerializer(images[0])
- return Response(serializer.data)
-
- def put(self, request, pk, format=None):
- """update image not implemnted"""
- return Response(status=status.HTTP_404_NOT_FOUND)
-
- def delete(self, request, pk, format=None):
- """delete image not implemnted"""
- return Response(status=status.HTTP_404_NOT_FOUND)
-
-
-
-
diff --git a/planetstack/core/views/nodes.py b/planetstack/core/views/nodes.py
index 0f1977e..8706114 100644
--- a/planetstack/core/views/nodes.py
+++ b/planetstack/core/views/nodes.py
@@ -1,55 +1,13 @@
-from django.http import Http404
-from rest_framework.views import APIView
-from rest_framework.response import Response
-from rest_framework import status
-
-from core.api.nodes import add_node, delete_node, get_nodes, update_node
from core.serializers import NodeSerializer
-from util.request import parse_request
+from rest_framework import generics
+from core.models import Node
+
+class NodeList(generics.ListCreateAPIView):
+ queryset = Node.objects.all()
+ serializer_class = NodeSerializer
+
+class NodeDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = Node.objects.all()
+ serializer_class = NodeSerializer
-class NodeListCreate(APIView):
- """
- List all nodes or create a new node.
- """
-
- def post(self, request, format = None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'node' in data:
- """Not Implemented"""
- return Response(status=status.HTTP_404_NOT_FOUND)
- else:
- nodes = get_nodes(data['auth'])
- serializer = NodeSerializer(nodes, many=True)
- return Response(serializer.data)
-
-
-class NodeRetrieveUpdateDestroy(APIView):
- """
- Retrieve, update or delete an node
- """
-
- def post(self, request, pk, format=None):
- """Retrieve an node """
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- nodes = get_nodes(data['auth'], pk)
- if not nodes:
- return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = NodeSerializer(nodes[0])
- return Response(serializer.data)
-
- def put(self, request, pk, format=None):
- """update node not implemnted"""
- return Response(status=status.HTTP_404_NOT_FOUND)
-
- def delete(self, request, pk, format=None):
- """delete node not implemnted"""
- return Response(status=status.HTTP_404_NOT_FOUND)
-
-
-
-
diff --git a/planetstack/core/views/roles.py b/planetstack/core/views/roles.py
index 37bb149..13c9917 100644
--- a/planetstack/core/views/roles.py
+++ b/planetstack/core/views/roles.py
@@ -1,58 +1,13 @@
-from django.http import Http404
-from rest_framework.views import APIView
-from rest_framework.response import Response
-from rest_framework import status
-
-from core.api.roles import add_role, delete_role, get_roles
from core.serializers import RoleSerializer
-from util.request import parse_request
+from rest_framework import generics
+from core.models import Role
+
+class RoleList(generics.ListCreateAPIView):
+ queryset = Role.objects.all()
+ serializer_class = RoleSerializer
+
+class RoleDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = Role.objects.all()
+ serializer_class = RoleSerializer
-class RoleListCreate(APIView):
- """
- List all roles or create a new role.
- """
-
- def post(self, request, format = None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'role' in data:
- role = add_role(data['auth'], data['role']['role_type'])
- serializer = RoleSerializer(data=role)
- return Response(serializer.data, status=status.HTTP_201_CREATED)
- else:
- roles = get_roles(data['auth'])
- serializer = RoleSerializer(roles, many=True)
- return Response(serializer.data)
-
-
-class RoleRetrieveUpdateDestroy(APIView):
- """
- Retrieve, update or delete a role
- """
-
- def post(self, request, pk, format=None):
- """Retrieve a role"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- roles = get_roles(data['auth'], pk)
- if not roles:
- return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = RoleSerializer(roles[0])
- return Response(serializer.data)
-
- def put(self, request, pk, format=None):
- """role update not implemnted"""
- return Response(status=status.HTTP_404_NOT_FOUND)
-
- def delete(self, request, pk, format=None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_role(data['auth'], pk)
- return Response(status=status.HTTP_204_NO_CONTENT)
-
-
-
diff --git a/planetstack/core/views/site_privileges.py b/planetstack/core/views/site_privileges.py
index 37fc371..90053e5 100644
--- a/planetstack/core/views/site_privileges.py
+++ b/planetstack/core/views/site_privileges.py
@@ -1,66 +1,13 @@
-from django.http import Http404
-from rest_framework.views import APIView
-from rest_framework.response import Response
-from rest_framework import status
-
-from core.api.site_privileges import add_site_privilege, delete_site_privilege, get_site_privileges, update_site_privilege
from core.serializers import SitePrivilegeSerializer
-from util.request import parse_request
+from rest_framework import generics
+from core.models import SitePrivilege
+
+class SitePrivilegeList(generics.ListCreateAPIView):
+ queryset = SitePrivilege.objects.all()
+ serializer_class = SitePrivilegeSerializer
+
+class SitePrivilegeDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = SitePrivilege.objects.all()
+ serializer_class = SitePrivilegeSerializer
-class SitePrivilegeListCreate(APIView):
- """
- List all site_privileges or create a new site_privilege.
- """
-
- def post(self, request, format = None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'site_privilege' in data:
- site_privilege = add_site_privilege(data['auth'], data['site_privilege'])
- serializer = SitePrivilegeSerializer(site_privilege)
- return Response(serializer.data, status=status.HTTP_201_CREATED)
- else:
- site_privileges = get_site_privileges(data['auth'])
- serializer = SitePrivilegeSerializer(site_privileges, many=True)
- return Response(serializer.data)
-
-
-class SitePrivilegeRetrieveUpdateDestroy(APIView):
- """
- Retrieve, update or delete a site_privilege
- """
-
- def post(self, request, pk, format=None):
- """Retrieve a site_privilege"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- site_privileges = get_site_privileges(data['auth'], pk)
- if not site_privileges:
- return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = SitePrivilegeSerializer(site_privileges[0])
- return Response(serializer.data)
-
- def put(self, request, pk, format=None):
- """update a site_privilege"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'site_privilege' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
-
- site_privilege = update_site_privilege(pk, data['site_privilege'])
- serializer = SitePrivilegeSerializer(site_privilege)
- return Response(serializer.data)
-
- def delete(self, request, pk, format=None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_site_privilege(data['auth'], pk)
- return Response(status=status.HTTP_204_NO_CONTENT)
-
-
-
diff --git a/planetstack/core/views/sites.py b/planetstack/core/views/sites.py
index 6449b67..b4af8ac 100644
--- a/planetstack/core/views/sites.py
+++ b/planetstack/core/views/sites.py
@@ -1,66 +1,70 @@
-from django.http import Http404
-from rest_framework.views import APIView
-from rest_framework.response import Response
-from rest_framework import status
-
-from core.api.sites import add_site, delete_site, get_sites
from core.serializers import SiteSerializer
-from util.request import parse_request
+from rest_framework import generics
+from core.models import Site
+
+class SiteList(generics.ListCreateAPIView):
+ queryset = Site.objects.all()
+ serializer_class = SiteSerializer
+
+class SiteDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = Site.objects.all()
+ serializer_class = SiteSerializer
-class SiteListCreate(APIView):
- """
- List all sites or create a new site.
- """
- def post(self, request, format = None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'site' in data:
- site = add_site(data['auth'], data['site'])
- serializer = SiteSerializer(site)
- return Response(serializer.data, status=status.HTTP_201_CREATED)
- else:
- sites = get_sites(data['auth'])
- serializer = SiteSerializer(sites, many=True)
- return Response(serializer.data)
+#class SiteListCreate(APIView):
+###### """
+## List all sites or create a new site.
+# """
+#
+# def post(self, request, format = None):
+# data = parse_request(request.DATA)
+# if 'auth' not in data:
+# return Response(status=status.HTTP_400_BAD_REQUEST)
+# elif 'site' in data:
+# site = add_site(data['auth'], data['site'])
+# serializer = SiteSerializer(site)
+# return Response(serializer.data, status=status.HTTP_201_CREATED)
+# else:
+# sites = get_sites(data['auth'])
+# serializer = SiteSerializer(sites, many=True)
+# return Response(serializer.data)
-class SiteRetrieveUpdateDestroy(APIView):
- """
- Retrieve, update or delete a site
- """
-
- def post(self, request, pk, format=None):
- """Retrieve a site"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- sites = get_sites(data['auth'], {'id': pk})
- if not sites:
- return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = SiteSerializer(sites[0])
- return Response(serializer.data)
-
- def put(self, request, pk, format=None):
- """update a site"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'site' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
-
- site = update_site(pk, data['site'])
- serializer = SiteSerializer(site)
- return Response(serializer.data)
-
- def delete(self, request, pk, format=None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_site(data['auth'], {'id': pk})
- return Response(status=status.HTTP_204_NO_CONTENT)
-
-
-
+#class SiteRetrieveUpdateDestroy(APIView):
+# """
+# Retrieve, update or delete a site
+# """
+#
+# def post(self, request, pk, format=None):
+# """Retrieve a site"""
+# data = parse_request(request.DATA)
+# if 'auth' not in data:
+# return Response(status=status.HTTP_400_BAD_REQUEST)
+# sites = get_sites(data['auth'], {'id': pk})
+# if not sites:
+# return Response(status=status.HTTP_404_NOT_FOUND)
+# serializer = SiteSerializer(sites[0])
+# return Response(serializer.data)
+#
+# def put(self, request, pk, format=None):
+# """update a site"""
+# data = parse_request(request.DATA)
+# if 'auth' not in data:
+# return Response(status=status.HTTP_400_BAD_REQUEST)
+# elif 'site' not in data:
+# return Response(status=status.HTTP_400_BAD_REQUEST)
+#
+# site = update_site(pk, data['site'])
+# serializer = SiteSerializer(site)
+# return Response(serializer.data)
+#
+# def delete(self, request, pk, format=None):
+# data = parse_request(request.DATA)
+# if 'auth' not in data:
+# return Response(status=status.HTTP_400_BAD_REQUEST)
+# delete_site(data['auth'], {'id': pk})
+# return Response(status=status.HTTP_204_NO_CONTENT)
+#
+#
+##
diff --git a/planetstack/core/views/slice_memberships.py b/planetstack/core/views/slice_memberships.py
index 4bb581c..13f0707 100644
--- a/planetstack/core/views/slice_memberships.py
+++ b/planetstack/core/views/slice_memberships.py
@@ -1,66 +1,13 @@
-from django.http import Http404
-from rest_framework.views import APIView
-from rest_framework.response import Response
-from rest_framework import status
-
-from core.api.slice_memberships import add_slice_membership, delete_slice_membership, get_slice_memberships, update_slice_membership
from core.serializers import SliceMembershipSerializer
-from util.request import parse_request
+from rest_framework import generics
+from core.models import SliceMembership
+
+class SliceMembershipList(generics.ListCreateAPIView):
+ queryset = SliceMembership.objects.all()
+ serializer_class = SliceMembershipSerializer
+
+class SliceMembershipDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = SliceMembership.objects.all()
+ serializer_class = SliceMembershipSerializer
-class SliceMembershipListCreate(APIView):
- """
- List all slice_memberships or create a new slice_membership.
- """
-
- def post(self, request, format = None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'slice_membership' in data:
- slice_membership = add_slice_membership(data['auth'], data['slice_membership'])
- serializer = SliceMembershipSerializer(slice_membership)
- return Response(serializer.data, status=status.HTTP_201_CREATED)
- else:
- slice_memberships = get_slice_memberships(data['auth'])
- serializer = SliceMembershipSerializer(slice_memberships, many=True)
- return Response(serializer.data)
-
-
-class SliceMembershipRetrieveUpdateDestroy(APIView):
- """
- Retrieve, update or delete a slice_membership
- """
-
- def post(self, request, pk, format=None):
- """Retrieve a slice_membership"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- slice_memberships = get_slice_memberships(data['auth'], pk)
- if not slice_memberships:
- return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = SliceMembershipSerializer(slice_memberships[0])
- return Response(serializer.data)
-
- def put(self, request, pk, format=None):
- """update a slice_membership"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'slice_membership' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
-
- slice_membership = update_slice_membership(pk, data['slice_membership'])
- serializer = SliceMembershipSerializer(slice_membership)
- return Response(serializer.data)
-
- def delete(self, request, pk, format=None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_slice_membership(data['auth'], pk)
- return Response(status=status.HTTP_204_NO_CONTENT)
-
-
-
diff --git a/planetstack/core/views/slices.py b/planetstack/core/views/slices.py
index 5954d0c..e3ab139 100644
--- a/planetstack/core/views/slices.py
+++ b/planetstack/core/views/slices.py
@@ -1,66 +1,13 @@
-from django.http import Http404
-from rest_framework.views import APIView
-from rest_framework.response import Response
-from rest_framework import status
-
-from core.api.slices import add_slice, delete_slice, get_slices, update_slice
from core.serializers import SliceSerializer
-from util.request import parse_request
+from rest_framework import generics
+from core.models import Slice
+
+class SliceList(generics.ListCreateAPIView):
+ queryset = Slice.objects.all()
+ serializer_class = SliceSerializer
+
+class SliceDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = Slice.objects.all()
+ serializer_class = SliceSerializer
-class SliceListCreate(APIView):
- """
- List all slices or create a new slice.
- """
-
- def post(self, request, format = None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'slice' in data:
- slice = add_slice(data['auth'], data['slice'])
- serializer = SliceSerializer(slice)
- return Response(serializer.data, status=status.HTTP_201_CREATED)
- else:
- slices = get_slices(data['auth'])
- serializer = SliceSerializer(slices, many=True)
- return Response(serializer.data)
-
-
-class SliceRetrieveUpdateDestroy(APIView):
- """
- Retrieve, update or delete a slice
- """
-
- def post(self, request, pk, format=None):
- """Retrieve a slice"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- slices = get_slices(data['auth'], pk)
- if not slices:
- return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = SliceSerializer(slices[0])
- return Response(serializer.data)
-
- def put(self, request, pk, format=None):
- """update a slice"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'slice' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
-
- slice = update_slice(pk, data['slice'])
- serializer = SliceSerializer(slice)
- return Response(serializer.data)
-
- def delete(self, request, pk, format=None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_slice(data['auth'], pk)
- return Response(status=status.HTTP_204_NO_CONTENT)
-
-
-
diff --git a/planetstack/core/views/slivers.py b/planetstack/core/views/slivers.py
index 3741cce..bb310da 100644
--- a/planetstack/core/views/slivers.py
+++ b/planetstack/core/views/slivers.py
@@ -1,66 +1,13 @@
-from django.http import Http404
-from rest_framework.views import APIView
-from rest_framework.response import Response
-from rest_framework import status
-
-from core.api.slivers import add_sliver, delete_sliver, get_slivers, update_sliver
from core.serializers import SliverSerializer
-from util.request import parse_request
+from rest_framework import generics
+from core.models import Sliver
+
+class SliverList(generics.ListCreateAPIView):
+ queryset = Sliver.objects.all()
+ serializer_class = SliverSerializer
+
+class SliverDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = Sliver.objects.all()
+ serializer_class = SliverSerializer
-class SliverListCreate(APIView):
- """
- List all slivers or create a new sliver.
- """
-
- def post(self, request, format = None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'sliver' in data:
- sliver = add_sliver(data['auth'], data['sliver'])
- serializer = SliverSerializer(sliver)
- return Response(serializer.data, status=status.HTTP_201_CREATED)
- else:
- slivers = get_slivers(data['auth'])
- serializer = SliverSerializer(slivers, many=True)
- return Response(serializer.data)
-
-
-class SliverRetrieveUpdateDestroy(APIView):
- """
- Retrieve, update or delete a sliver
- """
-
- def post(self, request, pk, format=None):
- """Retrieve a sliver"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- slivers = get_slivers(data['auth'], pk)
- if not slivers:
- return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = SliverSerializer(slivers[0])
- return Response(serializer.data)
-
- def put(self, request, pk, format=None):
- """update a sliver"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'sliver' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
-
- sliver = update_sliver(pk, data['sliver'])
- serializer = SliverSerializer(sliver)
- return Response(serializer.data)
-
- def delete(self, request, pk, format=None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_sliver(data['auth'], pk)
- return Response(status=status.HTTP_204_NO_CONTENT)
-
-
-
diff --git a/planetstack/core/views/users.py b/planetstack/core/views/users.py
index 8b27928..06ac0f3 100644
--- a/planetstack/core/views/users.py
+++ b/planetstack/core/views/users.py
@@ -1,66 +1,11 @@
-from django.http import Http404
-from rest_framework.views import APIView
-from rest_framework.response import Response
-from rest_framework import status
-
-from core.api.users import add_user, delete_user, get_users, update_user
from core.serializers import UserSerializer
-from util.request import parse_request
+from rest_framework import generics
+from core.models import User
+class UserList(generics.ListCreateAPIView):
+ queryset = User.objects.all()
+ serializer_class = UserSerializer
-class UserListCreate(APIView):
- """
- List all users or create a new user.
- """
-
- def post(self, request, format = None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'user' in data:
- user = add_user(data['auth'], data['user'])
- serializer = UserSerializer(user)
- return Response(serializer.data, status=status.HTTP_201_CREATED)
- else:
- users = get_users(data['auth'])
- serializer = UserSerializer(users, many=True)
- return Response(serializer.data)
-
-
-class UserRetrieveUpdateDestroy(APIView):
- """
- Retrieve, update or delete a user
- """
-
- def post(self, request, pk, format=None):
- """Retrieve a user"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- users = get_users(data['auth'], {'id': pk})
- if not users:
- return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = UserSerializer(users[0])
- return Response(serializer.data)
-
- def put(self, request, pk, format=None):
- """update a user"""
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- elif 'user' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
-
- user = update_user(pk, data['user'])
- serializer = UserSerializer(user)
- return Response(serializer.data)
-
- def delete(self, request, pk, format=None):
- data = parse_request(request.DATA)
- if 'auth' not in data:
- return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_user(data['auth'], {'id': pk})
- return Response(status=status.HTTP_204_NO_CONTENT)
-
-
-
+class UserDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = User.objects.all()
+ serializer_class = UserSerializer