from django.conf import settings
from django.template.loader import render_to_string
from django.db import models
from django.conf import settings
from django.template.loader import render_to_string
from django.db import models
from django.utils.translation import ugettext_lazy as _, ugettext, override
import getpaid
from catalogue.models import Book
from django.utils.translation import ugettext_lazy as _, ugettext, override
import getpaid
from catalogue.models import Book
target = models.DecimalField(_('target'), decimal_places=2, max_digits=10)
start = models.DateField(_('start'), db_index=True)
end = models.DateField(_('end'), db_index=True)
target = models.DecimalField(_('target'), decimal_places=2, max_digits=10)
start = models.DateField(_('start'), db_index=True)
end = models.DateField(_('end'), db_index=True)
redakcja_url = models.URLField(_('redakcja URL'), blank=True)
book = models.ForeignKey(Book, null=True, blank=True,
help_text=_('Published book.'))
cover = models.ImageField(_('Cover'), upload_to = 'funding/covers')
poll = models.ForeignKey(Poll, help_text = _('Poll'), null = True, blank = True, on_delete = models.SET_NULL)
redakcja_url = models.URLField(_('redakcja URL'), blank=True)
book = models.ForeignKey(Book, null=True, blank=True,
help_text=_('Published book.'))
cover = models.ImageField(_('Cover'), upload_to = 'funding/covers')
poll = models.ForeignKey(Poll, help_text = _('Poll'), null = True, blank = True, on_delete = models.SET_NULL)
- """ Returns current fundraiser or None. """
+ """ Returns current fundraiser or None.
+
+ Current fundraiser is the one that:
+ - has already started,
+ - hasn't yet ended,
+ - if there's more than one of those, it's the one that ends last.
+
+ """
- """ QuerySet for all current and past fundraisers. """
- today = date.today()
- return cls.objects.filter(end__lt=today)
+ """ QuerySet for all past fundraisers. """
+ objects = cls.public()
+ current = cls.current()
+ if current is not None:
+ objects = objects.exclude(pk=current.pk)
+ return objects
assert not self.is_current()
self.notify_all(
_('The fundraiser has ended!'),
assert not self.is_current()
self.notify_all(
_('The fundraiser has ended!'),
'remaining': self.remaining(),
'current': self.current(),
})
'remaining': self.remaining(),
'current': self.current(),
})
def get_absolute_url(self):
return reverse('funding_funding', args=[self.pk])
def get_absolute_url(self):
return reverse('funding_funding', args=[self.pk])
def get_disable_notifications_url(self):
return "%s?%s" % (reverse("funding_disable_notifications"),
urlencode({
def get_disable_notifications_url(self):
return "%s?%s" % (reverse("funding_disable_notifications"),
urlencode({
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':
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':