Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 1 | from django.http import Http404 |
| 2 | from rest_framework.views import APIView |
| 3 | from rest_framework.response import Response |
| 4 | from rest_framework import status |
| 5 | |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 6 | from core.api.nodes import add_node, delete_node, get_nodes, update_node |
| 7 | from core.serializers import NodeSerializer |
| 8 | from util.request import parse_request |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 9 | |
| 10 | |
| 11 | class NodeListCreate(APIView): |
| 12 | """ |
| 13 | List all nodes or create a new node. |
| 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 'node' in data: |
| 21 | """Not Implemented""" |
| 22 | return Response(status=status.HTTP_404_NOT_FOUND) |
| 23 | else: |
| 24 | nodes = get_nodes(data['auth']) |
| 25 | serializer = NodeSerializer(nodes, many=True) |
| 26 | return Response(serializer.data) |
| 27 | |
| 28 | |
| 29 | class NodeRetrieveUpdateDestroy(APIView): |
| 30 | """ |
| 31 | Retrieve, update or delete an node |
| 32 | """ |
| 33 | |
| 34 | def post(self, request, pk, format=None): |
| 35 | """Retrieve an node """ |
| 36 | data = parse_request(request.DATA) |
| 37 | if 'auth' not in data: |
| 38 | return Response(status=status.HTTP_400_BAD_REQUEST) |
| 39 | nodes = get_nodes(data['auth'], pk) |
| 40 | if not nodes: |
| 41 | return Response(status=status.HTTP_404_NOT_FOUND) |
| 42 | serializer = NodeSerializer(nodes[0]) |
| 43 | return Response(serializer.data) |
| 44 | |
| 45 | def put(self, request, pk, format=None): |
| 46 | """update node not implemnted""" |
| 47 | return Response(status=status.HTTP_404_NOT_FOUND) |
| 48 | |
| 49 | def delete(self, request, pk, format=None): |
| 50 | """delete node not implemnted""" |
| 51 | return Response(status=status.HTTP_404_NOT_FOUND) |
| 52 | |
| 53 | |
| 54 | |
| 55 | |