1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from decimal import Decimal, DecimalException
5 from django import forms
6 from django.template.loader import render_to_string
9 class PerksAmountWidget(forms.Textarea):
11 def perks_input_name(name):
12 return "_%s_perk" % name
14 def render(self, name, value, attrs=None, renderer=None):
16 value = Decimal(value)
17 except DecimalException:
19 perks = list(self.form_instance.offer.get_perks())
22 if perk.price == value:
27 return render_to_string("funding/widgets/amount.html", {
30 "perks_input_name": self.perks_input_name(name),
31 "perk_chosen": perk_chosen,
36 def value_from_datadict(self, data, files, name):
37 num_str = data.get(self.perks_input_name(name)) or data[name]
38 return num_str.replace(',', '.')