From b66cdea7532385be2c132209db60e3d79e144f26 Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Sat, 14 Mar 2026 17:13:35 +0100 Subject: [PATCH] fixups --- a5/.gitignore | 1 + a5/db.py | 2 +- a5/greetings.db | Bin 0 -> 12288 bytes a5/main.py | 4 ++-- a5/templates/block/measurements.html.j2 | 4 ++-- a5/templates/page/index.html.j2 | 4 ++-- a5/templates/page/measurements.html.j2 | 4 ++-- a5/uv.lock | 8 ++++++++ 8 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 a5/.gitignore create mode 100644 a5/greetings.db create mode 100644 a5/uv.lock diff --git a/a5/.gitignore b/a5/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/a5/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/a5/db.py b/a5/db.py index e73dc2e..fe40095 100644 --- a/a5/db.py +++ b/a5/db.py @@ -84,7 +84,7 @@ CREATE TABLE IF NOT EXISTS measurements cursor.execute( # sql "SELECT timestamp, tvoc, co2 FROM measurements ORDER BY timestamp DESC LIMIT ?, ?", - (page_size, page * page_size), + (page_size, (page - 1) * page_size), ) return cursor.fetchall() diff --git a/a5/greetings.db b/a5/greetings.db new file mode 100644 index 0000000000000000000000000000000000000000..79e5337fc5f87a6cb9a80eee61c83a18093e49b0 GIT binary patch literal 12288 zcmeI#ze@u#6u|N16qQ1`Zk>cI2MQ{vgR50;vWwdNh&96D{it_2v7_$(P5xWr)a0P_ zI(2g>-v@cg<0WwU+?2=racYfvDXUytbtwiyN^z}}5JI}KY0qe>NSUj{pJ)AbQ$%e@dl009ILKmY**5I_I{1Q2Ki78=-8IRF3v literal 0 HcmV?d00001 diff --git a/a5/main.py b/a5/main.py index bd44aa7..e6a2c0c 100644 --- a/a5/main.py +++ b/a5/main.py @@ -28,7 +28,7 @@ def report() -> ResponseReturnValue: return "ok", 200 -@app.route("/stats", methods=["GET"]) +@app.route("/", methods=["GET"]) def stats() -> ResponseReturnValue: """Gets overall statistics as well as few recent measurements""" db = get_db() @@ -45,7 +45,7 @@ def measurements() -> ResponseReturnValue: """Lists measurements""" db = get_db() page_size = 20 - page = request.args["page"] + page = request.args["page"] if "page" in request.args else 1 try: page = int(page) if page < 0: diff --git a/a5/templates/block/measurements.html.j2 b/a5/templates/block/measurements.html.j2 index 280a500..8fce3f7 100644 --- a/a5/templates/block/measurements.html.j2 +++ b/a5/templates/block/measurements.html.j2 @@ -20,10 +20,10 @@ {% endfor %}
- {% if has_next_page %} + {% if page > 1 %} Previous page {% endif %} - {% if page > 0 %} + {% if has_next_page %} Next page {% endif %} diff --git a/a5/templates/page/index.html.j2 b/a5/templates/page/index.html.j2 index cdb6a8d..03becb9 100644 --- a/a5/templates/page/index.html.j2 +++ b/a5/templates/page/index.html.j2 @@ -1,6 +1,6 @@ -{% extends "../base.html.j2" %} +{% extends "base.html.j2" %} {% block title %}Overview{% endblock %} {% block description %}Overview of a CO2 and TVOC sensor data.{% endblock %} {% block content %} - {% include "../block/index.html.j2" %} + {% include "block/index.html.j2" %} {% endblock %} diff --git a/a5/templates/page/measurements.html.j2 b/a5/templates/page/measurements.html.j2 index e7bf6e5..746e9ad 100644 --- a/a5/templates/page/measurements.html.j2 +++ b/a5/templates/page/measurements.html.j2 @@ -1,6 +1,6 @@ -{% extends "../base.html.j2" %} +{% extends "base.html.j2" %} {% block title %}Measurements{% endblock %} {% block description %}List of measurements{% endblock %} {% block content %} - {% include "../block/measurements.html.j2" %} + {% include "block/measurements.html.j2" %} {% endblock %} diff --git a/a5/uv.lock b/a5/uv.lock new file mode 100644 index 0000000..cf845d2 --- /dev/null +++ b/a5/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 3 +requires-python = ">=3.13" + +[[package]] +name = "a5" +version = "0.1.0" +source = { virtual = "." }