Funding: behave nicer with time conflicts.
[wolnelektury.git] / apps / funding / templatetags / funding_tags.py
1 from django import template
2 from ..models import Offer
3
4 register = template.Library()
5
6
7 @register.inclusion_tag("funding/tags/funding.html", takes_context=True)
8 def funding(context, offer=None, link=False, closeable=False, show_title=True, show_title_calling = True, add_class=""):
9     if offer is None and context.get('funding_no_show_current') is None:
10         offer = Offer.current()
11         is_current = True
12     elif offer is not None:
13         is_current = offer.is_current()
14
15     if offer is None:
16         return {}
17
18     offer_sum = offer.sum()
19     return {
20         'offer': offer,
21         'sum': offer_sum,
22         'is_current': is_current,
23         'is_win': offer_sum >= offer.target,
24         'missing': offer.target - offer_sum,
25         'percentage': 100 * offer_sum / offer.target,
26         'link': link,
27         'closeable': closeable,
28         'show_title': show_title,
29         'show_title_calling': show_title_calling,
30         'add_class': add_class,
31     }
32
33
34 @register.inclusion_tag("funding/tags/offer_status.html")
35 def offer_status(offer):
36     return {
37         'offer': offer,
38     }
39     
40 @register.inclusion_tag("funding/tags/offer_status_more.html")
41 def offer_status_more(offer):
42     return {
43         'offer': offer,
44     }
45
46