| from core.serializers import SiteSerializer |
| 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 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) |
| # |
| # |
| ## |