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.
5 from decimal import Decimal
6 from django.conf import settings
7 from django import forms
8 from django.template.loader import render_to_string
11 class PerksAmountWidget(forms.Textarea):
12 def perks_input_name(self, name):
13 return "_%s_perk" % name
15 def render(self, name, value, attrs=None):
17 value = Decimal(value)
20 perks = list(self.form_instance.offer.get_perks())
23 if perk.price == value:
28 return render_to_string("funding/widgets/amount.html", {
31 "perks_input_name": self.perks_input_name(name),
32 "perk_chosen": perk_chosen,
37 def value_from_datadict(self, data, files, name):
38 num_str = data.get(self.perks_input_name(name)) or data[name]
39 return num_str.replace(',', '.')