regular_costs #5

Merged
jlusiardi merged 19 commits from regular_costs into master 2021-06-18 20:20:13 +02:00
1 changed files with 25 additions and 0 deletions
Showing only changes of commit 1f2e33bec4 - Show all commits

View File

@ -2,6 +2,31 @@ from wtforms.validators import ValidationError
from datetime import date from datetime import date
def odometer_date_check(form, field):
"""
Checks that the entered date and odometer of the pitstop is conformant to the existing pitstops. That means, if a
pitstops date is between to other pitstops, the odometer should be as well.
:param form:
:param field:
:return:
"""
odometer = form.odometer.data
date = form.date.data
pitstops = form.pitstops
if date < pitstops[0].date and odometer >= pitstops[0].odometer:
raise ValidationError('The new odometer value must be less than %i km' % pitstops[0].odometer)
for index in range(0, len(pitstops)-1):
if pitstops[index].date <= date < pitstops[index + 1].date:
if odometer <= pitstops[index].odometer or odometer >= pitstops[index+1].odometer:
raise ValidationError('The new odometer value must be greater than %i km and less than %i km'
% (pitstops[index].odometer,pitstops[index+1].odometer))
if date >= pitstops[-1].date and odometer <= pitstops[-1].odometer:
raise ValidationError('The new odometer value must be greater than %i km' % pitstops[-1].odometer)
def date_check(form, field): def date_check(form, field):
""" """
Checks that the date of the pitstop is not before the date of the latest pitstop and not after today. Checks that the date of the pitstop is not before the date of the latest pitstop and not after today.