From 26c273dc537a2122c2ca8eef4035e4f033a3a2d0 Mon Sep 17 00:00:00 2001 From: Victorious Children Studios Date: Sun, 24 Nov 2024 02:53:16 +0200 Subject: [PATCH] Deleting comments works now --- modules/Render.py | 59 +++++++++++++++++++++++++++++++++++++++++++---- modules/Run.py | 3 +++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/modules/Render.py b/modules/Render.py index 5059fdc..83112d7 100644 --- a/modules/Render.py +++ b/modules/Render.py @@ -5,6 +5,7 @@ import os import json import random import hashlib +import urllib.parse from datetime import datetime @@ -847,7 +848,7 @@ def CommentEditInput(server, comment, url, n=0, user=None, request=None): """ if request: html = html + '' - + html = html + '
  Pending Approval  

' account = comment.get("username", "") if account in accounts(): @@ -889,7 +890,10 @@ def CommentEditInput(server, comment, url, n=0, user=None, request=None): def Comment(comment, url, n=0, user=None, request=False): - html = '
' + if not request: + html = '
' + else: + html = '
' account = comment.get("username", "Anonymous User") html = html + User(account) + '
\n' @@ -915,7 +919,7 @@ def Comment(comment, url, n=0, user=None, request=False): html = html + ' Edit' html = html + '' - html = html + '' + html = html + '' html = html + ' Delete' html = html + '' @@ -1016,6 +1020,8 @@ def DoComment(server): "text":text } + placeRedirect = "#comment_" + if warn: comment["warning"] = warn @@ -1039,6 +1045,7 @@ def DoComment(server): if nick in Accounts or not nick: nick = "Anonymous Guest" comment["username"] = nick + placeRedirect = "#request_" place = "requests" @@ -1048,7 +1055,7 @@ def DoComment(server): if not number: article["comments"][place].append(comment) - number = len(article["comments"]["comments"])-1 + number = len(article["comments"][place])-1 else: number = int(number) if moderates(user.get("username"), article["comments"]["comments"][number]["username"]): @@ -1060,5 +1067,47 @@ def DoComment(server): json.dump(article, save, indent=4) except: pass + + if not number: + placeRedirect = "#comments" + number = "" - Redirect(server, url+"#comment_"+str(number)) + Redirect(server, url+placeRedirect+str(number)) + +def DeleteComment(server): + + user = validate(server.cookie) + + url = server.parsed.get("url", ["/"])[0] + if not url.startswith("/"): url = "/" + url + + number = int(server.parsed.get("number", ["0"])[0]) + + metadata = Set.Folder()+"/tabs"+url+"/metadata.json" + + try: + with open(metadata) as o: + article = json.load(o) + except: + Redirect(server, "/") + return + + comment = article["comments"]["comments"][number] + + if moderates(user.get("username", ""), comment.get("username", "")): + + del article["comments"]["comments"][number] + + + try: + with open(metadata, "w") as save: + json.dump(article, save, indent=4) + except: + pass + + if number: + redirect = "#comment_"+str(number-1) + else: + redirect = "#comments" + + Redirect(server, url+redirect) diff --git a/modules/Run.py b/modules/Run.py index 3269a68..5eb3151 100644 --- a/modules/Run.py +++ b/modules/Run.py @@ -77,6 +77,9 @@ class handler(BaseHTTPRequestHandler): elif self.path[1:].startswith("comment"): Render.DoComment(self) + elif self.path[1:].startswith("delete_comment"): + Render.DeleteComment(self) + elif self.path[1:].startswith("do_login"): Render.Login(self)