Adds start page for unauthed visitors

This commit is contained in:
Joachim Lusiardi 2016-05-18 08:17:53 +02:00
parent 227dc79e6b
commit 7eef2b6cee
4 changed files with 27 additions and 7 deletions

View File

@ -9,6 +9,7 @@ from flask.ext.security import Security, SQLAlchemyUserDatastore, \
from flask.ext.security import user_registered from flask.ext.security import user_registered
from flask_security.core import current_user from flask_security.core import current_user
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from flask.ext.security.forms import LoginForm
app = Flask(__name__) app = Flask(__name__)
app.config['SECURITY_PASSWORD_HASH'] = 'pbkdf2_sha512' app.config['SECURITY_PASSWORD_HASH'] = 'pbkdf2_sha512'
@ -72,9 +73,28 @@ def before_request():
@app.route('/') @app.route('/')
@login_required
def index(): 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/<int:vid>', methods=['GET', 'POST']) @app.route('/account/edit_vehicle/<int:vid>', methods=['GET', 'POST'])

View File

@ -134,7 +134,7 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="{{ url_for('get_pit_stops') }}">refuel journal</a> <a class="navbar-brand" href="{{ url_for('index') }}">refuel journal</a>
</div> </div>
<div id="navbar" class="collapse navbar-collapse"> <div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">

View File

@ -15,3 +15,4 @@
{% endif %} {% endif %}
</form> </form>
{% endblock %} {% endblock %}

View File

@ -3,9 +3,8 @@
{% block body %} {% block body %}
<h3>Select Vehicle</h3> <h3>Select 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.vehicle) }} {{ render_field_with_errors(form.vehicle) }}
{{ render_field_with_errors(form.submit) }} {{ render_field_with_errors(form.submit) }}
</form> </form>
{% endblock %} {% endblock %}