Deleting comments works now

This commit is contained in:
Victorious Children Studios 2024-11-24 02:53:16 +02:00
parent 6a1689a239
commit 26c273dc53
2 changed files with 57 additions and 5 deletions

View file

@ -5,6 +5,7 @@ import os
import json import json
import random import random
import hashlib import hashlib
import urllib.parse
from datetime import datetime from datetime import datetime
@ -847,7 +848,7 @@ def CommentEditInput(server, comment, url, n=0, user=None, request=None):
""" """
if request: if request:
html = html + '<input type="hidden" id="request" name="request" value=\"'+request+'">' html = html + '<input type="hidden" id="request" name="request" value=\"'+request+'">'
html = html + '<br><center><sup><b> &nbsp; Pending Approval &nbsp; </b></sup></center><br>'
account = comment.get("username", "") account = comment.get("username", "")
if account in accounts(): 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): def Comment(comment, url, n=0, user=None, request=False):
html = '<div class="dark_box" id="comment_'+str(n)+'">' if not request:
html = '<div class="dark_box" id="comment_'+str(n)+'">'
else:
html = '<div class="dark_box" id="request_'+str(n)+'">'
account = comment.get("username", "Anonymous User") account = comment.get("username", "Anonymous User")
html = html + User(account) + '<br>\n' html = html + User(account) + '<br>\n'
@ -915,7 +919,7 @@ def Comment(comment, url, n=0, user=None, request=False):
html = html + '<img src="/icon/edit" style="vertical-align: middle"> Edit' html = html + '<img src="/icon/edit" style="vertical-align: middle"> Edit'
html = html + '</a>' html = html + '</a>'
html = html + '<a class="button" href="/">' html = html + '<a class="button" href="/delete_comment?url='+urllib.parse.quote_plus(url)+'&number='+str(n)+'">'
html = html + '<img src="/icon/cancel" style="vertical-align: middle"> Delete' html = html + '<img src="/icon/cancel" style="vertical-align: middle"> Delete'
html = html + '</a>' html = html + '</a>'
@ -1016,6 +1020,8 @@ def DoComment(server):
"text":text "text":text
} }
placeRedirect = "#comment_"
if warn: if warn:
comment["warning"] = warn comment["warning"] = warn
@ -1039,6 +1045,7 @@ def DoComment(server):
if nick in Accounts or not nick: if nick in Accounts or not nick:
nick = "Anonymous Guest" nick = "Anonymous Guest"
comment["username"] = nick comment["username"] = nick
placeRedirect = "#request_"
place = "requests" place = "requests"
@ -1048,7 +1055,7 @@ def DoComment(server):
if not number: if not number:
article["comments"][place].append(comment) article["comments"][place].append(comment)
number = len(article["comments"]["comments"])-1 number = len(article["comments"][place])-1
else: else:
number = int(number) number = int(number)
if moderates(user.get("username"), article["comments"]["comments"][number]["username"]): if moderates(user.get("username"), article["comments"]["comments"][number]["username"]):
@ -1061,4 +1068,46 @@ def DoComment(server):
except: except:
pass pass
Redirect(server, url+"#comment_"+str(number)) if not number:
placeRedirect = "#comments"
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)

View file

@ -77,6 +77,9 @@ class handler(BaseHTTPRequestHandler):
elif self.path[1:].startswith("comment"): elif self.path[1:].startswith("comment"):
Render.DoComment(self) Render.DoComment(self)
elif self.path[1:].startswith("delete_comment"):
Render.DeleteComment(self)
elif self.path[1:].startswith("do_login"): elif self.path[1:].startswith("do_login"):
Render.Login(self) Render.Login(self)