views.py 1.7 KB
from django.http import Http404
from django.contrib.auth.decorators import login_required
from rest_framework.views import APIView  
from rest_framework.response import Response  
from rest_framework import status
from restful import s3_interface

from restful.models import File  
from restful.serializers import FileSerializer  

class FileList(APIView):
    """
    List all file, or create a new snippet.
    """

    def get(self, request, path="/", format=None):
        data = s3_interface.list_path(s3_interface.BUCKET, 'test1', path)
        return Response(data)


    def post(self, request, path="/", format=None):
        # TODO file upload
        return Response({})


class FileDetail(APIView):
    """
    Retrieve, update or delete a file instance.
    """
    # def get_object(self, pk):
    #     try:
    #         return File.objects.get(pk=pk)
    #     except File.DoesNotExist:
    #         raise Http404

    def get(self, request, path="/", format=None):
        # file = self.get_object(pk)
        # serializer = FileSerializer(file)
        # return Response(serializer.data, status=status.HTTP_200_OK)
        # TODO
        return

    def put(self, request, path="/", format=None):
        # file = self.get_object(pk)
        # serializer = FileSerializer(file, data=request.data)
        # if serializer.is_valid():
        #     serializer.save()
        #     return Response(serializer.data, status=status.HTTP_204_NO_CONTENT)
        # return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
        # TODO
        return

    def delete(self, request, path="/", format=None):
        result = s3_interface.delete_path(s3_interface.BUCKET, 'test1', path)
        return Response(result)