X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/dbb1ae2cf25105f7a3831961b08386a1326baef8..0e79f07515678e3e678c3637124a27cb81ee8a94:/apps/funding/models.py?ds=sidebyside diff --git a/apps/funding/models.py b/apps/funding/models.py index 800a15a3c..e36b73255 100644 --- a/apps/funding/models.py +++ b/apps/funding/models.py @@ -4,18 +4,19 @@ # from datetime import date, datetime from urllib import urlencode +from django.conf import settings +from django.contrib.sites.models import Site from django.core.urlresolvers import reverse from django.core.mail import send_mail -from django.conf import settings -from django.template.loader import render_to_string from django.db import models +from django.template.loader import render_to_string from django.utils.timezone import utc from django.utils.translation import ugettext_lazy as _, override import getpaid +from ssify import flush_ssi_includes from catalogue.models import Book -from catalogue.utils import get_random_hash, related_tag_name +from catalogue.utils import get_random_hash from polls.models import Poll -from django.contrib.sites.models import Site from . import app_settings @@ -58,10 +59,27 @@ class Offer(models.Model): self.pk is not None and type(self).objects.values('book').get(pk=self.pk)['book'] != self.book_id) retval = super(Offer, self).save(*args, **kw) + self.flush_includes() if published_now: self.notify_published() return retval + def flush_includes(self): + flush_ssi_includes([ + template % (self.pk, lang) + for template in [ + '/wesprzyj/o/%d/top-bar.%s.html', + '/wesprzyj/o/%d/detail-bar.%s.html', + '/wesprzyj/o/%d/list-bar.%s.html', + '/wesprzyj/o/%d/status.%s.html', + '/wesprzyj/o/%d/status-more.%s.html', + ] + [ + '/wesprzyj/o/%%d/fundings/%d.%%s.html' % page + for page in range(1, len(self.funding_payed()) // 10 + 2) + ] + for lang in [lc for (lc, _ln) in settings.LANGUAGES] + ]) + def is_current(self): return self.start <= date.today() <= self.end and self == self.current() @@ -176,7 +194,7 @@ class Offer(models.Model): 'funding/email/published.txt', { 'offer': self, 'book': self.book, - 'author': ", ".join(related_tag_name(a) for a in self.book.related_info()['tags']['author']), + 'author': self.book.pretty_title(), 'current': self.current(), }) @@ -247,7 +265,9 @@ class Funding(models.Model): def save(self, *args, **kwargs): if self.email and not self.notify_key: self.notify_key = get_random_hash(self.email) - return super(Funding, self).save(*args, **kwargs) + ret = super(Funding, self).save(*args, **kwargs) + self.offer.flush_includes() + return ret @classmethod def notify_funders(cls, subject, template_name, extra_context=None,