return retval
def is_current(self):
- return self.start <= date.today() <= self.end
+ return self.start <= date.today() <= self.end and self == self.current()
def is_win(self):
return self.sum() >= self.target
@classmethod
def current(cls):
- """ 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.
+
+ """
today = date.today()
- objects = cls.objects.filter(start__lte=today, end__gte=today)
+ objects = cls.objects.filter(start__lte=today, end__gte=today).order_by('-end')
try:
return objects[0]
except IndexError:
@classmethod
def past(cls):
- """ 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
@classmethod
def public(cls):
{% autopaginate object_list 10 %}
+{% if page_obj.number == 1 %}
+ <h2>{% trans "Current fundraiser:" %}</h2>
+{% endif %}
+
{% for offer in object_list %}
{% with is_win=offer.is_win is_current=offer.is_current %}
-
- {% if is_current %}
- <h2>{% trans "Current fundraiser:" %}</h2>
- {% elif forloop.is_first %}
+ {% if not is_current and forloop.first and page_obj.number == 1 %}
+ <p class="normal-text">{% trans "No fundraiser is currently running." %}</p>
<h2>{% trans "Previous fundraisers:" %}</h2>
{% endif %}
def funding(context, offer=None, link=False, closeable=False, show_title=True, show_title_calling = True, add_class=""):
if offer is None and context.get('funding_no_show_current') is None:
offer = Offer.current()
+ is_current = True
+ elif offer is not None:
+ is_current = offer.is_current()
+
if offer is None:
return {}
return {
'offer': offer,
'sum': offer_sum,
- 'is_current': offer.is_current(),
+ 'is_current': is_current,
'is_win': offer_sum >= offer.target,
'missing': offer.target - offer_sum,
'percentage': 100 * offer_sum / offer.target,
urlpatterns = patterns('',
url(r'^$', CurrentView.as_view(), name='funding_current'),
+ url(r'^teraz/$', CurrentView.as_view()),
url(r'^teraz/(?P<slug>[^/]+)/$', CurrentView.as_view(), name='funding_current'),
url(r'^lektura/$', OfferListView.as_view(), name='funding'),
url(r'^lektura/(?P<slug>[^/]+)/$', OfferDetailView.as_view(), name='funding_offer'),
def dispatch(self, request, slug=None):
self.object = Offer.current()
if self.object is None:
- raise Http404
+ return redirect(reverse('funding'))
elif slug != self.object.slug:
return redirect(reverse('funding_current', args=[self.object.slug]))
return super(CurrentView, self).dispatch(request, slug)