Unused imports & whitespace
[wolnelektury.git] / apps / funding / templatetags / funding_tags.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from django import template
6 from ..models import Offer
7 from ..utils import sanitize_payment_title
8
9 register = template.Library()
10
11
12 @register.inclusion_tag("funding/tags/funding.html", takes_context=True)
13 def funding(context, offer=None, link=False, closeable=False, show_title=True, show_title_calling=True, add_class=""):
14     if offer is None and context.get('funding_no_show_current') is None:
15         offer = Offer.current()
16         is_current = True
17     elif offer is not None:
18         is_current = offer.is_current()
19
20     if offer is None:
21         return {}
22
23     offer_sum = offer.sum()
24     return {
25         'offer': offer,
26         'sum': offer_sum,
27         'is_current': is_current,
28         'is_win': offer_sum >= offer.target,
29         'missing': offer.target - offer_sum,
30         'percentage': 100 * offer_sum / offer.target,
31         'link': link,
32         'closeable': closeable,
33         'show_title': show_title,
34         'show_title_calling': show_title_calling,
35         'add_class': add_class,
36     }
37
38
39 @register.inclusion_tag("funding/tags/offer_status.html")
40 def offer_status(offer):
41     return {
42         'offer': offer,
43     }
44
45 @register.inclusion_tag("funding/tags/offer_status_more.html")
46 def offer_status_more(offer):
47     return {
48         'offer': offer,
49     }
50
51 register.filter(sanitize_payment_title)