Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신은섭(Shin Eun Seop)
/
2018-1-d.cloud
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
10
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
신은섭(Shin Eun Seop)
2018-06-13 22:29:18 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
28f703c9f6657440ecbf397ce9f206e9cab369db
28f703c9
1 parent
31b6ca16
file download
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
4 deletions
dcloud/restful/s3_interface.py
dcloud/website/templates/website/file_list.html
dcloud/website/views.py
dcloud/restful/s3_interface.py
View file @
28f703c
dcloud/website/templates/website/file_list.html
View file @
28f703c
...
...
@@ -57,7 +57,11 @@
<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>
<td
class=
"center aligned collapsing"
>
{% with new_path=path|add:file.name %}
<a
href=
"{% url 'file_download' path=new_path %}"
><i
style=
"cursor: pointer;"
class=
"download icon"
></i></a>
{% endwith %}
</td>
</tr>
{% endfor %}
</tbody>
...
...
dcloud/website/views.py
View file @
28f703c
...
...
@@ -6,10 +6,12 @@ from restful.models import File
from
django.views
import
View
from
django.core.files.base
import
ContentFile
from
django.middleware
import
csrf
from
dcloud
import
settings
from
django.http
import
HttpResponse
import
os
import
requests
def
home
(
request
):
return
render
(
request
,
'website/home.html'
)
...
...
@@ -29,6 +31,7 @@ def file_upload(request, path):
cookies
[
'csrftoken'
]
=
csrf
.
get_token
(
request
)
headers
=
{
'X-CSRFToken'
:
cookies
[
'csrftoken'
]}
requests
.
post
(
'http://localhost:8000/restapi/list/'
+
path
,
files
=
{
'file'
:
file
},
headers
=
headers
,
cookies
=
cookies
)
# TODO delete mdeia/file
return
redirect
(
'file_list'
,
path
=
path
)
@login_required
...
...
@@ -46,10 +49,31 @@ def file_delete(request, path):
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
]))
new_path
=
"/"
.
join
(
path
.
split
(
"/"
)[:
-
1
])
if
new_path
!=
''
:
new_path
=
new_path
+
'/'
return
redirect
(
'file_list'
,
path
=
new_path
)
@login_required
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
file_path
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
path
)
if
os
.
path
.
exists
(
file_path
):
with
open
(
file_path
,
'rb'
)
as
fh
:
response
=
HttpResponse
(
fh
.
read
(),
content_type
=
'multipart/form-data'
)
response
[
'Content-Disposition'
]
=
'inline; filename='
+
os
.
path
.
basename
(
file_path
)
return
response
raise
Http404
@login_required
def
file_view
(
request
,
path
):
cookies
=
{
'sessionid'
:
request
.
session
.
session_key
}
requests
.
get
(
'http://localhost:8000/restapi/file/'
+
path
,
cookies
=
cookies
)
file_path
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
path
)
if
os
.
path
.
exists
(
file_path
):
with
open
(
file_path
,
'rb'
)
as
fh
:
response
=
HttpResponse
(
fh
.
read
(),
content_type
=
'text/plain'
)
response
[
'Content-Disposition'
]
=
'inline; filename='
+
os
.
path
.
basename
(
file_path
)
return
response
raise
Http404
\ No newline at end of file
...
...
Please
register
or
login
to post a comment