From e9dc5e50560ea44bb5c9b3b58b33413729bd71ad Mon Sep 17 00:00:00 2001 From: Alfie King Date: Tue, 22 Apr 2025 15:37:22 +0100 Subject: [PATCH] update --- readme.md | 2 +- src/database.py | 39 +++++++++++++++++++-- src/html/base.html | 6 +--- src/html/board.html | 4 ++- src/html/index.html | 6 ++-- src/html/post.html | 14 +++++--- src/html/posts.html | 4 ++- src/html/user.html | 11 +++++- src/main.py | 82 +++++++++++++++++++++++++++++++-------------- 9 files changed, 126 insertions(+), 42 deletions(-) diff --git a/readme.md b/readme.md index 625dbe2..6ce3e28 100644 --- a/readme.md +++ b/readme.md @@ -4,4 +4,4 @@ prismic is a simple messageboard made in python ## Planned features - [ ] user board creation - [ ] custom profiles -- [ ] moderation tools \ No newline at end of file +- [x] moderation tools \ No newline at end of file diff --git a/src/database.py b/src/database.py index 715c00d..a203755 100644 --- a/src/database.py +++ b/src/database.py @@ -405,6 +405,28 @@ class Database: logger.info("No reference post.") data['reference'] = None + # get post references + logger.info(f"Getting post references for post {post[0]}...") + self.cursor.execute(''' + SELECT * FROM posts WHERE refence = ? + ''', (post[0],)) + references = self.cursor.fetchall() + + if references: + data['replies'] = [] + for reference in references: + reference_data = { + 'id': reference[0], + 'content': reference[3], + 'short_content': reference[3][:20] + '...' if len(reference[3]) > 20 else reference[3], + 'created_at': reference[4] + } + data['replies'].append(reference_data) + logger.info(f"Post references found for post {post[0]}.") + else: + logger.warning(f"No post references found for post {post[0]}.") + data['replies'] = [] + logger.info(f"Post converted to dictionary.") return data @@ -540,7 +562,20 @@ class Database: if boards: logger.info(f"Boards found.") # Convert boards to dictionary - boards = [{"id": board[0], "name": board[1]} for board in boards].sort(key=lambda x: x['name']) + boards = [{"id": board[0], "name": board[1]} for board in boards] + boards.sort(key=lambda x: x['name']) return boards logger.warning(f"No boards found.") - return None \ No newline at end of file + return None + + def delete_post(self, post_id): + logger.info(f"Deleting post {post_id}...") + + # Delete post + self.cursor.execute(''' + DELETE FROM posts WHERE id = ? + ''', (post_id,)) + + self.connection.commit() + logger.info(f"Post {post_id} deleted.") + return True \ No newline at end of file diff --git a/src/html/base.html b/src/html/base.html index 679fc3c..98bf18c 100644 --- a/src/html/base.html +++ b/src/html/base.html @@ -33,11 +33,7 @@ {% block content %}{% endblock %} \ No newline at end of file diff --git a/src/html/board.html b/src/html/board.html index d39d345..10d04a3 100644 --- a/src/html/board.html +++ b/src/html/board.html @@ -17,10 +17,12 @@

{{ post.short_content }}

View Post {% if post.replies|length > 0 %} - | ({{ post.replies|length }} replies) + ({{ post.replies|length }} replies) {% endif %} {% if session.name == "SYSTEM" %} | Delete + {% elif session.name == post.user.name %} + | Delete {% endif %}
diff --git a/src/html/index.html b/src/html/index.html index e9e3335..087d3e7 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -11,15 +11,17 @@

From {{ post.user.name }} in /{{ post.board.name }}/

posted at {{ post.created_at }}
{% if post.reference %} -
ref post: {{ post.reference.short_content }}
+
ref post: {{ post.reference.short_content if post.reference.id is not none else '[NOT FOUND]' }}
{% endif %}

{{ post.short_content }}

View Post {% if post.replies|length > 0 %} - | ({{ post.replies|length }} replies) + ({{ post.replies|length }} replies) {% endif %} {% if session.name == "SYSTEM" %} | Delete + {% elif session.name == post.user.name %} + | Delete {% endif %}
diff --git a/src/html/post.html b/src/html/post.html index 21559ca..3ff5ef6 100644 --- a/src/html/post.html +++ b/src/html/post.html @@ -7,8 +7,15 @@
ref post: {{ post.reference.content }}
{% endif %}

{{ post.content }}

+ {% if session.name == "SYSTEM" %} +
Delete
+ {% elif session.name == post.user.name %} +
Delete
+ {% endif %}
+

Replies:

+