blob: 4a548acdf571e52e9373418215b571b4a485678a [file] [log] [blame]
Tony Mack53310082013-04-09 09:26:12 -04001from django.http import Http404
2from rest_framework.views import APIView
3from rest_framework.response import Response
4from rest_framework import status
5
Tony Mackf1c12242013-04-09 16:08:43 -04006from plstackapi.core.api.images import add_image, delete_image, get_images
7from plstackapi.core.serializers import ImageSerializer
Tony Mack53310082013-04-09 09:26:12 -04008from plstackapi.util.request import parse_request
9
10
11class ImageListCreate(APIView):
12 """
13 List all images or create a new image.
14 """
15
16 def post(self, request, format = None):
17 data = parse_request(request.DATA)
18 if 'auth' not in data:
19 return Response(status=status.HTTP_400_BAD_REQUEST)
20 elif 'image' in data:
21 """Not Implemented"""
22 return Response(status=status.HTTP_404_NOT_FOUND)
23 else:
24 images = get_images(data['auth'])
25 serializer = ImageSerializer(images, many=True)
26 return Response(serializer.data)
27
28
29class ImageRetrieveUpdateDestroy(APIView):
30 """
31 Retrieve, update or delete an image
32 """
33
34 def post(self, request, pk, format=None):
35 """Retrieve an image """
36 data = parse_request(request.DATA)
37 if 'auth' not in data:
38 return Response(status=status.HTTP_400_BAD_REQUEST)
Tony Mack29c287f2013-04-11 21:07:16 -040039 images = get_images(data['auth'], pk)
Tony Mack53310082013-04-09 09:26:12 -040040 if not images:
41 return Response(status=status.HTTP_404_NOT_FOUND)
42 serializer = ImageSerializer(images[0])
43 return Response(serializer.data)
44
45 def put(self, request, pk, format=None):
46 """update image not implemnted"""
47 return Response(status=status.HTTP_404_NOT_FOUND)
48
49 def delete(self, request, pk, format=None):
50 """delete image not implemnted"""
51 return Response(status=status.HTTP_404_NOT_FOUND)
52
53
54
55