Showing
5 changed files
with
34 additions
and
19 deletions
... | @@ -66,6 +66,6 @@ | ... | @@ -66,6 +66,6 @@ |
66 | 66 | ||
67 | <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> | 67 | <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> |
68 | <script src='{% static "js/bootstrap.js"%}'></script> | 68 | <script src='{% static "js/bootstrap.js"%}'></script> |
69 | - <script src='{% static "semantic/dist/semantic.min.js"%'></script> | 69 | + <script src='{% static "semantic/dist/semantic.min.js"%}'></script> |
70 | </body> | 70 | </body> |
71 | </html> | 71 | </html> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -6,22 +6,23 @@ | ... | @@ -6,22 +6,23 @@ |
6 | </style> | 6 | </style> |
7 | <center> | 7 | <center> |
8 | <div> | 8 | <div> |
9 | - <form method="post", action="{% url 'file_upload' %}" > | 9 | + <form method="post", enctype="multipart/form-data", action="{% url 'file_upload' path=path %}" > |
10 | {% csrf_token %} | 10 | {% csrf_token %} |
11 | <div style="border: solid; display:inline-block; padding: 5px; border-color: skyblue" > | 11 | <div style="border: solid; display:inline-block; padding: 5px; border-color: skyblue" > |
12 | - <input type="file"> | 12 | + <input type="file" name="file"> |
13 | </div> | 13 | </div> |
14 | <button style="margin-top: 10px" class="ui primary button" type="submit"><i class="upload icon"></i>업로드</button> | 14 | <button style="margin-top: 10px" class="ui primary button" type="submit"><i class="upload icon"></i>업로드</button> |
15 | </form> | 15 | </form> |
16 | </div> | 16 | </div> |
17 | </center> | 17 | </center> |
18 | 18 | ||
19 | -<button class="ui primary button" style="margin-left: 24%" type="submit" onclick="make_folder()"><i class="plus icon"></i>폴더 만들기</button> | 19 | +<button class="ui primary button" style="margin-left: 28%" type="submit" onclick="make_folder()"><i class="plus icon"></i>폴더 만들기</button> |
20 | <br> | 20 | <br> |
21 | <center> | 21 | <center> |
22 | <table style="margin-top: 7px" class="ui celled striped collapsing table"> | 22 | <table style="margin-top: 7px" class="ui celled striped collapsing table"> |
23 | <thead> | 23 | <thead> |
24 | - <tr><th class="twelve wide">/{{ user.username }}/</th> | 24 | + |
25 | + <tr><th class="twelve wide">/{{ path }}</th> | ||
25 | <th>복사</th> | 26 | <th>복사</th> |
26 | <th >이동</th> | 27 | <th >이동</th> |
27 | <th>삭제</th> | 28 | <th>삭제</th> |
... | @@ -32,7 +33,9 @@ | ... | @@ -32,7 +33,9 @@ |
32 | <tr> | 33 | <tr> |
33 | <td class="collapsing"> | 34 | <td class="collapsing"> |
34 | {% if file.type == "directory" %} | 35 | {% if file.type == "directory" %} |
35 | - <a href="#"><i class="folder icon"></i> {{file.name}}</a> | 36 | + {% with new_path=path|add:file.name|add:'/' %} |
37 | + <a href="{% url 'file_list' path=new_path %}"><i class="folder icon"></i> {{file.name}}</a> | ||
38 | + {% endwith %} | ||
36 | {% else %} | 39 | {% else %} |
37 | <i class="file outline icon"></i> {{file.name}} | 40 | <i class="file outline icon"></i> {{file.name}} |
38 | {% endif %} | 41 | {% endif %} |
... | @@ -43,6 +46,7 @@ | ... | @@ -43,6 +46,7 @@ |
43 | <td class="center aligned collapsing"><i onclick="make_folder()" style="cursor: pointer;" class="download icon"></i></td> | 46 | <td class="center aligned collapsing"><i onclick="make_folder()" style="cursor: pointer;" class="download icon"></i></td> |
44 | </tr> | 47 | </tr> |
45 | {% endfor %} | 48 | {% endfor %} |
49 | + </tbody> | ||
46 | </table> | 50 | </table> |
47 | </center> | 51 | </center> |
48 | 52 | ... | ... |
... | @@ -18,7 +18,7 @@ | ... | @@ -18,7 +18,7 @@ |
18 | <p class="text-center">D.cloud는 클라우드 사이트입니다.</p> | 18 | <p class="text-center">D.cloud는 클라우드 사이트입니다.</p> |
19 | <br> | 19 | <br> |
20 | {% if user.is_authenticated %} | 20 | {% if user.is_authenticated %} |
21 | - <p class="text-center"><a class= "btn btn-primary btn-lg" href="{% url 'file_list' %}" role ="button">내 클라우드로 가기</a></p> | 21 | + <p class="text-center"><a class= "btn btn-primary btn-lg" href="{% url 'file_list' path=''%}" role ="button">내 클라우드로 가기</a></p> |
22 | {% else %} | 22 | {% else %} |
23 | <p class="text-center"><a class= "btn btn-primary btn-lg" href="{% url 'login' %}" role ="button">내 클라우드로 가기</a></p> | 23 | <p class="text-center"><a class= "btn btn-primary btn-lg" href="{% url 'login' %}" role ="button">내 클라우드로 가기</a></p> |
24 | {% endif %} | 24 | {% endif %} | ... | ... |
... | @@ -9,9 +9,9 @@ urlpatterns = [ | ... | @@ -9,9 +9,9 @@ urlpatterns = [ |
9 | url(r'^accounts/delete_account_success/$', auth_views.delete_account_success, name='delete_account_success'), | 9 | url(r'^accounts/delete_account_success/$', auth_views.delete_account_success, name='delete_account_success'), |
10 | 10 | ||
11 | # blog | 11 | # blog |
12 | - url(r'^$', views.home), | 12 | + url(r'^$', views.home, name='home'), |
13 | - url(r'^files/', views.file_list, name='file_list'), | 13 | + url(r'^list/(?P<path>([\w\s가-힣.\`\'\˜\=\+\#\ˆ\@\$\&\-\.\(\)\{\}\;\[\]]*/)*)$', views.file_list, name='file_list'), |
14 | - url(r'^upload/', 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'^make_folder/', views.make_folder, name='make_folder'), |
16 | 16 | ||
17 | ] | 17 | ] |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -3,25 +3,36 @@ from django.utils import timezone | ... | @@ -3,25 +3,36 @@ from django.utils import timezone |
3 | from django.contrib.auth.decorators import login_required | 3 | from django.contrib.auth.decorators import login_required |
4 | from django.views.generic import FormView | 4 | from django.views.generic import FormView |
5 | from restful.models import File | 5 | from restful.models import File |
6 | +from django.views import View | ||
7 | +from django.core.files.base import ContentFile | ||
8 | +from django.middleware import csrf | ||
6 | import requests | 9 | import requests |
7 | 10 | ||
8 | 11 | ||
12 | + | ||
9 | def home(request): | 13 | def home(request): |
10 | return render(request, 'website/home.html') | 14 | return render(request, 'website/home.html') |
11 | 15 | ||
12 | 16 | ||
13 | @login_required | 17 | @login_required |
14 | -def file_list(request): | 18 | +def file_list(request, path): |
15 | cookies = {'sessionid' : request.session.session_key} | 19 | cookies = {'sessionid' : request.session.session_key} |
16 | - files = requests.get('http://localhost:8000/restapi/list/', cookies=cookies) | 20 | + files = requests.get('http://localhost:8000/restapi/list/'+path, cookies=cookies) |
17 | - return render(request, 'website/file_list.html', files.json()) | 21 | + ret = files.json() |
22 | + ret['path'] = path | ||
23 | + return render(request, 'website/file_list.html', ret) | ||
18 | 24 | ||
19 | -def file_upload(request): | 25 | +@login_required |
26 | +def file_upload(request, path): | ||
27 | + file = request.FILES.get('file') | ||
20 | cookies = {'sessionid' : request.session.session_key} | 28 | cookies = {'sessionid' : request.session.session_key} |
21 | - requests.post('http://localhost:8000/restapi/list/',request, cookies=cookies) | 29 | + cookies['csrftoken'] = csrf.get_token(request) |
22 | - return redirect('file_list') | 30 | + headers = {'X-CSRFToken': cookies['csrftoken']} |
31 | + print(cookies) | ||
32 | + requests.post('http://localhost:8000/restapi/list/', files={'file': file}, headers=headers, cookies=cookies) | ||
33 | + return redirect('file_list', path=path) | ||
23 | 34 | ||
24 | -def make_folder(request): | 35 | +def make_folder(request, path): |
25 | cookies = {'sessionid' : request.session.session_key} | 36 | cookies = {'sessionid' : request.session.session_key} |
26 | - files = requests.put('http://localhost:8000/restapi/list/', cookies=cookies) | 37 | + files = requests.put('http://localhost:8000/restapi/list/'+path, cookies=cookies) |
27 | - return redirect('file_list') | 38 | + return redirect('file_list', path=path) | ... | ... |
-
Please register or login to post a comment