add statistics

This commit is contained in:
Wojciech Kwolek 2020-08-31 22:42:57 +02:00
parent 20849b8ee5
commit 1ec4f14a4a
3 changed files with 31 additions and 0 deletions

View File

@ -25,4 +25,7 @@ def create_app():
auth.init_app(app)
app.register_blueprint(auth.blueprint)
from . import stats
app.register_blueprint(stats.blueprint)
return app

19
app/stats.py Normal file
View File

@ -0,0 +1,19 @@
from flask import Blueprint, render_template
from .db import db, Accomplishment, User
blueprint = Blueprint('stats', __name__)
@blueprint.route('/stats')
def stats():
total_accomplishments = Accomplishment.query.count()
total_accomplishments_by_me = Accomplishment.query.filter_by(
user_id=1).count()
total_users = User.query.count()
return render_template(
'stats.html',
total=total_accomplishments,
total_without_mine=total_accomplishments - total_accomplishments_by_me,
total_users=total_users
)

9
app/templates/stats.html Normal file
View File

@ -0,0 +1,9 @@
{% extends "_skel.html" %}
{% block title %}Stats{% endblock %}
{% block content %}
<div class="max-w-lg mx-auto text-center card">
<p><b>Total accomplishments added:</b> {{ total }}<br>
<b>Without mine:</b> {{ total_without_mine }}<br>
<b>Registered users:</b> {{ total_users }}</p>
</div>
{% endblock %}