diff options
| author | user@node5.net <user@node5.net> | 2025-07-19 15:18:48 +0200 |
|---|---|---|
| committer | user@node5.net <user@node5.net> | 2025-07-19 15:18:48 +0200 |
| commit | 1de5e27008b309a352f5c967dce253d956e40421 (patch) | |
| tree | 0123534dad29b3c56d3b6d88c55f8cdc4d4b7698 | |
| parent | ddcc24426fbc870d1017d1cf2cf7636936845d18 (diff) | |
Comment section ascii table
| -rw-r--r-- | blog.node5.net/templates/base.html | 29 | ||||
| -rw-r--r-- | requirements.txt | 3 | ||||
| -rw-r--r-- | src/blog_node5_net.py | 7 | ||||
| -rw-r--r-- | src/db_handler.py | 6 |
4 files changed, 13 insertions, 32 deletions
diff --git a/blog.node5.net/templates/base.html b/blog.node5.net/templates/base.html index 2fa0b44..13012ea 100644 --- a/blog.node5.net/templates/base.html +++ b/blog.node5.net/templates/base.html @@ -48,32 +48,9 @@ <input type="submit" value="Post comment" /> <small>(Will await approval before becoming public)</small> </form> <br> - {% if comments and comments|length > 0 %} - <h3> - ID <span class="dark-grey">|</span> - Nickname <span class="dark-grey">|</span> - <span title="URL of the website the commenter claims to be from">Visitor website URL</span><span class="dark-grey">|</span> - Means of contact <span class="dark-grey">|</span> - Created at - </h3> - - {% for comment in comments %} - <ul class="entries"> - <li> - <span class="grey"> - {{ comment.id }} <span class="dark-grey">|</span> - {% if comment.nickname %}<span {% if comment.nickname == 'user@node5.net' %}class="main-color glow"{% endif %} title="Nickname">{{ comment.nickname }}</span> <span class="dark-grey">|</span>{% endif %} - {% if comment.visitor_url %}<a title="Visitor url" href="{{comment.visitor_url}}">{{ comment.visitor_url }}</a> <span class="dark-grey">|</span>{% endif %} - {% if comment.contact %}<span title="Means of contact">{{ comment.contact }}</span> <span class="dark-grey">|</span>{% endif %} - {{ comment.created_at }} - </span><br> - {{ comment.comment }} - <br><br> - </li> - </ul> - - {% endfor %} - {% endif %} + {% if comments and comments|length > 0 %}<pre><code> +{{ comments }} + </code></pre>{% endif %} </div> <div id="footer"> diff --git a/requirements.txt b/requirements.txt index a73988b..76671d5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ PyYAML~=6.0 Markdown~=3.5 psycopg~=3.1 python-telegram-bot~=20.8 -pygments~=2.17 # Use a newer version than in debain packages for python code snippet highlighting \ No newline at end of file +pygments~=2.17 # Use a newer version than in debain packages for python code snippet highlighting +tabulate~=0.9 # Format lists as ascii tables for comments 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, |
