Little Improvements
Help text for create pitstops form More precise error messages for create pitstops form Fixed bu in statistics page when only one pitstop was present
This commit is contained in:
parent
471f1415d9
commit
e1e5fe7725
|
@ -9,7 +9,6 @@ from flask.ext.security import Security, SQLAlchemyUserDatastore, \
|
|||
from flask.ext.security import user_registered
|
||||
from flask_security.core import current_user
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
import logging
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////data/rollerverbrauch.db'
|
||||
|
@ -162,7 +161,7 @@ def create_pit_stop_form(vid):
|
|||
if len(vehicle.pitstops) > 0:
|
||||
last_pitstop = vehicle.pitstops[-1]
|
||||
else:
|
||||
last_pitstop = Pitstop(0, 0, date.today())
|
||||
last_pitstop = Pitstop(0, 0, date(1970, 1, 1))
|
||||
|
||||
form = CreatePitstopForm()
|
||||
form.set_pitstop(last_pitstop)
|
||||
|
@ -179,7 +178,11 @@ def create_pit_stop_form(vid):
|
|||
form.litres.default = last_pitstop.litres
|
||||
form.date.default = date.today()
|
||||
form.process()
|
||||
return render_template('newPitStopForm.html', form=form, vehicle=vehicle)
|
||||
messages = {
|
||||
'date': 'Date must be between %s and %s (including).' % (str(last_pitstop.date), str(date.today())),
|
||||
'odometer': 'Odometer must be greater than %s km.' % (str(last_pitstop.odometer))
|
||||
}
|
||||
return render_template('newPitStopForm.html', form=form, vehicle=vehicle, messages = messages)
|
||||
|
||||
|
||||
@app.route('/pitstops', methods=['GET'])
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
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.pitstop.date:
|
||||
raise ValidationError('The new date must after %s' % form.pitstop.date)
|
||||
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.pitstop.odometer:
|
||||
raise ValidationError('The new odometer value must be higher than %i km' % form.pitstop.odometer)
|
||||
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):
|
||||
|
@ -28,10 +31,10 @@ class CreatePitstopForm(Form):
|
|||
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
|
||||
litres = DecimalField('Litres (l)', places=2, validators=[litres_check])
|
||||
submit = SubmitField(label='Do it!')
|
||||
pitstop = None
|
||||
last_pitstop = None
|
||||
|
||||
def set_pitstop(self, pitstop):
|
||||
self.pitstop = pitstop
|
||||
def set_pitstop(self, last_pitstop):
|
||||
self.last_pitstop = last_pitstop
|
||||
|
||||
|
||||
class EditVehicleForm(Form):
|
||||
|
|
|
@ -31,17 +31,17 @@
|
|||
{% endfor %}
|
||||
</select>
|
||||
{% elif field.type == 'BooleanField' %}
|
||||
<input class="form-control" type="checkbox" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" />
|
||||
<input class="form-control" type="checkbox" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" aria-describedby="{{ field.id }}_help" />
|
||||
{% elif field.type == 'StringField' %}
|
||||
<input class="form-control" type="text" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" />
|
||||
<input class="form-control" type="text" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" aria-describedby="{{ field.id }}_help" />
|
||||
{% elif field.type == 'PasswordField' %}
|
||||
<input class="form-control" type="password" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" />
|
||||
<input class="form-control" type="password" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" aria-describedby="{{ field.id }}_help" />
|
||||
{% elif field.type == 'DateField' %}
|
||||
<input class="form-control" type="date" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" />
|
||||
<input class="form-control" type="date" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" aria-describedby="{{ field.id }}_help" />
|
||||
{% elif field.type == 'IntegerField' %}
|
||||
<input class="form-control" type="number" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" step="1" />
|
||||
<input class="form-control" type="number" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" step="1" aria-describedby="{{ field.id }}_help" />
|
||||
{% elif field.type == 'DecimalField' %}
|
||||
<input class="form-control" type="number" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" step="{{ 1 / 10 ** field.places}}" />
|
||||
<input class="form-control" type="number" id="{{ field.id }}" name="{{ field.id }}" value="{{ field.default|none_filter }}" step="{{ 1 / 10 ** field.places}}" aria-describedby="{{ field.id }}_help" />
|
||||
{% else %}
|
||||
{{ field(**kwargs)|safe }}
|
||||
{% endif %}
|
||||
|
|
|
@ -5,7 +5,13 @@
|
|||
<form class='form-horizontal' method="POST">
|
||||
{{ form.hidden_tag() }}
|
||||
{{ render_field_with_errors(form.date) }}
|
||||
<span id="{{form.date.id}}_help" class="help-block">
|
||||
{{messages['date']}}
|
||||
</span>
|
||||
{{ render_field_with_errors(form.odometer) }}
|
||||
<span id="{{form.odometer.id}}_help" class="help-block">
|
||||
{{messages['odometer']}}
|
||||
</span>
|
||||
{{ render_field_with_errors(form.litres) }}
|
||||
{{ render_field_with_errors(form.submit) }}
|
||||
</form>
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
<div class="tab-pane " id="v{{vehicle.id}}_c3">
|
||||
{% if vehicle.pitstop_count > 0 %}
|
||||
{% if vehicle.pitstop_count > 1 %}
|
||||
<div id="averageUsageDiv{{vehicle.id}}" style="width:100%; height:500px;"></div>
|
||||
<script type="text/javascript">
|
||||
{{ chartScript('averageUsageDiv'+vehicle.id|str, vehicle.average_litres, 'l/100 km') }}
|
||||
|
|
Loading…
Reference in New Issue