From 7eef2b6cee867f639e38c4e7b69c0e12740b7753 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Wed, 18 May 2016 08:17:53 +0200 Subject: [PATCH 1/4] Adds start page for unauthed visitors --- app/rollerverbrauch/__init__.py | 24 +++++++++++++++++-- app/rollerverbrauch/templates/layout.html | 2 +- .../templates/security/login_user.html | 1 + .../templates/selectVehice.html | 7 +++--- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/app/rollerverbrauch/__init__.py b/app/rollerverbrauch/__init__.py index 3581461..19a6f99 100644 --- a/app/rollerverbrauch/__init__.py +++ b/app/rollerverbrauch/__init__.py @@ -9,6 +9,7 @@ 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 +from flask.ext.security.forms import LoginForm app = Flask(__name__) app.config['SECURITY_PASSWORD_HASH'] = 'pbkdf2_sha512' @@ -72,9 +73,28 @@ def before_request(): @app.route('/') -@login_required def index(): - return redirect(url_for('get_pit_stops')) + if current_user.is_authenticated: + return redirect(url_for('get_pit_stops')) + else: + user_count = len(User.query.all()) + vehicles = Vehicle.query.all() + litres = 0 + kilometers = 0 + for vehicle in vehicles: + stats = tools.VehicleStats(vehicle) + litres += stats.overall_litres + kilometers += stats.overall_distance + vehicle_count = len(vehicles) + pitstop_count = len(Pitstop.query.all()) + data = { + 'users':user_count, + 'vehicles': vehicle_count, + 'pitstops': pitstop_count, + 'litres': litres, + 'kilometers': kilometers + } + return render_template('index.html', login_user_form=LoginForm(), data=data) @app.route('/account/edit_vehicle/', methods=['GET', 'POST']) diff --git a/app/rollerverbrauch/templates/layout.html b/app/rollerverbrauch/templates/layout.html index 2df1885..e03289b 100644 --- a/app/rollerverbrauch/templates/layout.html +++ b/app/rollerverbrauch/templates/layout.html @@ -134,7 +134,7 @@ - refuel journal + refuel journal