aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoruser@node5.net <user@node5.net>2025-07-19 15:58:56 +0200
committeruser@node5.net <user@node5.net>2025-07-19 15:58:56 +0200
commit800da4c7e251040ed2e6f8533b8dc24b6b83eaef (patch)
tree6d3e050766ebd4616f38e0a4d6ceaa1c8c98c7b1 /src
parent1de5e27008b309a352f5c967dce253d956e40421 (diff)
No comments SQL select count
Diffstat (limited to 'src')
-rw-r--r--src/blog_node5_net.py9
-rw-r--r--src/db_handler.py2
2 files changed, 8 insertions, 3 deletions
diff --git a/src/blog_node5_net.py b/src/blog_node5_net.py
index d22608f..5761fc1 100644
--- a/src/blog_node5_net.py
+++ b/src/blog_node5_net.py
@@ -93,8 +93,13 @@ except FileNotFoundError as ex:
@app.context_processor # Always inject site title to all render_templates
def inject_common():
- comments, comment_headers = db.get_comments(strip_trailing_slash(flask.request.path))
- comments_formatted = tabulate.tabulate(comments, comment_headers, tablefmt="psql")
+ url = strip_trailing_slash(flask.request.path)
+ comments, comment_headers = db.get_comments(url)
+ if comments:
+ comments_formatted = tabulate.tabulate(comments, comment_headers, tablefmt="psql")
+ else:
+ comments_formatted = f"""sqlite> SELECT COUNT(comment) FROM comment WHERE page_url = '{url}';
+0"""
args = {
'comments': comments_formatted,
diff --git a/src/db_handler.py b/src/db_handler.py
index c52d667..c0dba76 100644
--- a/src/db_handler.py
+++ b/src/db_handler.py
@@ -19,7 +19,7 @@ class DBHandler:
'''
SELECT id, nickname, comment, page_url, visitor_url, (CASE WHEN show_contact THEN contact ELSE NULL END) as contact, created_at
FROM comment WHERE approved AND public AND page_url = ? ORDER BY created_at DESC;
- ''', (url))
+ ''', (url,))
comments = cur.fetchall()
headers = list(map(lambda attr : attr[0], cur.description))
return comments, headers