From 8f0e995471a5e4c8deb113abc9bc33877ebc570a Mon Sep 17 00:00:00 2001 From: Luke Else Date: Fri, 2 Feb 2024 16:42:19 +0000 Subject: [PATCH] #5 Added ability to get a quick overview of all of the product stats on one page. --- controllers/database/stats.py | 2 +- controllers/web/stats.py | 9 ++++++--- templates/stats.html | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 templates/stats.html diff --git a/controllers/database/stats.py b/controllers/database/stats.py index 4656c12..c8ab8d3 100644 --- a/controllers/database/stats.py +++ b/controllers/database/stats.py @@ -29,7 +29,7 @@ class StatsController(DatabaseController): cursor = self._conn.execute( "SELECT * FROM Views", ) - rows = cursor.fetchmany() + rows = cursor.fetchall() if rows is None: return None diff --git a/controllers/web/stats.py b/controllers/web/stats.py index 1a3cdc7..879ccd6 100644 --- a/controllers/web/stats.py +++ b/controllers/web/stats.py @@ -15,20 +15,23 @@ blueprint = Blueprint("stats", __name__, url_prefix='/stats') @blueprint.route('/') def stats_index(): + """ Main page to view all of the statistics for the site """ db = StatsController() data = db.read() - return "" + return render_template("index.html", content="stats.html", data=data) @blueprint.route('/product/') def view_product_stats(id: int): + """ Page to view statistics for a given product """ db = StatsController() data = db.read_product(id) - return "" + return render_template("index.html", content="stats.html", data=data) @blueprint.route('/user/') def view_user_stats(id: int): + """ Page to view statistics for a given user """ db = StatsController() data = db.read_user(id) - return "" + return render_template("index.html", content="stats.html", data=data) diff --git a/templates/stats.html b/templates/stats.html new file mode 100644 index 0000000..3de953f --- /dev/null +++ b/templates/stats.html @@ -0,0 +1,17 @@ + + +
+ {% if data != None %} + {% for stat in data %} + +
{{stat.userID}}
+
+
+
£{{stat.productID}}
+
{{stat.viewDate}}
+
+
+
+ {% endfor %} + {% endif %} +