about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authoruser@node5.net <user@node5.net>2025-07-19 15:18:48 +0200
committeruser@node5.net <user@node5.net>2025-07-19 15:18:48 +0200
commit1de5e27008b309a352f5c967dce253d956e40421 (patch)
tree0123534dad29b3c56d3b6d88c55f8cdc4d4b7698 /src
parentddcc24426fbc870d1017d1cf2cf7636936845d18 (diff)
Comment section ascii table
Diffstat (limited to 'src')
-rw-r--r--src/blog_node5_net.py7
-rw-r--r--src/db_handler.py6
2 files changed, 8 insertions, 5 deletions
diff --git a/src/blog_node5_net.py b/src/blog_node5_net.py
index d39fe7f..d22608f 100644
--- a/src/blog_node5_net.py
+++ b/src/blog_node5_net.py
@@ -10,6 +10,7 @@ import flask
 import markdown
 import markupsafe
 import yaml
+import tabulate
 
 import article
 import db_handler
@@ -90,11 +91,13 @@ try:
 except FileNotFoundError as ex:
     logger.warning("Telegram config - Not found, running without")
 
-
 @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")
+
     args = {
-        'comments': db.get_comments(strip_trailing_slash(flask.request.path)) if db else None,
+        'comments': comments_formatted,
         'title': config['site_root_folder_path'],
         'motd': random.choice(motd_list)
     }
diff --git a/src/db_handler.py b/src/db_handler.py
index 673431d..c52d667 100644
--- a/src/db_handler.py
+++ b/src/db_handler.py
@@ -17,12 +17,12 @@ class DBHandler:
             cur = con.cursor()
             cur.execute(
                 '''
-                SELECT id, comment, page_url, visitor_url, nickname,
-                (CASE WHEN show_contact THEN contact ELSE NULL END) as contact, created_at
+                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))
             comments = cur.fetchall()
-            return comments
+            headers = list(map(lambda attr : attr[0], cur.description))
+            return comments, headers
 
 
     def post_comment(self, comment: str, page_url: str, visitor_url: str=None, nickname: str=None, contact: str=None,