X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/dfd584e3b136d770bf56569030d10712a8722569..82c3054bcdeb000aa9782da80d644070797b5cbe:/apps/picture/templatetags/picture_tags.py diff --git a/apps/picture/templatetags/picture_tags.py b/apps/picture/templatetags/picture_tags.py index 1767ce228..02d80b005 100644 --- a/apps/picture/templatetags/picture_tags.py +++ b/apps/picture/templatetags/picture_tags.py @@ -2,31 +2,27 @@ # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +import logging +from random import randint from django import template +from django.core.urlresolvers import reverse +from django.utils.cache import add_never_cache_headers +import sorl.thumbnail.default +from ssify import ssi_variable from catalogue.utils import split_tags from ..engine import CustomCroppingEngine -import sorl.thumbnail.default -import logging +from ..models import Picture + register = template.Library() cropper = CustomCroppingEngine() -@register.inclusion_tag('picture/picture_short.html', takes_context=True) -def picture_short(context, picture): - context.update({ - 'picture': picture, - 'main_link': picture.get_absolute_url(), - 'request': context.get('request'), - 'tags': split_tags(picture.tags), - }) - return context - @register.inclusion_tag('picture/picture_wide.html', takes_context=True) def picture_wide(context, picture): context.update({ 'picture': picture, - 'main_link': picture.get_absolute_url(), + 'main_link': reverse('picture_viewer', args=[picture.slug]), 'request': context.get('request'), 'tags': split_tags(picture.tags), }) @@ -65,3 +61,15 @@ def area_thumbnail_url(area, geometry): sorl.thumbnail.default.engine = _engine return th.url + + +@ssi_variable(register, patch_response=[add_never_cache_headers]) +def picture_random_picture(request, exclude_ids, unless=None): + if unless: + return None + queryset = Picture.objects.exclude(pk__in=exclude_ids).exclude(image_file='') + count = queryset.count() + if count: + return queryset[randint(0, count - 1)].pk + else: + return None