X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/967eed676fc83d15b26149047f353ac61faa8217..6a41571eecb01fc448e4d5d6a9d3059523988f18:/src/sponsors/models.py?ds=sidebyside diff --git a/src/sponsors/models.py b/src/sponsors/models.py index 8b5055239..c193f427e 100644 --- a/src/sponsors/models.py +++ b/src/sponsors/models.py @@ -1,10 +1,10 @@ -# -*- 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. # import json import time from io import BytesIO +from django.core.cache import cache from django.db import models from django.utils.translation import ugettext_lazy as _ from django.template.loader import render_to_string @@ -12,7 +12,6 @@ from PIL import Image from jsonfield import JSONField from django.core.files.base import ContentFile -from ssify import flush_ssi_includes THUMB_WIDTH = 120 THUMB_HEIGHT = 120 @@ -66,14 +65,14 @@ class SponsorPage(models.Model): if simg.size[0] > THUMB_WIDTH or simg.size[1] > THUMB_HEIGHT: size = ( min(THUMB_WIDTH, - simg.size[0] * THUMB_HEIGHT / simg.size[1]), + round(simg.size[0] * THUMB_HEIGHT / simg.size[1])), min(THUMB_HEIGHT, - simg.size[1] * THUMB_WIDTH / simg.size[0]) + round(simg.size[1] * THUMB_WIDTH / simg.size[0])) ) simg = simg.resize(size, Image.ANTIALIAS) sprite.paste(simg, ( - (THUMB_WIDTH - simg.size[0]) / 2, - i * THUMB_HEIGHT + (THUMB_HEIGHT - simg.size[1]) / 2, + round((THUMB_WIDTH - simg.size[0]) / 2), + round(i * THUMB_HEIGHT + (THUMB_HEIGHT - simg.size[1]) / 2), )) imgstr = BytesIO() sprite.save(imgstr, 'png') @@ -97,11 +96,8 @@ class SponsorPage(models.Model): 'page': self }) ret = super(SponsorPage, self).save(*args, **kwargs) - self.flush_includes() + cache.delete('sponsor_page:' + name) return ret - def flush_includes(self): - flush_ssi_includes(['/sponsors/page/%s.html' % self.name]) - def __str__(self): return self.name