Kangsubeen

make folder

......@@ -15,8 +15,13 @@
</form>
</div>
</center>
<button class="ui primary button" style="margin-left: 28%" type="submit" onclick="make_folder()"><i class="plus icon"></i>폴더 만들기</button>
<div>
<button class="ui primary button" style="margin-left: 28%" onclick="make_folder()"><i class="plus icon"></i>폴더 만들기</button>
<div style="display: none;" id="dir_make">
<input type="text" id="dir_name">
<button class="ui primary button" onclick="make_directory({{path}} )">만들기</button>
</div>
</div>
<br>
<center>
<table style="margin-top: 7px" class="ui celled striped collapsing table">
......@@ -40,10 +45,19 @@
<i class="file outline icon"></i> {{file.name}}
{% endif %}
</td>
<td class="center aligned collapsing"><i onclick="make_folder()" style="cursor: pointer;" class="copy outline icon"></i></td>
<td class="center aligned collapsing">
{% with new_path=path|add:file.name|add:'/' %}
<a href="#"><i class="copy outline icon"></i></a>
{% endwith %}
</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"><i onclick="make_folder()" style="cursor: pointer;" class="trash alternate outline icon"></i></td>
<td class="center aligned collapsing"><i onclick="make_folder()" style="cursor: pointer;" class="download icon"></i></td>
<td class="center aligned collapsing">
{% with new_path=path|add:file.name|add:'/' %}
<a href="{% url 'file_delete' path=new_path %}"><i class="trash alternate outline icon"></i></a>
{% endwith %}
</td>
<td class="center aligned collapsing"><i style="cursor: pointer;" class="download icon"></i></td>
</tr>
{% endfor %}
</tbody>
......@@ -62,7 +76,14 @@
}
}
function make_folder(){
location.href = "/make_folder/";
document.getElementById("dir_make").style.display = "inline-block";
}
function make_directory(dir_path){
dir = document.getElementById("dir_name").value;
var dir_path = "{{ path }}";
new_path = dir_path + dir + '/';
location.href = "{% url 'make_folder' path='' %}" + new_path;
}
function copy(){
......@@ -71,7 +92,7 @@
function move(){
}
function delete(){
function delete_file(){
}
function download(){
......
......@@ -12,6 +12,7 @@ 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'^make_folder/', views.make_folder, name='make_folder'),
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'),
]
\ No newline at end of file
......
......@@ -16,11 +16,11 @@ def home(request):
@login_required
def file_list(request, path):
cookies = {'sessionid' : request.session.session_key}
files = requests.get('http://localhost:8000/restapi/list/'+path, cookies=cookies)
ret = files.json()
ret['path'] = path
return render(request, 'website/file_list.html', ret)
cookies = {'sessionid' : request.session.session_key}
files = requests.get('http://localhost:8000/restapi/list/'+path, cookies=cookies)
ret = files.json()
ret['path'] = path
return render(request, 'website/file_list.html', ret)
@login_required
def file_upload(request, path):
......@@ -28,11 +28,26 @@ def file_upload(request, path):
cookies = {'sessionid' : request.session.session_key}
cookies['csrftoken'] = csrf.get_token(request)
headers = {'X-CSRFToken': cookies['csrftoken']}
print(cookies)
requests.post('http://localhost:8000/restapi/list/', files={'file': file}, headers=headers, cookies=cookies)
requests.post('http://localhost:8000/restapi/list/'+path, files={'file': file}, headers=headers, cookies=cookies)
return redirect('file_list', path=path)
def make_folder(request, path):
dir_name = request.POST.get('dir_name')
cookies = {'sessionid' : request.session.session_key}
files = requests.put('http://localhost:8000/restapi/list/'+path, cookies=cookies)
cookies['csrftoken'] = csrf.get_token(request)
headers = {'X-CSRFToken': cookies['csrftoken']}
print(path)
files = requests.put('http://localhost:8000/restapi/list/'+path, headers=headers, cookies=cookies)
return redirect('file_list', path=path)
def file_delete(request, path):
cookies = {'sessionid' : request.session.session_key}
cookies['csrftoken'] = csrf.get_token(request)
headers = {'X-CSRFToken': cookies['csrftoken']}
requests.delete('http://localhost:8000/restapi/file/'+path, headers=headers, cookies=cookies)
return redirect('file_list', path="/".join(path.split("/")[:-2]))
def file_download(request, path):
cookies = {'sessionid' : request.session.session_key}
requests.get('http://localhost:8000/restapi/file/'+path, cookies=cookies)
return redirect('file_list', path="/".join(path.split("/")[:-2]))
\ No newline at end of file
......