신은섭(Shin Eun Seop)

add file delete restapi, close #11

import os
import aws_conf
from dcloud import aws_conf
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......
......@@ -27,4 +27,5 @@ def list_path(bucket, user, path):
return {'files':files}
# print(list_path(BUCKET, 'test1', ''))
\ No newline at end of file
def delete_path(bucket, user, path):
return S3.delete_object(Bucket=bucket, Key='{}/{}'.format(user, path))
......
......@@ -4,8 +4,10 @@ from rest_framework.urlpatterns import format_suffix_patterns
from restful import views
urlpatterns = [
url(r'^files/(?P<path>([a-zA-z0-9가-힣._-]*/)*)$', views.FileList.as_view(), name='file-list'),
url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view()),
url(r'^list/(?P<path>([a-zA-z0-9가-힣._-]*/)*)$', views.FileList.as_view(), name='file-list'),
# url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view()),
url(r'^file/(?P<path>([a-zA-z0-9가-힣._-]*/*)*)$', views.FileDetail.as_view(), name='file-detail')
]
urlpatterns = format_suffix_patterns(urlpatterns)
\ No newline at end of file
......
......@@ -34,27 +34,30 @@ 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, pk, format=None):
file = self.get_object(pk)
serializer = FileSerializer(file)
return Response(serializer.data, status=status.HTTP_200_OK)
def put(self, request, pk, 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)
def delete(self, request, pk, format=None):
file = self.get_object(pk)
file.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
# 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)
......