신은섭(Shin Eun Seop)

add file listing without user name

add file listing at /restapi/file/*
need to modify `user` parameter in restful.views.FileList.get

kairos03/2018-1-d.cloud#10
...@@ -105,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -105,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [
105 # Internationalization 105 # Internationalization
106 # https://docs.djangoproject.com/en/2.0/topics/i18n/ 106 # https://docs.djangoproject.com/en/2.0/topics/i18n/
107 107
108 -LANGUAGE_CODE = 'en-us' 108 +LANGUAGE_CODE = 'ko_kr'
109 109
110 TIME_ZONE = 'UTC' 110 TIME_ZONE = 'UTC'
111 111
......
...@@ -18,5 +18,5 @@ from django.conf.urls import url, include ...@@ -18,5 +18,5 @@ from django.conf.urls import url, include
18 18
19 urlpatterns = [ 19 urlpatterns = [
20 url('admin/', admin.site.urls), 20 url('admin/', admin.site.urls),
21 - url(r'^', include('restful.urls')), 21 + url(r'^restapi/', include('restful.urls')),
22 ] 22 ]
......
1 +import boto3
2 +import json
3 +
4 +S3 = boto3.client('s3')
5 +BUCKET = '2018-dcloud'
6 +
7 +
8 +def list_path(bucket, user, path):
9 +
10 + files = []
11 + # get list
12 + objects = S3.list_objects(Bucket=bucket, Prefix='{}/{}'.format(user, path), Delimiter='/')
13 +
14 + # get sub directorys
15 + common_prefixes = objects.get('CommonPrefixes')
16 + if common_prefixes:
17 + for obj in common_prefixes:
18 + files.append({'type':'diretory', 'name':obj.get('Prefix').split('/')[-2]})
19 +
20 + # get files
21 + contents = objects.get('Contents')
22 + if contents:
23 + for obj in contents:
24 + file = obj.get('Key').split('/')[-1]
25 + if file != '':
26 + files.append({'type':'file', 'name':file})
27 +
28 + return {'files':files}
29 +
30 +# print(list_path(BUCKET, 'test1', ''))
...\ No newline at end of file ...\ No newline at end of file
1 from django.conf.urls import url 1 from django.conf.urls import url
2 +from django.shortcuts import redirect
2 from rest_framework.urlpatterns import format_suffix_patterns 3 from rest_framework.urlpatterns import format_suffix_patterns
3 from restful import views 4 from restful import views
4 5
5 urlpatterns = [ 6 urlpatterns = [
6 - url(r'^files/$', views.FileList.as_view(), name='file-list'), 7 + url(r'^files/(?P<path>(\/*[a-zA-z0-9가-힣._-]*/)*)$', views.FileList.as_view(), name='file-list'),
7 - url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view(), name='file-detail'), 8 + url(r'^files/(?P<pk>[0-9]+)/$', views.FileDetail.as_view()),
8 ] 9 ]
9 10
10 urlpatterns = format_suffix_patterns(urlpatterns) 11 urlpatterns = format_suffix_patterns(urlpatterns)
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -4,6 +4,7 @@ from django.http import Http404 ...@@ -4,6 +4,7 @@ from django.http import Http404
4 from rest_framework.views import APIView 4 from rest_framework.views import APIView
5 from rest_framework.response import Response 5 from rest_framework.response import Response
6 from rest_framework import status 6 from rest_framework import status
7 +from restful import s3_interface
7 8
8 9
9 # Create your views here. 10 # Create your views here.
...@@ -12,10 +13,14 @@ class FileList(APIView): ...@@ -12,10 +13,14 @@ class FileList(APIView):
12 List all file, or create a new snippet. 13 List all file, or create a new snippet.
13 """ 14 """
14 15
15 - def get(self, request, format=None): 16 + def get(self, request, path='/', format=None):
16 - file = File.objects.all() 17 + # file = File.objects.all()
17 - serializer = FileSerializer(file, many=True) 18 + # serializer = FileSerializer(file, many=True)
18 - return Response(serializer.data) 19 + # print(serializer.data)
20 + # return Response(serializer.data)
21 + data = s3_interface.list_path(s3_interface.BUCKET, 'test1', path)
22 + return Response(data)
23 +
19 24
20 def post(self, request, format=None): 25 def post(self, request, format=None):
21 serializer = FileSerializer(data=request.data) 26 serializer = FileSerializer(data=request.data)
......
1 +from django.conf.urls import url
2 +from website import views, auth_views
3 +
4 +urlpatterns = [
5 + # blog
6 + url(r'^$', views.post_list, name='post_list'),
7 + url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
8 + url(r'^post/new/$', views.post_new, name='post_new'),
9 + url(r'^post/(?P<pk>\d+)/edit/$', views.post_edit, name='post_edit'),
10 + url(r'^drafts/$', views.post_draft_list, name='post_draft_list'),
11 + url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish, name='post_publish'),
12 +
13 + url(r'^files/$', views.file_list, name='file_list'),
14 + url(r'^signup/$', auth_views.signup, name='signup'),
15 +]
...\ No newline at end of file ...\ No newline at end of file