X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/09afe5bd72a407c6d6474ccce467b7a9dddda0bf..b95d1183f738648f51099c1f75ace38e0c683456:/apps/funding/models.py diff --git a/apps/funding/models.py b/apps/funding/models.py index 3a74238e7..1eff8b4c6 100644 --- a/apps/funding/models.py +++ b/apps/funding/models.py @@ -9,10 +9,11 @@ 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.utils.timezone import utc from django.utils.translation import ugettext_lazy as _, ugettext, override import getpaid from catalogue.models import Book -from catalogue.utils import get_random_hash +from catalogue.utils import get_random_hash, related_tag_name from polls.models import Poll from django.contrib.sites.models import Site from . import app_settings @@ -124,6 +125,9 @@ class Offer(models.Model): """ QuerySet for all completed payments for the offer. """ return Funding.payed().filter(offer=self) + def funders(self): + return self.funding_payed().order_by('-amount', 'payed_at') + def sum(self): """ The money gathered. """ return self.funding_payed().aggregate(s=models.Sum('amount'))['s'] or 0 @@ -145,7 +149,7 @@ class Offer(models.Model): 'remaining': self.remaining(), 'current': self.current(), }) - self.notified_end = datetime.now() + self.notified_end = datetime.utcnow().replace(tzinfo=utc) self.save() def notify_near(self, force=False): @@ -162,7 +166,7 @@ class Offer(models.Model): 'sum': sum_, 'need': need, }) - self.notified_near = datetime.now() + self.notified_near = datetime.utcnow().replace(tzinfo=utc) self.save() def notify_published(self): @@ -172,7 +176,7 @@ class Offer(models.Model): 'funding/email/published.txt', { 'offer': self, 'book': self.book, - 'author': ", ".join(a[0] for a in self.book.related_info()['tags']['author']), + 'author': ", ".join(related_tag_name(a) for a in self.book.related_info()['tags']['author']), 'current': self.current(), }) @@ -230,6 +234,9 @@ class Funding(models.Model): def get_absolute_url(self): return reverse('funding_funding', args=[self.pk]) + def perk_names(self): + return ", ".join(perk.name for perk in self.perks.all()) + def get_disable_notifications_url(self): return "%s?%s" % (reverse("funding_disable_notifications"), urlencode({ @@ -267,7 +274,7 @@ class Funding(models.Model): with override(self.language_code or app_settings.DEFAULT_LANGUAGE): send_mail(subject, render_to_string(template_name, context), - getattr(settings, 'CONTACT_EMAIL', 'wolnelektury@nowoczesnapolska.org.pl'), + settings.CONTACT_EMAIL, [self.email], fail_silently=False ) @@ -311,7 +318,7 @@ getpaid.signals.user_data_query.connect(user_data_query_listener) def payment_status_changed_listener(sender, instance, old_status, new_status, **kwargs): """ React to status changes from getpaid. """ if old_status != 'paid' and new_status == 'paid': - instance.order.payed_at = datetime.now() + instance.order.payed_at = datetime.utcnow().replace(tzinfo=utc) instance.order.save() if instance.order.email: instance.order.notify(