shared_thumbnail.py 474 Bytes
Newer Older
1
from django import template
2
from django.urls import resolve, reverse
3

Tom van Bussel's avatar
Tom van Bussel committed
4
5
from os.path import basename

6
7
8
9
10
11
12
13
from utils.templatetags.thumbnail import thumbnail

register = template.Library()


@register.simple_tag
def shared_thumbnail(slug, token, path, size, fit=True):
    thumb = resolve(thumbnail(path, size, fit))
Tom van Bussel's avatar
Tom van Bussel committed
14
15
    filename = basename(thumb.kwargs['path'])
    args = [slug, thumb.kwargs['size_fit'], token, filename]
16
    return reverse('photos:shared-thumbnail', args=args)