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.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():
|
||||||
|
if current_user.is_authenticated:
|
||||||
return redirect(url_for('get_pit_stops'))
|
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'])
|
||||||
|
|
|
@ -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">
|
||||||
|
|
|
@ -15,3 +15,4 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -7,5 +7,4 @@
|
||||||
{{ 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 %}
|
||||||
|
|
Loading…
Reference in New Issue