Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
62776b30
Commit
62776b30
authored
Sep 21, 2016
by
WKuipers
Committed by
Wietse Kuipers
Nov 23, 2016
Browse files
Add album downloading
Zip files are put in /tmp/ then served with sendfile
parent
5a725fa7
Changes
3
Hide whitespace changes
Inline
Side-by-side
website/photos/templates/photos/album.html
View file @
62776b30
...
...
@@ -9,7 +9,13 @@
{% endblock %}
{% block body %}
<h1>
{{ album.title }}
</h1>
<h1>
{{ album.title }}
<span
class=
"title-meta clearfix"
>
<span><a
href=
"{% url 'photos:album-download' album.slug %}"
class=
"overlay-icon-download"
></a></span>
<span><a
href=
"{% url 'photos:index' %}"
class=
"back"
></a></span>
</span>
<span
class=
"title-meta clearfix"
>
</h1>
<h2>
{{ album.date|date:"d-m-Y" }}
</h2>
{% if album.shareable %}
<p
class=
"tcenter"
>
...
...
website/photos/urls.py
View file @
62776b30
...
...
@@ -9,6 +9,7 @@ urlpatterns = [
url
(
r
'^shared-download/(?P<slug>[-\w]+)/(?P<token>[a-zA-Z0-9]+)/(?P<path>.*)'
,
views
.
shared_download
,
name
=
'shared-download'
),
url
(
r
'^shared-thumbnail/(?P<slug>[-\w]+)/(?P<token>[a-zA-Z0-9]+)/(?P<size_fit>\d+x\d+_[01])/(?P<path>.*)'
,
views
.
shared_thumbnail
,
name
=
'shared-thumbnail'
),
url
(
r
'^(?P<slug>[-\w]+)/$'
,
views
.
album
,
name
=
'album'
),
url
(
r
'^(?P<slug>[-\w]+)/download$'
,
views
.
album_download
,
name
=
'album-download'
),
url
(
r
'^(?P<slug>[-\w]+)/(?P<token>[a-zA-Z0-9]+)$'
,
views
.
shared_album
,
name
=
'shared_album'
),
url
(
r
'^$'
,
views
.
index
,
name
=
'index'
),
]
website/photos/views.py
View file @
62776b30
...
...
@@ -7,6 +7,8 @@ from django.http import Http404
from
django.db.models
import
Q
from
django.shortcuts
import
get_object_or_404
,
render
from
sendfile
import
sendfile
from
zipfile
import
ZipFile
from
tempfile
import
gettempdir
from
utils.snippets
import
sanitize_path
from
utils.views
import
_private_thumbnails_unauthed
...
...
@@ -110,11 +112,30 @@ def _download(request, path):
return
sendfile
(
request
,
path
,
attachment
=
True
)
def
_album_download
(
request
,
slug
):
"""This function provides a layer of indirection for shared albums"""
album
=
get_object_or_404
(
Album
,
slug
=
slug
)
albumpath
=
os
.
path
.
join
(
album
.
photospath
,
album
.
dirname
)
pictures
=
[
os
.
path
.
join
(
albumpath
,
x
)
for
x
in
os
.
listdir
(
albumpath
)]
zipfilename
=
os
.
path
.
join
(
gettempdir
(),
'{}.zip'
.
format
(
album
.
dirname
))
if
not
os
.
path
.
exists
(
zipfilename
):
with
ZipFile
(
zipfilename
,
'w'
)
as
f
:
for
picture
in
pictures
:
f
.
write
(
picture
,
arcname
=
os
.
path
.
basename
(
picture
))
return
sendfile
(
request
,
zipfilename
,
attachment
=
True
)
@
login_required
def
download
(
request
,
path
):
return
_download
(
request
,
path
)
@
login_required
def
album_download
(
request
,
slug
):
return
_album_download
(
request
,
slug
)
def
shared_download
(
request
,
slug
,
token
,
path
):
_checked_shared_album
(
slug
,
token
)
return
_download
(
request
,
path
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment