Fixes.
[wolnelektury.git] / src / sponsors / models.py
index 8b50552..c193f42 100644 (file)
@@ -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