신은섭(Shin Eun Seop)

add delete file

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