diff options
| author | Arnaud Bos <arnaud.tlse@gmail.com> | 2011-11-17 09:07:32 +0100 |
|---|---|---|
| committer | Arnaud Bos <arnaud.tlse@gmail.com> | 2011-11-17 09:07:32 +0100 |
| commit | 9962b6d60f7c193cbdd34e76f8d2b414a4fc675b (patch) | |
| tree | 19f81b254cba76fd3bd8483146c3e28842dd8184 /budget/forms.py | |
| parent | 3bf8cececf19fbd47e19a9f60eb6d922106d61d0 (diff) | |
| parent | 04becafbddf6cac095d1429a37242fb79a83bba0 (diff) | |
| download | ihatemoney-mirror-9962b6d60f7c193cbdd34e76f8d2b414a4fc675b.zip ihatemoney-mirror-9962b6d60f7c193cbdd34e76f8d2b414a4fc675b.tar.gz ihatemoney-mirror-9962b6d60f7c193cbdd34e76f8d2b414a4fc675b.tar.bz2 | |
Merge branch 'master' of github.com:spiral-project/ihatemoney
Diffstat (limited to 'budget/forms.py')
| -rw-r--r-- | budget/forms.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/budget/forms.py b/budget/forms.py index 36bde64..f5c3fb5 100644 --- a/budget/forms.py +++ b/budget/forms.py @@ -45,6 +45,12 @@ def get_billform_for(project, set_default=True, **kwargs): form.set_default() return form +class CommaDecimalField(DecimalField): + """A class to deal with comma in Decimal Field""" + def process_formdata(self, value): + if value: + value[0] = str(value[0]).replace(',', '.') + return super(CommaDecimalField, self).process_formdata(value) class EditProjectForm(Form): @@ -101,7 +107,7 @@ class BillForm(Form): date = DateField(_("Date"), validators=[Required()], default=datetime.now) what = TextField(_("What?"), validators=[Required()]) payer = SelectField(_("Payer"), validators=[Required()], coerce=int) - amount = DecimalField(_("Amount paid"), validators=[Required()]) + amount = CommaDecimalField(_("Amount paid"), validators=[Required()]) payed_for = SelectMultipleField(_("For whom?"), validators=[Required()], widget=select_multi_checkbox, coerce=int) submit = SubmitField(_("Send the bill")) @@ -128,7 +134,9 @@ class BillForm(Form): def validate_amount(self, field): if field.data < 0: - raise ValidationError(_("Bills can't be negative")) + field.data = abs(field.data) + elif field.data == 0: + raise ValidationError(_("Bills can't be null")) class MemberForm(Form): |
