Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 1 | from core.serializers import SiteSerializer |
Siobhan Tully | 5d7dc8d | 2013-07-02 13:17:33 -0400 | [diff] [blame] | 2 | from rest_framework import generics |
| 3 | from core.models import Site |
| 4 | |
| 5 | class SiteList(generics.ListCreateAPIView): |
| 6 | queryset = Site.objects.all() |
| 7 | serializer_class = SiteSerializer |
| 8 | |
| 9 | class SiteDetail(generics.RetrieveUpdateDestroyAPIView): |
| 10 | queryset = Site.objects.all() |
| 11 | serializer_class = SiteSerializer |
Tony Mack | 7ab0db7 | 2013-04-08 23:19:32 -0400 | [diff] [blame] | 12 | |
| 13 | |
Tony Mack | 7ab0db7 | 2013-04-08 23:19:32 -0400 | [diff] [blame] | 14 | |
Siobhan Tully | 5d7dc8d | 2013-07-02 13:17:33 -0400 | [diff] [blame] | 15 | #class SiteListCreate(APIView): |
| 16 | ###### """ |
| 17 | ## List all sites or create a new site. |
| 18 | # """ |
| 19 | # |
| 20 | # def post(self, request, format = None): |
| 21 | # data = parse_request(request.DATA) |
| 22 | # if 'auth' not in data: |
| 23 | # return Response(status=status.HTTP_400_BAD_REQUEST) |
| 24 | # elif 'site' in data: |
| 25 | # site = add_site(data['auth'], data['site']) |
| 26 | # serializer = SiteSerializer(site) |
| 27 | # return Response(serializer.data, status=status.HTTP_201_CREATED) |
| 28 | # else: |
| 29 | # sites = get_sites(data['auth']) |
| 30 | # serializer = SiteSerializer(sites, many=True) |
| 31 | # return Response(serializer.data) |
Tony Mack | 7ab0db7 | 2013-04-08 23:19:32 -0400 | [diff] [blame] | 32 | |
| 33 | |
Siobhan Tully | 5d7dc8d | 2013-07-02 13:17:33 -0400 | [diff] [blame] | 34 | #class SiteRetrieveUpdateDestroy(APIView): |
| 35 | # """ |
| 36 | # Retrieve, update or delete a site |
| 37 | # """ |
| 38 | # |
| 39 | # def post(self, request, pk, format=None): |
| 40 | # """Retrieve a site""" |
| 41 | # data = parse_request(request.DATA) |
| 42 | # if 'auth' not in data: |
| 43 | # return Response(status=status.HTTP_400_BAD_REQUEST) |
| 44 | # sites = get_sites(data['auth'], {'id': pk}) |
| 45 | # if not sites: |
| 46 | # return Response(status=status.HTTP_404_NOT_FOUND) |
| 47 | # serializer = SiteSerializer(sites[0]) |
| 48 | # return Response(serializer.data) |
| 49 | # |
| 50 | # def put(self, request, pk, format=None): |
| 51 | # """update a site""" |
| 52 | # data = parse_request(request.DATA) |
| 53 | # if 'auth' not in data: |
| 54 | # return Response(status=status.HTTP_400_BAD_REQUEST) |
| 55 | # elif 'site' not in data: |
| 56 | # return Response(status=status.HTTP_400_BAD_REQUEST) |
| 57 | # |
| 58 | # site = update_site(pk, data['site']) |
| 59 | # serializer = SiteSerializer(site) |
| 60 | # return Response(serializer.data) |
| 61 | # |
| 62 | # def delete(self, request, pk, format=None): |
| 63 | # data = parse_request(request.DATA) |
| 64 | # if 'auth' not in data: |
| 65 | # return Response(status=status.HTTP_400_BAD_REQUEST) |
| 66 | # delete_site(data['auth'], {'id': pk}) |
| 67 | # return Response(status=status.HTTP_204_NO_CONTENT) |
| 68 | # |
| 69 | # |
| 70 | ## |