From 1ec4f14a4ac00c25879180f64f7ee255f006ca96 Mon Sep 17 00:00:00 2001 From: Wojciech Kwolek Date: Mon, 31 Aug 2020 22:42:57 +0200 Subject: [PATCH] add statistics --- app/__init__.py | 3 +++ app/stats.py | 19 +++++++++++++++++++ app/templates/stats.html | 9 +++++++++ 3 files changed, 31 insertions(+) create mode 100644 app/stats.py create mode 100644 app/templates/stats.html diff --git a/app/__init__.py b/app/__init__.py index 0498cc5..1e60430 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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 diff --git a/app/stats.py b/app/stats.py new file mode 100644 index 0000000..f003bb4 --- /dev/null +++ b/app/stats.py @@ -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 + ) diff --git a/app/templates/stats.html b/app/templates/stats.html new file mode 100644 index 0000000..b327bc7 --- /dev/null +++ b/app/templates/stats.html @@ -0,0 +1,9 @@ +{% extends "_skel.html" %} +{% block title %}Stats{% endblock %} +{% block content %} +
+

Total accomplishments added: {{ total }}
+ Without mine: {{ total_without_mine }}
+ Registered users: {{ total_users }}

+
+{% endblock %}