about summary refs log tree commit diff
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
parent1de5e27008b309a352f5c967dce253d956e40421 (diff)
No comments SQL select count
-rw-r--r--blog.node5.net/static/article.css2
-rw-r--r--blog.node5.net/templates/base.html4
-rw-r--r--src/blog_node5_net.py9
-rw-r--r--src/db_handler.py2
4 files changed, 11 insertions, 6 deletions
diff --git a/blog.node5.net/static/article.css b/blog.node5.net/static/article.css
index 8704d5f..00cbdbc 100644
--- a/blog.node5.net/static/article.css
+++ b/blog.node5.net/static/article.css
@@ -8,7 +8,7 @@ img {
   background: unset !important;
 }
 
-pre {
+pre:not(#comments) {
   overflow: auto;
   width: 100%;
   display: inline-block;
diff --git a/blog.node5.net/templates/base.html b/blog.node5.net/templates/base.html
index 13012ea..a872fb6 100644
--- a/blog.node5.net/templates/base.html
+++ b/blog.node5.net/templates/base.html
@@ -48,9 +48,9 @@
         <input type="submit" value="Post comment" /> <small>(Will await approval before becoming public)</small>
     </form>
     <br>
-    {% if comments and comments|length > 0 %}<pre><code>
+    {% if comments and comments|length > 0 %}<pre id="comments">
 {{ comments }}
-    </code></pre>{% endif %}
+    </pre>{% else %}*No comments*{% endif %}
 
 </div>
 <div id="footer">
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