Deleting comments works now
This commit is contained in:
parent
6a1689a239
commit
26c273dc53
2 changed files with 57 additions and 5 deletions
|
@ -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 + '<input type="hidden" id="request" name="request" value=\"'+request+'">'
|
||||
|
||||
html = html + '<br><center><sup><b> Pending Approval </b></sup></center><br>'
|
||||
|
||||
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 = '<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")
|
||||
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 + '</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 + '</a>'
|
||||
|
||||
|
@ -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"]):
|
||||
|
@ -1061,4 +1068,46 @@ def DoComment(server):
|
|||
except:
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue