신은섭(Shin Eun Seop)

add file delete restapi, close #11

1 import os 1 import os
2 -import aws_conf 2 +from dcloud import aws_conf
3 3
4 # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 4 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
5 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 5 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......
...@@ -27,4 +27,5 @@ def list_path(bucket, user, path): ...@@ -27,4 +27,5 @@ def list_path(bucket, user, path):
27 27
28 return {'files':files} 28 return {'files':files}
29 29
30 -# print(list_path(BUCKET, 'test1', ''))
...\ No newline at end of file ...\ No newline at end of file
30 +def delete_path(bucket, user, path):
31 + return S3.delete_object(Bucket=bucket, Key='{}/{}'.format(user, path))
......
...@@ -4,8 +4,10 @@ from rest_framework.urlpatterns import format_suffix_patterns ...@@ -4,8 +4,10 @@ from rest_framework.urlpatterns import format_suffix_patterns
4 from restful import views 4 from restful import views
5 5
6 urlpatterns = [ 6 urlpatterns = [
7 - url(r'^files/(?P<path>([a-zA-z0-9가-힣._-]*/)*)$', views.FileList.as_view(), name='file-list'), 7 + url(r'^list/(?P<path>([a-zA-z0-9가-힣._-]*/)*)$', views.FileList.as_view(), name='file-list'),
8 - url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view()), 8 + # url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view()),
9 +
10 + url(r'^file/(?P<path>([a-zA-z0-9가-힣._-]*/*)*)$', views.FileDetail.as_view(), name='file-detail')
9 ] 11 ]
10 12
11 urlpatterns = format_suffix_patterns(urlpatterns) 13 urlpatterns = format_suffix_patterns(urlpatterns)
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -34,27 +34,30 @@ class FileDetail(APIView): ...@@ -34,27 +34,30 @@ class FileDetail(APIView):
34 """ 34 """
35 Retrieve, update or delete a file instance. 35 Retrieve, update or delete a file instance.
36 """ 36 """
37 - def get_object(self, pk): 37 + # def get_object(self, pk):
38 - try: 38 + # try:
39 - return File.objects.get(pk=pk) 39 + # return File.objects.get(pk=pk)
40 - except File.DoesNotExist: 40 + # except File.DoesNotExist:
41 - raise Http404 41 + # raise Http404
42 - 42 +
43 - def get(self, request, pk, format=None): 43 + def get(self, request, path="/", format=None):
44 - file = self.get_object(pk) 44 + # file = self.get_object(pk)
45 - serializer = FileSerializer(file) 45 + # serializer = FileSerializer(file)
46 - return Response(serializer.data, status=status.HTTP_200_OK) 46 + # return Response(serializer.data, status=status.HTTP_200_OK)
47 - 47 + # TODO
48 - def put(self, request, pk, format=None): 48 + return
49 - file = self.get_object(pk) 49 +
50 - serializer = FileSerializer(file, data=request.data) 50 + def put(self, request, path="/", format=None):
51 - if serializer.is_valid(): 51 + # file = self.get_object(pk)
52 - serializer.save() 52 + # serializer = FileSerializer(file, data=request.data)
53 - return Response(serializer.data, status=status.HTTP_204_NO_CONTENT) 53 + # if serializer.is_valid():
54 - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) 54 + # serializer.save()
55 - 55 + # return Response(serializer.data, status=status.HTTP_204_NO_CONTENT)
56 - def delete(self, request, pk, format=None): 56 + # return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
57 - file = self.get_object(pk) 57 + # TODO
58 - file.delete() 58 + return
59 - return Response(status=status.HTTP_204_NO_CONTENT) 59 +
60 + def delete(self, request, path="/", format=None):
61 + result = s3_interface.delete_path(s3_interface.BUCKET, 'test1', path)
62 + return Response(result)
60 63
......