Showing
3 changed files
with
54 additions
and
17 deletions
| ... | @@ -15,8 +15,13 @@ | ... | @@ -15,8 +15,13 @@ |
| 15 | </form> | 15 | </form> |
| 16 | </div> | 16 | </div> |
| 17 | </center> | 17 | </center> |
| 18 | - | 18 | +<div> |
| 19 | -<button class="ui primary button" style="margin-left: 28%" type="submit" onclick="make_folder()"><i class="plus icon"></i>폴더 만들기</button> | 19 | + <button class="ui primary button" style="margin-left: 28%" onclick="make_folder()"><i class="plus icon"></i>폴더 만들기</button> |
| 20 | + <div style="display: none;" id="dir_make"> | ||
| 21 | + <input type="text" id="dir_name"> | ||
| 22 | + <button class="ui primary button" onclick="make_directory({{path}} )">만들기</button> | ||
| 23 | + </div> | ||
| 24 | +</div> | ||
| 20 | <br> | 25 | <br> |
| 21 | <center> | 26 | <center> |
| 22 | <table style="margin-top: 7px" class="ui celled striped collapsing table"> | 27 | <table style="margin-top: 7px" class="ui celled striped collapsing table"> |
| ... | @@ -40,10 +45,19 @@ | ... | @@ -40,10 +45,19 @@ |
| 40 | <i class="file outline icon"></i> {{file.name}} | 45 | <i class="file outline icon"></i> {{file.name}} |
| 41 | {% endif %} | 46 | {% endif %} |
| 42 | </td> | 47 | </td> |
| 43 | - <td class="center aligned collapsing"><i onclick="make_folder()" style="cursor: pointer;" class="copy outline icon"></i></td> | 48 | + <td class="center aligned collapsing"> |
| 49 | + {% with new_path=path|add:file.name|add:'/' %} | ||
| 50 | + <a href="#"><i class="copy outline icon"></i></a> | ||
| 51 | + {% endwith %} | ||
| 52 | + | ||
| 53 | + </td> | ||
| 44 | <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> |
| 45 | - <td class="center aligned collapsing"><i onclick="make_folder()" style="cursor: pointer;" class="trash alternate outline icon"></i></td> | 55 | + <td class="center aligned collapsing"> |
| 46 | - <td class="center aligned collapsing"><i onclick="make_folder()" style="cursor: pointer;" class="download icon"></i></td> | 56 | + {% with new_path=path|add:file.name|add:'/' %} |
| 57 | + <a href="{% url 'file_delete' path=new_path %}"><i class="trash alternate outline icon"></i></a> | ||
| 58 | + {% endwith %} | ||
| 59 | + </td> | ||
| 60 | + <td class="center aligned collapsing"><i style="cursor: pointer;" class="download icon"></i></td> | ||
| 47 | </tr> | 61 | </tr> |
| 48 | {% endfor %} | 62 | {% endfor %} |
| 49 | </tbody> | 63 | </tbody> |
| ... | @@ -62,7 +76,14 @@ | ... | @@ -62,7 +76,14 @@ |
| 62 | } | 76 | } |
| 63 | } | 77 | } |
| 64 | function make_folder(){ | 78 | function make_folder(){ |
| 65 | - location.href = "/make_folder/"; | 79 | + document.getElementById("dir_make").style.display = "inline-block"; |
| 80 | + } | ||
| 81 | + | ||
| 82 | + function make_directory(dir_path){ | ||
| 83 | + dir = document.getElementById("dir_name").value; | ||
| 84 | + var dir_path = "{{ path }}"; | ||
| 85 | + new_path = dir_path + dir + '/'; | ||
| 86 | + location.href = "{% url 'make_folder' path='' %}" + new_path; | ||
| 66 | } | 87 | } |
| 67 | 88 | ||
| 68 | function copy(){ | 89 | function copy(){ |
| ... | @@ -71,7 +92,7 @@ | ... | @@ -71,7 +92,7 @@ |
| 71 | function move(){ | 92 | function move(){ |
| 72 | 93 | ||
| 73 | } | 94 | } |
| 74 | - function delete(){ | 95 | + function delete_file(){ |
| 75 | 96 | ||
| 76 | } | 97 | } |
| 77 | function download(){ | 98 | function download(){ | ... | ... |
| ... | @@ -12,6 +12,7 @@ urlpatterns = [ | ... | @@ -12,6 +12,7 @@ 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'^make_folder/', views.make_folder, name='make_folder'), | 15 | + url(r'^download/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.file_download, name='file_download'), |
| 16 | - | 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'), | ||
| 17 | ] | 18 | ] |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -16,11 +16,11 @@ def home(request): | ... | @@ -16,11 +16,11 @@ def home(request): |
| 16 | 16 | ||
| 17 | @login_required | 17 | @login_required |
| 18 | def file_list(request, path): | 18 | def file_list(request, path): |
| 19 | - cookies = {'sessionid' : request.session.session_key} | 19 | + cookies = {'sessionid' : request.session.session_key} |
| 20 | - files = requests.get('http://localhost:8000/restapi/list/'+path, cookies=cookies) | 20 | + files = requests.get('http://localhost:8000/restapi/list/'+path, cookies=cookies) |
| 21 | - ret = files.json() | 21 | + ret = files.json() |
| 22 | - ret['path'] = path | 22 | + ret['path'] = path |
| 23 | - return render(request, 'website/file_list.html', ret) | 23 | + return render(request, 'website/file_list.html', ret) |
| 24 | 24 | ||
| 25 | @login_required | 25 | @login_required |
| 26 | def file_upload(request, path): | 26 | def file_upload(request, path): |
| ... | @@ -28,11 +28,26 @@ def file_upload(request, path): | ... | @@ -28,11 +28,26 @@ def file_upload(request, path): |
| 28 | cookies = {'sessionid' : request.session.session_key} | 28 | cookies = {'sessionid' : request.session.session_key} |
| 29 | cookies['csrftoken'] = csrf.get_token(request) | 29 | cookies['csrftoken'] = csrf.get_token(request) |
| 30 | headers = {'X-CSRFToken': cookies['csrftoken']} | 30 | headers = {'X-CSRFToken': cookies['csrftoken']} |
| 31 | - print(cookies) | 31 | + requests.post('http://localhost:8000/restapi/list/'+path, files={'file': file}, headers=headers, cookies=cookies) |
| 32 | - requests.post('http://localhost:8000/restapi/list/', files={'file': file}, headers=headers, cookies=cookies) | ||
| 33 | return redirect('file_list', path=path) | 32 | return redirect('file_list', path=path) |
| 34 | 33 | ||
| 35 | def make_folder(request, path): | 34 | def make_folder(request, path): |
| 35 | + dir_name = request.POST.get('dir_name') | ||
| 36 | cookies = {'sessionid' : request.session.session_key} | 36 | cookies = {'sessionid' : request.session.session_key} |
| 37 | - files = requests.put('http://localhost:8000/restapi/list/'+path, cookies=cookies) | 37 | + cookies['csrftoken'] = csrf.get_token(request) |
| 38 | + headers = {'X-CSRFToken': cookies['csrftoken']} | ||
| 39 | + print(path) | ||
| 40 | + files = requests.put('http://localhost:8000/restapi/list/'+path, headers=headers, cookies=cookies) | ||
| 38 | return redirect('file_list', path=path) | 41 | return redirect('file_list', path=path) |
| 42 | + | ||
| 43 | +def file_delete(request, path): | ||
| 44 | + cookies = {'sessionid' : request.session.session_key} | ||
| 45 | + cookies['csrftoken'] = csrf.get_token(request) | ||
| 46 | + headers = {'X-CSRFToken': cookies['csrftoken']} | ||
| 47 | + requests.delete('http://localhost:8000/restapi/file/'+path, headers=headers, cookies=cookies) | ||
| 48 | + return redirect('file_list', path="/".join(path.split("/")[:-2])) | ||
| 49 | + | ||
| 50 | +def file_download(request, path): | ||
| 51 | + cookies = {'sessionid' : request.session.session_key} | ||
| 52 | + requests.get('http://localhost:8000/restapi/file/'+path, cookies=cookies) | ||
| 53 | + return redirect('file_list', path="/".join(path.split("/")[:-2])) | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment