2016-04-23 23:08:39 +02:00
|
|
|
from flask_wtf import Form
|
2016-04-27 07:23:28 +02:00
|
|
|
from wtforms import DateField, IntegerField, DecimalField, StringField, SelectField, SubmitField
|
2016-04-23 23:24:25 +02:00
|
|
|
from wtforms.validators import ValidationError, Length
|
2016-04-23 23:08:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
def date_check(form, field):
|
|
|
|
if field.data < form.pitstop.date:
|
|
|
|
raise ValidationError('The new date must after %s' % form.pitstop.date)
|
|
|
|
|
|
|
|
|
|
|
|
def odometer_check(form, field):
|
|
|
|
if field.data <= form.pitstop.odometer:
|
|
|
|
raise ValidationError('The new odometer value must be higher than %i km' % form.pitstop.odometer)
|
|
|
|
|
|
|
|
|
|
|
|
def litres_check(form, field):
|
|
|
|
if field.data is not None and field.data <= 0:
|
|
|
|
raise ValidationError('You must fuel at least 0.1 l')
|
|
|
|
|
|
|
|
|
2016-04-24 14:09:41 +02:00
|
|
|
class SelectVehicleForm(Form):
|
2016-04-23 23:24:25 +02:00
|
|
|
vehicle = SelectField('Vehicle', coerce=int)
|
2016-04-27 07:23:28 +02:00
|
|
|
submit = SubmitField(label='Do it!')
|
2016-04-24 14:09:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CreatePitstopForm(Form):
|
2016-04-23 23:08:39 +02:00
|
|
|
date = DateField('Date of Pitstop', validators=[date_check])
|
|
|
|
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
|
2016-04-27 07:23:28 +02:00
|
|
|
litres = DecimalField('Litres (l)', places=2, validators=[litres_check])
|
|
|
|
submit = SubmitField(label='Do it!')
|
2016-04-23 23:08:39 +02:00
|
|
|
pitstop = None
|
|
|
|
|
|
|
|
def set_pitstop(self, pitstop):
|
|
|
|
self.pitstop = pitstop
|
|
|
|
|
|
|
|
|
2016-04-23 23:24:25 +02:00
|
|
|
class EditVehicleForm(Form):
|
|
|
|
name = StringField('Name', validators=[Length(1, 255)])
|
2016-04-27 07:23:28 +02:00
|
|
|
submit = SubmitField(label='Do it!')
|
2016-04-23 23:24:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
class DeleteVehicleForm(Form):
|
2016-04-27 07:23:28 +02:00
|
|
|
submit = SubmitField(label='Do it!')
|