From 2e3c70edcd15b528a433cacd4e1a95be27ab158b Mon Sep 17 00:00:00 2001 From: Adrien CLERC Date: Sat, 2 May 2020 12:40:30 +0200 Subject: [PATCH] enable currency rendering for bill form --- ihatemoney/forms.py | 23 +++++++++-------------- ihatemoney/web.py | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index dc4daea7..2c6099a0 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -45,19 +45,8 @@ def get_billform_for(project, set_default=True, **kwargs): form.original_currency.data = project.default_currency if form.original_currency.data != CurrencyConverter.default: - choices = copy.copy(form.original_currency.choices) - choices.remove((CurrencyConverter.default, CurrencyConverter.default)) - choices.sort( - key=lambda rates: "" if rates[0] == project.default_currency else rates[0] - ) - form.original_currency.choices = choices - else: - form.original_currency.render_kw = {"default": True} - form.original_currency.data = CurrencyConverter.default + form.original_currency.choices.remove((CurrencyConverter.default, render_localized_currency(CurrencyConverter.default, detailed=False))) - form.original_currency.label = Label( - "original_currency", "Currency (Default: %s)" % (project.default_currency) - ) active_members = [(m.id, m.name) for m in project.active_members] form.payed_for.choices = form.payer.choices = active_members @@ -233,7 +222,7 @@ class BillForm(FlaskForm): original_currency = SelectField( _("Currency"), choices=[ - (currency_name, currency_name) + (currency_name, render_localized_currency(currency_name, detailed=False)) for currency_name in currency_helper.get_currencies() ], validators=[DataRequired()], @@ -276,7 +265,7 @@ class BillForm(FlaskForm): return bill - def fill(self, bill): + def fill(self, bill, project): self.payer.data = bill.payer_id self.amount.data = bill.amount self.what.data = bill.what @@ -285,6 +274,12 @@ class BillForm(FlaskForm): self.date.data = bill.date self.payed_for.data = [int(ower.id) for ower in bill.owers] + if bill.original_currency != project.default_currency: + label = _("Currency (Default: %(currency)s)", currency=project.default_currency) + else: + label = _("Currency") + self.original_currency.label = Label("original_currency", label) + def set_default(self): self.payed_for.data = self.payed_for.default diff --git a/ihatemoney/web.py b/ihatemoney/web.py index d2094d8c..ba783012 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -733,7 +733,7 @@ def edit_bill(bill_id): return redirect(url_for(".list_bills")) if not form.errors: - form.fill(bill) + form.fill(bill, g.project) return render_template("add_bill.html", form=form, edit=True)