신은섭(Shin Eun Seop)

add delete file

...@@ -31,24 +31,29 @@ def list_path(bucket, user, path): ...@@ -31,24 +31,29 @@ def list_path(bucket, user, path):
31 31
32 return {'files':files} 32 return {'files':files}
33 33
34 +
34 def upload_file(bucket, user, local_path, key): 35 def upload_file(bucket, user, local_path, key):
35 return S3.upload_file(local_path, bucket, user+"/"+key) 36 return S3.upload_file(local_path, bucket, user+"/"+key)
36 37
38 +
37 def download_file(bucket, user, local_path, key): 39 def download_file(bucket, user, local_path, key):
38 return S3.download_file(bucket, user+"/"+key, local_path) 40 return S3.download_file(bucket, user+"/"+key, local_path)
39 41
42 +
40 def delete_path(bucket, user, path): 43 def delete_path(bucket, user, path):
41 return S3.delete_object(Bucket=bucket, Key=user+"/"+path) 44 return S3.delete_object(Bucket=bucket, Key=user+"/"+path)
42 45
46 +
43 def make_directory(bucket, user, path): 47 def make_directory(bucket, user, path):
44 return S3.put_object(Bucket=BUCKET, Key=user+"/"+path) 48 return S3.put_object(Bucket=BUCKET, Key=user+"/"+path)
45 49
46 -# 50 +
47 def move_file(bucket, user, old_path, new_path): 51 def move_file(bucket, user, old_path, new_path):
48 S3.copy_object(Bucket=bucket, CopySource=bucket+"/"+user+"/"+old_path, Key=user+"/"+new_path) 52 S3.copy_object(Bucket=bucket, CopySource=bucket+"/"+user+"/"+old_path, Key=user+"/"+new_path)
49 S3.delete_object(Bucket=bucket, Key=user+"/"+old_path) 53 S3.delete_object(Bucket=bucket, Key=user+"/"+old_path)
50 return 54 return
51 55
56 +
52 def copy_file(bucket, user, old_path, new_path): 57 def copy_file(bucket, user, old_path, new_path):
53 S3.copy_object(Bucket=bucket, CopySource=bucket+"/"+user+"/"+old_path, Key=user+"/"+new_path) 58 S3.copy_object(Bucket=bucket, CopySource=bucket+"/"+user+"/"+old_path, Key=user+"/"+new_path)
54 return 59 return
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
53 </td> 53 </td>
54 <td class="center aligned collapsing"><i onclick="make_folder()" style="cursor: pointer;" class="sign out alternate icon"></i></td> 54 <td class="center aligned collapsing"><i onclick="make_folder()" style="cursor: pointer;" class="sign out alternate icon"></i></td>
55 <td class="center aligned collapsing"> 55 <td class="center aligned collapsing">
56 - {% with new_path=path|add:file.name|add:'/' %} 56 + {% with new_path=path|add:file.name %}
57 <a href="{% url 'file_delete' path=new_path %}"><i class="trash alternate outline icon"></i></a> 57 <a href="{% url 'file_delete' path=new_path %}"><i class="trash alternate outline icon"></i></a>
58 {% endwith %} 58 {% endwith %}
59 </td> 59 </td>
......
...@@ -12,7 +12,9 @@ urlpatterns = [ ...@@ -12,7 +12,9 @@ urlpatterns = [
12 url(r'^$', views.home, name='home'), 12 url(r'^$', views.home, name='home'),
13 url(r'^list/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.file_list, name='file_list'), 13 url(r'^list/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.file_list, name='file_list'),
14 url(r'^upload/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.file_upload, name='file_upload'), 14 url(r'^upload/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.file_upload, name='file_upload'),
15 - url(r'^download/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.file_download, name='file_download'),
16 - url(r'^delete/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.file_delete, name='file_delete'),
17 url(r'^make_folder/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.make_folder, name='make_folder'), 15 url(r'^make_folder/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.make_folder, name='make_folder'),
16 +
17 + url(r'^delete/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)$', views.file_delete, name='file_delete'),
18 + url(r'^download/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)$', views.file_download, name='file_download'),
19 +
18 ] 20 ]
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -31,6 +31,7 @@ def file_upload(request, path): ...@@ -31,6 +31,7 @@ def file_upload(request, path):
31 requests.post('http://localhost:8000/restapi/list/'+path, files={'file': file}, headers=headers, cookies=cookies) 31 requests.post('http://localhost:8000/restapi/list/'+path, files={'file': file}, headers=headers, cookies=cookies)
32 return redirect('file_list', path=path) 32 return redirect('file_list', path=path)
33 33
34 +@login_required
34 def make_folder(request, path): 35 def make_folder(request, path):
35 dir_name = request.POST.get('dir_name') 36 dir_name = request.POST.get('dir_name')
36 cookies = {'sessionid' : request.session.session_key} 37 cookies = {'sessionid' : request.session.session_key}
...@@ -39,6 +40,7 @@ def make_folder(request, path): ...@@ -39,6 +40,7 @@ def make_folder(request, path):
39 files = requests.put('http://localhost:8000/restapi/list/'+path, headers=headers, cookies=cookies) 40 files = requests.put('http://localhost:8000/restapi/list/'+path, headers=headers, cookies=cookies)
40 return redirect('file_list', path=path) 41 return redirect('file_list', path=path)
41 42
43 +@login_required
42 def file_delete(request, path): 44 def file_delete(request, path):
43 cookies = {'sessionid' : request.session.session_key} 45 cookies = {'sessionid' : request.session.session_key}
44 cookies['csrftoken'] = csrf.get_token(request) 46 cookies['csrftoken'] = csrf.get_token(request)
...@@ -46,6 +48,7 @@ def file_delete(request, path): ...@@ -46,6 +48,7 @@ def file_delete(request, path):
46 requests.delete('http://localhost:8000/restapi/file/'+path, headers=headers, cookies=cookies) 48 requests.delete('http://localhost:8000/restapi/file/'+path, headers=headers, cookies=cookies)
47 return redirect('file_list', path="/".join(path.split("/")[:-2])) 49 return redirect('file_list', path="/".join(path.split("/")[:-2]))
48 50
51 +@login_required
49 def file_download(request, path): 52 def file_download(request, path):
50 cookies = {'sessionid' : request.session.session_key} 53 cookies = {'sessionid' : request.session.session_key}
51 requests.get('http://localhost:8000/restapi/file/'+path, cookies=cookies) 54 requests.get('http://localhost:8000/restapi/file/'+path, cookies=cookies)
......