views.py
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)