Updates create pitstop form
The form now uses the new odometer_date_check to allow entering pitstops that are before the currently last pitstop.
This commit is contained in:
parent
25705562ad
commit
13090d2735
|
@ -35,16 +35,16 @@ class EditPitstopForm(FlaskForm):
|
||||||
|
|
||||||
|
|
||||||
class CreatePitstopForm(FlaskForm):
|
class CreatePitstopForm(FlaskForm):
|
||||||
date = DateField('Date of Pitstop', validators=[date_check])
|
date = DateField('Date of Pitstop')
|
||||||
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
|
odometer = IntegerField('Odometer (km)', validators=[odometer_date_check])
|
||||||
litres = DecimalField('Litres (l)', places=2, validators=[litres_check])
|
litres = DecimalField('Litres (l)', places=2, validators=[litres_check])
|
||||||
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
|
costs = DecimalField('Costs (€, overall)', places=2, validators=[costs_check])
|
||||||
submit = SubmitField(label='Do it!')
|
submit = SubmitField(label='Do it!')
|
||||||
last_pitstop = None
|
|
||||||
same_odometer_allowed = True
|
same_odometer_allowed = True
|
||||||
|
pitstops = []
|
||||||
|
|
||||||
def set_pitstop(self, last_pitstop):
|
def set_pitstops(self, pitstops):
|
||||||
self.last_pitstop = last_pitstop
|
self.pitstops = pitstops
|
||||||
|
|
||||||
def set_consumable(self, consumable):
|
def set_consumable(self, consumable):
|
||||||
self.litres.label = '%s (%s)' % (consumable.name, consumable.unit)
|
self.litres.label = '%s (%s)' % (consumable.name, consumable.unit)
|
||||||
|
@ -57,24 +57,19 @@ class CreatePitstopForm(FlaskForm):
|
||||||
if self.odometer.data:
|
if self.odometer.data:
|
||||||
self.odometer.default = self.odometer.data
|
self.odometer.default = self.odometer.data
|
||||||
else:
|
else:
|
||||||
self.odometer.default = self.last_pitstop.odometer
|
self.odometer.default = self.pitstops[-1].odometer
|
||||||
if self.litres.data:
|
if self.litres.data:
|
||||||
self.litres.default = self.litres.data
|
self.litres.default = self.litres.data
|
||||||
else:
|
else:
|
||||||
self.litres.default = self.last_pitstop.amount
|
self.litres.default = self.pitstops[-1].amount
|
||||||
if self.costs.data:
|
if self.costs.data:
|
||||||
self.costs.default = self.costs.data
|
self.costs.default = self.costs.data
|
||||||
else:
|
else:
|
||||||
self.costs.default = self.last_pitstop.costs
|
self.costs.default = self.pitstops[-1].costs
|
||||||
|
|
||||||
def get_hint_messages(self):
|
def get_hint_messages(self):
|
||||||
if self.same_odometer_allowed:
|
|
||||||
or_equal = ' or equal to'
|
|
||||||
else:
|
|
||||||
or_equal = ''
|
|
||||||
messages = {
|
messages = {
|
||||||
'date': 'Date must be between %s and %s (including).' % (str(self.last_pitstop.date), str(date.today())),
|
'litres': 'Litres must be higher than 0.01 L.',
|
||||||
'odometer': 'Odometer must be greater than%s %s km.' % (or_equal, str(self.last_pitstop.odometer)),
|
|
||||||
'costs': 'Costs must be higher than 0.01 €.'
|
'costs': 'Costs must be higher than 0.01 €.'
|
||||||
}
|
}
|
||||||
return messages
|
return messages
|
||||||
|
|
|
@ -64,7 +64,7 @@ def create_pit_stop_form(vid, cid):
|
||||||
|
|
||||||
data = get_event_line_for_vehicle(vehicle)
|
data = get_event_line_for_vehicle(vehicle)
|
||||||
if len(data) > 0:
|
if len(data) > 0:
|
||||||
form.set_pitstop(Pitstop(data[-1].odometer, 0, data[-1].date, 0, cid))
|
form.set_pitstops(vehicle.pitstops)
|
||||||
form.same_odometer_allowed = (type(data[-1]) != Pitstop) or (data[-1].consumable.id != cid)
|
form.same_odometer_allowed = (type(data[-1]) != Pitstop) or (data[-1].consumable.id != cid)
|
||||||
else:
|
else:
|
||||||
form.set_pitstop(Pitstop(date(1970, 1, 1), 0, vid, 0, ''))
|
form.set_pitstop(Pitstop(date(1970, 1, 1), 0, vid, 0, ''))
|
||||||
|
|
Loading…
Reference in New Issue