From 28109eb5866d84fc8b8ac13082c54d05146bb348 Mon Sep 17 00:00:00 2001 From: guimoz Date: Wed, 12 Apr 2017 21:06:59 +0200 Subject: [PATCH 1/3] Adds a counter of indexed torrents on the homepage --- magneticow/magneticow/magneticow.py | 12 +++++++++++- magneticow/magneticow/static/styles/homepage.css | 9 ++++++++- magneticow/magneticow/templates/homepage.html | 6 +++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/magneticow/magneticow/magneticow.py b/magneticow/magneticow/magneticow.py index c6d43fc..cccc3cd 100644 --- a/magneticow/magneticow/magneticow.py +++ b/magneticow/magneticow/magneticow.py @@ -67,7 +67,17 @@ def requires_auth(f): @app.route("/") @requires_auth def home_page(): - return flask.render_template("homepage.html") + magneticod_db = get_magneticod_db() + context = {} + + with magneticod_db: + cur = magneticod_db.execute( + "SELECT" + " count(id) " + "FROM torrents ;") + context["counter"] = cur.fetchall() + + return flask.render_template("homepage.html",**context) @app.route("/torrents/") diff --git a/magneticow/magneticow/static/styles/homepage.css b/magneticow/magneticow/static/styles/homepage.css index d6659e0..8f8fb82 100644 --- a/magneticow/magneticow/static/styles/homepage.css +++ b/magneticow/magneticow/static/styles/homepage.css @@ -20,4 +20,11 @@ main form input { main > div { margin-right: 0.5em; -} \ No newline at end of file +} + +footer { + margin-top: 0.833em; + + display: flex; + justify-content: space-between; +} diff --git a/magneticow/magneticow/templates/homepage.html b/magneticow/magneticow/templates/homepage.html index 3e0eed7..6ad415e 100644 --- a/magneticow/magneticow/templates/homepage.html +++ b/magneticow/magneticow/templates/homepage.html @@ -15,5 +15,9 @@ + + - \ No newline at end of file + From d3ff2419aaa5b31455af9876d921963fead40655 Mon Sep 17 00:00:00 2001 From: guimoz Date: Thu, 13 Apr 2017 19:20:34 +0200 Subject: [PATCH 2/3] Refactoring of the counter code --- magneticow/magneticow/magneticow.py | 9 +++------ magneticow/magneticow/templates/homepage.html | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/magneticow/magneticow/magneticow.py b/magneticow/magneticow/magneticow.py index cccc3cd..169650c 100644 --- a/magneticow/magneticow/magneticow.py +++ b/magneticow/magneticow/magneticow.py @@ -71,13 +71,10 @@ def home_page(): context = {} with magneticod_db: - cur = magneticod_db.execute( - "SELECT" - " count(id) " - "FROM torrents ;") - context["counter"] = cur.fetchall() + cur = magneticod_db.execute("SELECT count() FROM torrents ;") + n_torrents = cur.fetchone()[0] - return flask.render_template("homepage.html",**context) + return flask.render_template("homepage.html",n_torrents=n_torrents) @app.route("/torrents/") diff --git a/magneticow/magneticow/templates/homepage.html b/magneticow/magneticow/templates/homepage.html index 6ad415e..475a1f0 100644 --- a/magneticow/magneticow/templates/homepage.html +++ b/magneticow/magneticow/templates/homepage.html @@ -17,7 +17,7 @@
-
Now with {{counter[0][0]}} torrents available !
+ Now with {{n_torrents}} torrents available !
From 059330c18837d1d4212bd29221fb1d235a3d350a Mon Sep 17 00:00:00 2001 From: g_goessel Date: Thu, 13 Apr 2017 22:07:18 +0200 Subject: [PATCH 3/3] Remove unused variable and resolve styling issues --- magneticow/magneticow/magneticow.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/magneticow/magneticow/magneticow.py b/magneticow/magneticow/magneticow.py index 169650c..9a25487 100644 --- a/magneticow/magneticow/magneticow.py +++ b/magneticow/magneticow/magneticow.py @@ -68,13 +68,12 @@ def requires_auth(f): @requires_auth def home_page(): magneticod_db = get_magneticod_db() - context = {} with magneticod_db: cur = magneticod_db.execute("SELECT count() FROM torrents ;") n_torrents = cur.fetchone()[0] - return flask.render_template("homepage.html",n_torrents=n_torrents) + return flask.render_template("homepage.html", n_torrents=n_torrents) @app.route("/torrents/")