views.py 820 Bytes
Newer Older
1
2
3
import os

from django.conf import settings
4
from django.contrib.auth.decorators import login_required
Joost Rijneveld's avatar
Joost Rijneveld committed
5
from django.http import Http404
6
7
8
9
10
from sendfile import sendfile

from .snippets import sanitize_path


11
12
13
14
def _private_thumbnails_unauthed(request, size_fit, path):
    """This layer of indirection makes it possible to make exceptions
    to the authentication requirements for thumbnails, e.g. when sharing
    photo albums with external parties using access tokens."""
15
16
    path = sanitize_path(path)
    path = os.path.join(settings.MEDIA_ROOT, 'thumbnails', size_fit, path)
Joost Rijneveld's avatar
Joost Rijneveld committed
17
18
    if not os.path.isfile(path):
        raise Http404("Thumbnail not found.")
19
    return sendfile(request, path)
20
21
22
23
24


@login_required
def private_thumbnails(request, size_fit, path):
    return _private_thumbnails_unauthed(request, size_fit, path)