Showing
4 changed files
with
105 additions
and
36 deletions
| ... | @@ -78,6 +78,10 @@ class FileCopyMove(APIView): | ... | @@ -78,6 +78,10 @@ class FileCopyMove(APIView): |
| 78 | """ | 78 | """ |
| 79 | Download or delete a file instance. | 79 | Download or delete a file instance. |
| 80 | """ | 80 | """ |
| 81 | + | ||
| 82 | + authentication_classes = (SessionAuthentication, BasicAuthentication) | ||
| 83 | + permission_classes = (IsAuthenticated,) | ||
| 84 | + | ||
| 81 | #TODO is folder move, copy well? | 85 | #TODO is folder move, copy well? |
| 82 | # move | 86 | # move |
| 83 | def post(self, request, old_path, new_path, format=None): | 87 | def post(self, request, old_path, new_path, format=None): | ... | ... |
| ... | @@ -16,52 +16,82 @@ | ... | @@ -16,52 +16,82 @@ |
| 16 | </div> | 16 | </div> |
| 17 | </center> | 17 | </center> |
| 18 | <div> | 18 | <div> |
| 19 | - <button class="ui primary button" style="margin-left: 28%" onclick="make_folder()"><i class="plus icon"></i>폴더 만들기</button> | 19 | + <button class="ui primary button" style="margin-left: 24%" onclick="make_folder()"><i class="plus icon"></i>폴더 만들기</button> |
| 20 | <div style="display: none;" id="dir_make"> | 20 | <div style="display: none;" id="dir_make"> |
| 21 | <input type="text" id="dir_name"> | 21 | <input type="text" id="dir_name"> |
| 22 | - <button class="ui primary button" onclick="make_directory({{path}} )">만들기</button> | 22 | + <button class="ui primary button" onclick="make_directory()">만들기</button> |
| 23 | </div> | 23 | </div> |
| 24 | + | ||
| 24 | </div> | 25 | </div> |
| 25 | <br> | 26 | <br> |
| 26 | <center> | 27 | <center> |
| 27 | <table style="margin-top: 7px" class="ui celled striped collapsing table"> | 28 | <table style="margin-top: 7px" class="ui celled striped collapsing table"> |
| 28 | <thead> | 29 | <thead> |
| 29 | 30 | ||
| 30 | - <tr><th class="twelve wide">/{{ path }}</th> | 31 | + <tr><th class="nine wide">/{{ path }}</th> |
| 31 | - <th>복사</th> | 32 | + <th class="center aligned">경로</th> |
| 32 | - <th >이동</th> | 33 | + <th class="center aligned">복사</th> |
| 33 | - <th>삭제</th> | 34 | + <th class="center aligned">이동</th> |
| 34 | - <th >다운로드</th> | 35 | + <th class="collapsing">삭제</th> |
| 36 | + <th class="collapsing">다운로드</th> | ||
| 35 | </tr></thead> | 37 | </tr></thead> |
| 36 | <tbody> | 38 | <tbody> |
| 37 | - {% for file in files %} | 39 | + {% if path != "" %} |
| 40 | + <td> | ||
| 41 | + <a onclick="go_parent()"><i class="folder icon"></i> ...</a> | ||
| 42 | + </td> | ||
| 43 | + {% endif %} | ||
| 44 | + | ||
| 38 | <tr> | 45 | <tr> |
| 46 | + {% for file in files %} | ||
| 39 | <td class="collapsing"> | 47 | <td class="collapsing"> |
| 40 | {% if file.type == "directory" %} | 48 | {% if file.type == "directory" %} |
| 41 | {% with new_path=path|add:file.name|add:'/' %} | 49 | {% with new_path=path|add:file.name|add:'/' %} |
| 42 | - <a href="{% url 'file_list' path=new_path %}"><i class="folder icon"></i> {{file.name}}</a> | 50 | + <a href="{% url 'file_list' path=new_path %}" ><i class="folder icon"></i> {{file.name}}</a> |
| 43 | {% endwith %} | 51 | {% endwith %} |
| 44 | {% else %} | 52 | {% else %} |
| 45 | - <i class="file outline icon"></i> {{file.name}} | 53 | + {% with new_path=path|add:file.name %} |
| 54 | + <a style="color: black" href="{% url 'file_view' path=new_path %}"><i class="file outline icon"></i> {{file.name}} </a> | ||
| 55 | + {% endwith %} | ||
| 46 | {% endif %} | 56 | {% endif %} |
| 47 | </td> | 57 | </td> |
| 48 | - <td class="center aligned collapsing"> | 58 | + <td> |
| 49 | - {% with new_path=path|add:file.name|add:'/' %} | 59 | + {% if file.type != "directory" %} |
| 50 | - <a href="#"><i class="copy outline icon"></i></a> | 60 | + {% with old_path=path|add:file.name %} |
| 51 | - {% endwith %} | 61 | + <input placeholder="dir/test.txt" type="text" id="{{ old_path }}"> |
| 52 | - | 62 | + {% endwith %} |
| 63 | + {% endif %} | ||
| 64 | + | ||
| 53 | </td> | 65 | </td> |
| 54 | - <td class="center aligned collapsing"><i onclick="make_folder()" style="cursor: pointer;" class="sign out alternate icon"></i></td> | 66 | + <td class="collapsing"> |
| 67 | + <div> | ||
| 68 | + {% if file.type != "directory" %} | ||
| 69 | + {% with old_path=path|add:file.name %} | ||
| 70 | + <a style="color: black" id= "copy_path" onclick="copy('{{ old_path }}')"><i class="copy outline icon"></i></a> | ||
| 71 | + {% endwith %} | ||
| 72 | + {% endif %} | ||
| 73 | + </div> | ||
| 74 | + </td> | ||
| 75 | + | ||
| 55 | <td class="center aligned collapsing"> | 76 | <td class="center aligned collapsing"> |
| 56 | - {% with new_path=path|add:file.name %} | 77 | + {% if file.type != "directory" %} |
| 57 | - <a href="{% url 'file_delete' path=new_path %}"><i class="trash alternate outline icon"></i></a> | 78 | + {% with old_path=path|add:file.name %} |
| 58 | - {% endwith %} | 79 | + <a style="color: black" onclick="move('{{ old_path }}')"><i class="sign out alternate icon"></i></a> |
| 59 | - </td> | 80 | + {% endwith %} |
| 60 | - <td class="center aligned collapsing"> | 81 | + {% endif %} |
| 61 | - {% with new_path=path|add:file.name %} | 82 | + </td> |
| 62 | - <a href="{% url 'file_download' path=new_path %}"><i style="cursor: pointer;" class="download icon"></i></a> | 83 | + |
| 63 | - {% endwith %} | 84 | + <td class="center aligned collapsing"> |
| 64 | - </td> | 85 | + {% with new_path=path|add:file.name %} |
| 86 | + <a style="color: black" href="{% url 'file_delete' path=new_path %}"><i class="trash alternate outline icon"></i></a> | ||
| 87 | + {% endwith %} | ||
| 88 | + </td> | ||
| 89 | + | ||
| 90 | + <td class="center aligned collapsing"> | ||
| 91 | + {% with new_path=path|add:file.name %} | ||
| 92 | + <a style="color: black" href="{% url 'file_download' path=new_path %}"><i class="download icon"></i></a> | ||
| 93 | + {% endwith %} | ||
| 94 | + </td> | ||
| 65 | </tr> | 95 | </tr> |
| 66 | {% endfor %} | 96 | {% endfor %} |
| 67 | </tbody> | 97 | </tbody> |
| ... | @@ -83,24 +113,33 @@ | ... | @@ -83,24 +113,33 @@ |
| 83 | document.getElementById("dir_make").style.display = "inline-block"; | 113 | document.getElementById("dir_make").style.display = "inline-block"; |
| 84 | } | 114 | } |
| 85 | 115 | ||
| 86 | - function make_directory(dir_path){ | 116 | + function make_directory(){ |
| 117 | + | ||
| 87 | dir = document.getElementById("dir_name").value; | 118 | dir = document.getElementById("dir_name").value; |
| 119 | + console.log(dir) | ||
| 88 | var dir_path = "{{ path }}"; | 120 | var dir_path = "{{ path }}"; |
| 89 | new_path = dir_path + dir + '/'; | 121 | new_path = dir_path + dir + '/'; |
| 90 | location.href = "{% url 'make_folder' path='' %}" + new_path; | 122 | location.href = "{% url 'make_folder' path='' %}" + new_path; |
| 91 | } | 123 | } |
| 92 | - | 124 | + function go_parent(){ |
| 93 | - function copy(){ | 125 | + var dir_path = "{{ path }}"; |
| 94 | - | 126 | + var dir_arr = dir_path.split('/'); |
| 127 | + dir_arr.pop(); | ||
| 128 | + dir_arr.pop(); | ||
| 129 | + var new_path = dir_arr.join('/'); | ||
| 130 | + location.href = "{% url 'file_list' path='' %}" + new_path; | ||
| 95 | } | 131 | } |
| 96 | - function move(){ | ||
| 97 | 132 | ||
| 133 | + function copy(old){ | ||
| 134 | + var copy_path = document.getElementById(old).value; | ||
| 135 | + location.href = "/copy/"+old+"&" + copy_path; | ||
| 98 | } | 136 | } |
| 99 | - function delete_file(){ | ||
| 100 | 137 | ||
| 138 | + function move(old){ | ||
| 139 | + var move_path = document.getElementById(old).value; | ||
| 140 | + location.href = "/move/"+old+"&" + move_path; | ||
| 141 | + | ||
| 101 | } | 142 | } |
| 102 | - function download(){ | ||
| 103 | 143 | ||
| 104 | - } | ||
| 105 | </script> | 144 | </script> |
| 106 | {% endblock %} | 145 | {% endblock %} |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -12,9 +12,10 @@ urlpatterns = [ | ... | @@ -12,9 +12,10 @@ 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'^view/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)$', views.file_view, name='file_view'), | ||
| 15 | url(r'^make_folder/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.make_folder, name='make_folder'), | 16 | url(r'^make_folder/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.make_folder, name='make_folder'), |
| 16 | - | 17 | + url(r'^copy/(?P<old_path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)&(?P<new_path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]]*/*)*)$', views.file_copy, name='file_copy'), |
| 18 | + url(r'^move/(?P<old_path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)&(?P<new_path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]]*/*)*)$', views.file_move, name='file_move'), | ||
| 17 | url(r'^delete/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)$', views.file_delete, name='file_delete'), | 19 | 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'), | 20 | url(r'^download/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/*)*)$', views.file_download, name='file_download'), |
| 19 | - | ||
| 20 | ] | 21 | ] |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -76,4 +76,29 @@ def file_view(request, path): | ... | @@ -76,4 +76,29 @@ def file_view(request, path): |
| 76 | response = HttpResponse(fh.read(), content_type='text/plain' ) | 76 | response = HttpResponse(fh.read(), content_type='text/plain' ) |
| 77 | response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path) | 77 | response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path) |
| 78 | return response | 78 | return response |
| 79 | - raise Http404 | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 79 | + raise Http404 | ||
| 80 | + | ||
| 81 | +@login_required | ||
| 82 | +def file_copy(request, old_path, new_path): | ||
| 83 | + cookies = {'sessionid' : request.session.session_key} | ||
| 84 | + cookies['csrftoken'] = csrf.get_token(request) | ||
| 85 | + headers = {'X-CSRFToken': cookies['csrftoken']} | ||
| 86 | + files = requests.post('http://localhost:8000/restapi/file-mod/'+old_path+'&'+new_path, data={'method': 'cp'}, headers=headers, cookies=cookies) | ||
| 87 | + print(files.json()) | ||
| 88 | + new_path = "/".join(new_path.split("/")[:-1]) | ||
| 89 | + if new_path != '': | ||
| 90 | + new_path = new_path+'/' | ||
| 91 | + return redirect('file_list', path=new_path) | ||
| 92 | + | ||
| 93 | +@login_required | ||
| 94 | +def file_move(request, old_path, new_path): | ||
| 95 | + cookies = {'sessionid' : request.session.session_key} | ||
| 96 | + cookies['csrftoken'] = csrf.get_token(request) | ||
| 97 | + headers = {'X-CSRFToken': cookies['csrftoken']} | ||
| 98 | + files = requests.post('http://localhost:8000/restapi/file-mod/'+old_path+'&'+new_path, data={'method': 'mv'}, headers=headers, cookies=cookies) | ||
| 99 | + print(files.json()) | ||
| 100 | + new_path = "/".join(new_path.split("/")[:-1]) | ||
| 101 | + if new_path != '': | ||
| 102 | + new_path = new_path+'/' | ||
| 103 | + return redirect('file_list', path=new_path) | ||
| 104 | + | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment