From 088d1f24a099c41f26355868b444739daae1ea3e Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Tue, 16 Aug 2016 13:21:54 +0200 Subject: [PATCH] add redirect if vehicle is not configured and flash messages --- app/__init__.py | 8 +++++--- app/static/main.css | 10 +++++++++- app/templates/editVehicleForm.html | 2 +- app/templates/layout.html | 19 +++++++++++++++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index c908e2f..c2d0e09 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,6 +1,4 @@ -from datetime import date - -from flask import Flask +from flask import Flask, flash from flask import redirect, g from flask import render_template from flask import url_for @@ -241,6 +239,10 @@ def select_consumable_for_new_pitstop(vid): if vehicle is None or vehicle not in current_user.vehicles: return redirect(url_for('select_vehicle_for_new_pitstop')) + if len(vehicle.consumables) == 0: + flash('Please choose at least one consumable!', 'warning') + return redirect(url_for('edit_vehicle', vid=vid)) + if len(vehicle.consumables) == 1: return redirect(url_for('create_pit_stop_form', vid=vid, cid=vehicle.consumables[0].id)) diff --git a/app/static/main.css b/app/static/main.css index 6b9476b..73b9e3b 100644 --- a/app/static/main.css +++ b/app/static/main.css @@ -3,7 +3,7 @@ body { } .starter-template { - padding-top: 30px; + padding-top: 0px; padding-bottom: 60px; text-align: center; } @@ -59,6 +59,14 @@ h3:after{ text-align: left; } +.alert { + margin-bottom:0px; +} + +.topspace { + margin-top: 5px; +} + // for small devices @media only screen and (min-device-width : 320px) diff --git a/app/templates/editVehicleForm.html b/app/templates/editVehicleForm.html index c5b18dd..78638c5 100644 --- a/app/templates/editVehicleForm.html +++ b/app/templates/editVehicleForm.html @@ -5,7 +5,7 @@
-

Edit vehicle

+

Edit vehicle '{{vehicle.name}}'

{{ form.hidden_tag() }} {{ render_field_with_errors(form.name) }} diff --git a/app/templates/layout.html b/app/templates/layout.html index 49a4383..91314bf 100644 --- a/app/templates/layout.html +++ b/app/templates/layout.html @@ -151,8 +151,23 @@
- -
+ {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} +
+
+
+ +
+
+
+ {% endfor %} + {% endif %} + {% endwith %} +
{% block body %} {% endblock %}