This commit adds a new field to each pitstop for tracking of costs. This includes: * a new DB column * a new field in the create pitstop form * a new column in the pitstop overview * new stats values related to costs * 2 new graphs
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
from flask_wtf import Form
|
|
from wtforms import DateField, IntegerField, DecimalField, StringField, SelectField, SubmitField
|
|
from wtforms.validators import ValidationError, Length
|
|
from datetime import date
|
|
|
|
|
|
def date_check(form, field):
|
|
if field.data < form.last_pitstop.date:
|
|
raise ValidationError('The new date must not be before %s' % form.last_pitstop.date)
|
|
if field.data > date.today():
|
|
raise ValidationError('The new date must not be after %s' % date.today())
|
|
|
|
|
|
def odometer_check(form, field):
|
|
if field.data <= form.last_pitstop.odometer:
|
|
raise ValidationError('The new odometer value must be higher than %i km' % form.last_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')
|
|
|
|
|
|
def costs_check(form, field):
|
|
if field.data is not None and field.data <= 0:
|
|
raise ValidationError('Costs must be above 0.01 €.')
|
|
|
|
|
|
class SelectVehicleForm(Form):
|
|
vehicle = SelectField('Vehicle', coerce=int)
|
|
submit = SubmitField(label='Do it!')
|
|
|
|
|
|
class CreatePitstopForm(Form):
|
|
date = DateField('Date of Pitstop', validators=[date_check])
|
|
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
|
|
litres = DecimalField('Litres (l)', places=2, validators=[litres_check])
|
|
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
|
|
submit = SubmitField(label='Do it!')
|
|
last_pitstop = None
|
|
|
|
def set_pitstop(self, last_pitstop):
|
|
self.last_pitstop = last_pitstop
|
|
|
|
|
|
class EditVehicleForm(Form):
|
|
name = StringField('Name', validators=[Length(1, 255)])
|
|
submit = SubmitField(label='Do it!')
|
|
|
|
|
|
class DeleteVehicleForm(Form):
|
|
submit = SubmitField(label='Do it!')
|
|
|
|
|
|
class DeleteAccountForm(Form):
|
|
submit = SubmitField(label='Really delete my account!')
|