X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ae60b2a3949e96357477cc04f90fd0873cee8a92..HEAD:/src/picture/templatetags/picture_tags.py diff --git a/src/picture/templatetags/picture_tags.py b/src/picture/templatetags/picture_tags.py index b31405b8d..f6ba50017 100644 --- a/src/picture/templatetags/picture_tags.py +++ b/src/picture/templatetags/picture_tags.py @@ -1,14 +1,12 @@ -# -*- coding: utf-8 -*- -# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # import logging from random import randint from django import template -from django.core.urlresolvers import reverse +from django.urls 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 from ..models import Picture @@ -19,17 +17,6 @@ register = template.Library() cropper = CustomCroppingEngine() -@register.inclusion_tag('picture/picture_wide.html', takes_context=True) -def picture_wide(context, picture): - context.update({ - 'picture': picture, - 'main_link': reverse('picture_viewer', args=[picture.slug]), - 'request': context.get('request'), - 'tags': split_tags(picture.tags), - }) - return context - - @register.simple_tag() def area_thumbnail_url(area, geometry): def to_square(coords): @@ -48,14 +35,16 @@ def area_thumbnail_url(area, geometry): # what to do about this? _engine = sorl.thumbnail.default.engine sorl.thumbnail.default.engine = cropper - coords = to_square(area.area) + coords = to_square(area.get_area_json()) try: th = sorl.thumbnail.default.backend.get_thumbnail( area.picture.image_file, geometry, crop="%dpx %dpx %dpx %dpx" % tuple(map(lambda d: max(0, d), tuple(coords[0] + coords[1])))) - except Exception, e: + except ZeroDivisionError: + return '' + except Exception as e: logging.exception("Error creating a thumbnail for PictureArea") return '' @@ -64,13 +53,11 @@ def area_thumbnail_url(area, geometry): 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 +@register.simple_tag +def picture_random_picture(exclude_ids): queryset = Picture.objects.exclude(pk__in=exclude_ids).exclude(image_file='') count = queryset.count() if count: - return queryset[randint(0, count - 1)].pk + return queryset[randint(0, count - 1)] else: return None