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