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