Added Length validator

Added wtforms Length validator. Applied this validator to the bill amount because large values will crash an instance of the project.
This commit is contained in:
mazzolaa 2021-12-06 02:19:09 -05:00 committed by GitHub
parent 915c832acc
commit 24657e1fff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,6 +20,7 @@ from wtforms.validators import (
NumberRange, NumberRange,
Optional, Optional,
ValidationError, ValidationError,
Length,
) )
from ihatemoney.currency_convertor import CurrencyConverter from ihatemoney.currency_convertor import CurrencyConverter
@ -305,7 +306,7 @@ class BillForm(FlaskForm):
date = DateField(_("When?"), validators=[DataRequired()], default=datetime.now) date = DateField(_("When?"), validators=[DataRequired()], default=datetime.now)
what = StringField(_("What?"), validators=[DataRequired()]) what = StringField(_("What?"), validators=[DataRequired()])
payer = SelectField(_("Who paid?"), validators=[DataRequired()], coerce=int) payer = SelectField(_("Who paid?"), validators=[DataRequired()], coerce=int)
amount = CalculatorStringField(_("How much?"), validators=[DataRequired()]) amount = CalculatorStringField(_("How much?"), validators=[DataRequired(), Length(max=20)])
currency_helper = CurrencyConverter() currency_helper = CurrencyConverter()
original_currency = SelectField(_("Currency"), validators=[DataRequired()]) original_currency = SelectField(_("Currency"), validators=[DataRequired()])
external_link = URLField( external_link = URLField(