ae3b04f62c1706756333f1e9feeac7c47c665d32
[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, add_class=""):
9     if offer is None and context.get('funding_no_show_current') is None:
10         offer = Offer.current()
11     if offer is None:
12         return {}
13
14     offer_sum = offer.sum()
15     return {
16         'offer': offer,
17         'sum': offer_sum,
18         'is_current': offer.is_current(),
19         'missing': offer.target - offer_sum,
20         'percentage': 100 * offer_sum / offer.target,
21         'link': link,
22         'add_class': add_class,
23     }
24
25
26 @register.inclusion_tag("funding/tags/offer_detail_head.html")
27 def offer_detail_head(offer):
28     return {
29         'offer': offer,
30         'state': offer.state(),
31     }
32