can add pitstops to vehicles nows
This commit is contained in:
parent
3709eddabb
commit
038e255b56
|
@ -27,7 +27,8 @@ mail = Mail(app)
|
||||||
from rollerverbrauch.forms import \
|
from rollerverbrauch.forms import \
|
||||||
CreatePitstopForm, \
|
CreatePitstopForm, \
|
||||||
EditVehicleForm, \
|
EditVehicleForm, \
|
||||||
DeleteVehicleForm
|
DeleteVehicleForm, \
|
||||||
|
SelectVehicleForm
|
||||||
|
|
||||||
from rollerverbrauch.entities import \
|
from rollerverbrauch.entities import \
|
||||||
User, \
|
User, \
|
||||||
|
@ -122,22 +123,41 @@ def create_vehicle():
|
||||||
return render_template('createVehicleForm.html', form=form)
|
return render_template('createVehicleForm.html', form=form)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/pitstops/createForm', methods=['GET', 'POST'])
|
@app.route('/pitstops/select_vehicle', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def create_pit_stop_form():
|
def select_vehicle_for_new_pitstop():
|
||||||
last_pitstop = Pitstop.query.order_by(Pitstop.id.desc()).first()
|
form = SelectVehicleForm()
|
||||||
if last_pitstop is None:
|
form.vehicle.choices = [(g.id, g.name) for g in current_user.vehicles]
|
||||||
|
|
||||||
|
if form.validate_on_submit():
|
||||||
|
vehicle = Vehicle.query.filter(Vehicle.id == form.vehicle.data).first()
|
||||||
|
if not vehicle in current_user.vehicles:
|
||||||
|
return render_template('selectVehice.html', form=form)
|
||||||
|
|
||||||
|
return redirect(url_for('create_pit_stop_form', vid=form.vehicle.data))
|
||||||
|
|
||||||
|
return render_template('selectVehice.html', form=form)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/pitstops/create/<int:vid>', methods=['GET', 'POST'])
|
||||||
|
@login_required
|
||||||
|
def create_pit_stop_form(vid):
|
||||||
|
vehicle = Vehicle.query.filter(Vehicle.id == vid).first()
|
||||||
|
if not vehicle in current_user.vehicles:
|
||||||
|
return redirect(url_for('select_vehicle_for_new_pitstop'))
|
||||||
|
|
||||||
|
if len(vehicle.pitstops) > 0:
|
||||||
|
last_pitstop = vehicle.pitstops[-1]
|
||||||
|
else:
|
||||||
last_pitstop = Pitstop(0, 0, date.today())
|
last_pitstop = Pitstop(0, 0, date.today())
|
||||||
|
|
||||||
form = CreatePitstopForm()
|
form = CreatePitstopForm()
|
||||||
form.set_pitstop(last_pitstop)
|
form.set_pitstop(last_pitstop)
|
||||||
form.vehicle.choices = [(g.id, g.name) for g in current_user.vehicles]
|
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
v = Vehicle.query.filter(Vehicle.id == form.vehicle.data).first()
|
|
||||||
new_stop = Pitstop(form.odometer.data, form.litres.data, form.date.data)
|
new_stop = Pitstop(form.odometer.data, form.litres.data, form.date.data)
|
||||||
db.session.add(new_stop)
|
db.session.add(new_stop)
|
||||||
v.pitstops.append(new_stop)
|
vehicle.pitstops.append(new_stop)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(url_for('get_pit_stops'))
|
return redirect(url_for('get_pit_stops'))
|
||||||
|
|
||||||
|
@ -145,7 +165,7 @@ def create_pit_stop_form():
|
||||||
form.litres.default = last_pitstop.litres
|
form.litres.default = last_pitstop.litres
|
||||||
form.date.default = date.today()
|
form.date.default = date.today()
|
||||||
form.process()
|
form.process()
|
||||||
return render_template('newPitStopForm.html', form=form)
|
return render_template('newPitStopForm.html', form=form, vehicle = vehicle)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/pitstops', methods=['GET'])
|
@app.route('/pitstops', methods=['GET'])
|
||||||
|
|
|
@ -18,8 +18,11 @@ def litres_check(form, field):
|
||||||
raise ValidationError('You must fuel at least 0.1 l')
|
raise ValidationError('You must fuel at least 0.1 l')
|
||||||
|
|
||||||
|
|
||||||
class CreatePitstopForm(Form):
|
class SelectVehicleForm(Form):
|
||||||
vehicle = SelectField('Vehicle', coerce=int)
|
vehicle = SelectField('Vehicle', coerce=int)
|
||||||
|
|
||||||
|
|
||||||
|
class CreatePitstopForm(Form):
|
||||||
date = DateField('Date of Pitstop', validators=[date_check])
|
date = DateField('Date of Pitstop', validators=[date_check])
|
||||||
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
|
odometer = IntegerField('Odometer (km)', validators=[odometer_check])
|
||||||
litres = DecimalField('Litres (l)', places=1, validators=[litres_check])
|
litres = DecimalField('Litres (l)', places=1, validators=[litres_check])
|
||||||
|
@ -35,7 +38,3 @@ class EditVehicleForm(Form):
|
||||||
|
|
||||||
class DeleteVehicleForm(Form):
|
class DeleteVehicleForm(Form):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,56 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Account management for {{current_user.email}}</h1>
|
<h3>Account management for {{current_user.email}}</h3>
|
||||||
|
<div class="panel panel-default">
|
||||||
<a href='{{ url_for('security.change_password') }}'>Change password</a>
|
<div class="panel-heading">Password</div>
|
||||||
|
<div class="panel-body">
|
||||||
<a href="{{ url_for('create_vehicle') }}">create</a>
|
<a href='{{ url_for('security.change_password') }}'>
|
||||||
<table>
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Change
|
||||||
{% for vehicle in current_user.vehicles %}
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">Vehicles</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<a href="{{ url_for('create_vehicle') }}">
|
||||||
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span> create
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<table class="table table-striped table-bordered">
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{vehicle.name}}</td>
|
<th>
|
||||||
<td><a href="{{ url_for('edit_vehicle', vid=vehicle.id) }}">edit</a></td>
|
Vehicle
|
||||||
<td><a href="{{ url_for('delete_vehicle', vid=vehicle.id) }}">delete</a></td>
|
</th>
|
||||||
|
<th>
|
||||||
|
Info
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Actions
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% for vehicle in current_user.vehicles %}
|
||||||
</table>
|
<tr>
|
||||||
|
<td style="text-align:center">
|
||||||
|
{{ vehicle.name }}
|
||||||
|
</td>
|
||||||
|
<td style="text-align:center">
|
||||||
|
{{ vehicle.pitstops | length }} pitstops
|
||||||
|
</td>
|
||||||
|
<td style="text-align:center">
|
||||||
|
<a href="{{ url_for('edit_vehicle', vid=vehicle.id) }}">
|
||||||
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit
|
||||||
|
</a>
|
||||||
|
{% if current_user.vehicles | length > 1 %}
|
||||||
|
<a href="{{ url_for('delete_vehicle', vid=vehicle.id) }}">
|
||||||
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> delete
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Admin</h1>
|
<h3>Admin</h3>
|
||||||
We have {{ data.users|length }} users so far:
|
We have {{ data.users|length }} users so far:
|
||||||
<ul>
|
<ul>
|
||||||
{% for user in data.users %}
|
{% for user in data.users %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Create vehicle</h1>
|
<h3>Create vehicle</h3>
|
||||||
<form class='form-horizontal' method="POST">
|
<form class='form-horizontal' method="POST">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
{{ render_field_with_errors(form.name) }}
|
{{ render_field_with_errors(form.name) }}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Delete vehicle "{{vehicle.name}}"</h1>
|
<h3>Delete vehicle '{{vehicle.name}}'</h3>
|
||||||
<form class='form-horizontal' method="POST">
|
<form class='form-horizontal' method="POST">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
<input type="submit" value="Go">
|
<input type="submit" value="Go">
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Edit vehicle</h1>
|
<h3>Edit vehicle</h3>
|
||||||
<form class='form-horizontal' method="POST">
|
<form class='form-horizontal' method="POST">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
{{ render_field_with_errors(form.name) }}
|
{{ render_field_with_errors(form.name) }}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% macro navigation() -%}
|
{% macro navigation() -%}
|
||||||
{% if current_user.email %}
|
{% if current_user.email %}
|
||||||
<li><a href='{{ url_for('create_pit_stop_form') }}'>Create Pitstop</a></li>
|
<li><a href='{{ url_for('select_vehicle_for_new_pitstop') }}'>Create Pitstop</a></li>
|
||||||
<li><a href='{{ url_for('get_statistics') }}'>Statistics</a></li>
|
<li><a href='{{ url_for('get_statistics') }}'>Statistics</a></li>
|
||||||
<li><a href='{{ url_for('get_account_page') }}'>Account</a></li>
|
<li><a href='{{ url_for('get_account_page') }}'>Account</a></li>
|
||||||
{% if current_user.has_role('admin') %}
|
{% if current_user.has_role('admin') %}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
<h3>New Pitstop for '{{ vehicle.name }}'</h3>
|
||||||
<form class='form-horizontal' method="POST">
|
<form class='form-horizontal' method="POST">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
{{ render_field_with_errors(form.vehicle) }}
|
|
||||||
{{ render_field_with_errors(form.date) }}
|
{{ render_field_with_errors(form.date) }}
|
||||||
{{ render_field_with_errors(form.odometer) }}
|
{{ render_field_with_errors(form.odometer) }}
|
||||||
{{ render_field_with_errors(form.litres) }}
|
{{ render_field_with_errors(form.litres) }}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<form class='form-horizontal' method="POST">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
{{ render_field_with_errors(form.vehicle) }}
|
||||||
|
<input type="submit" value="Go">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
Loading…
Reference in New Issue