Adds start page for unauthed visitors
This commit is contained in:
parent
227dc79e6b
commit
7eef2b6cee
@ -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/<int:vid>', methods=['GET', 'POST'])
|
||||
|
@ -134,7 +134,7 @@
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</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 id="navbar" class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
|
@ -15,3 +15,4 @@
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
|
@ -3,9 +3,8 @@
|
||||
{% block body %}
|
||||
<h3>Select Vehicle</h3>
|
||||
<form class='form-horizontal' method="POST">
|
||||
{{ form.hidden_tag() }}
|
||||
{{ render_field_with_errors(form.vehicle) }}
|
||||
{{ render_field_with_errors(form.submit) }}
|
||||
{{ form.hidden_tag() }}
|
||||
{{ render_field_with_errors(form.vehicle) }}
|
||||
{{ render_field_with_errors(form.submit) }}
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user