Commit 62776b30 authored by WKuipers's avatar WKuipers Committed by Wietse Kuipers
Browse files

Add album downloading

Zip files are put in /tmp/ then served with sendfile
parent 5a725fa7
......@@ -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 class="title-meta clearfix">
<h2>{{|date:"d-m-Y" }}</h2>
{% if album.shareable %}
<p class="tcenter">
......@@ -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'),
......@@ -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(),
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)
def download(request, path):
return _download(request, path)
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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment