diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/blog_node5_net.py | 9 | ||||
| -rw-r--r-- | src/db_handler.py | 2 |
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 |
