aboutsummaryrefslogtreecommitdiff
path: root/cgi/post.py
diff options
context:
space:
mode:
Diffstat (limited to 'cgi/post.py')
-rw-r--r--cgi/post.py71
1 files changed, 63 insertions, 8 deletions
diff --git a/cgi/post.py b/cgi/post.py
index b7efef1..c53e8a1 100644
--- a/cgi/post.py
+++ b/cgi/post.py
@@ -56,7 +56,7 @@ class Post(object):
return self.post
def insert(self):
- logging.info("Insertando Post")
+ logging.info("Insertando post")
post_keys = []
post_templates = []
post_values = []
@@ -694,7 +694,63 @@ def regenerateBoard(everything=False):
for post in op_posts:
regenerateThreadPage(post["id"])
-def deletePost(postid, password, deltype=0, imageonly=False, quick=False):
+def deletePosts(boarddir, postid, imageonly, password):
+ board = setBoard(boarddir)
+
+ # validate posts
+ if not postid:
+ raise UserError("Selecciona uno o más mensajes a eliminar.")
+
+ to_delete = []
+ if isinstance(postid, list):
+ to_delete = [int(n.value) for n in postid]
+ else:
+ to_delete = [int(postid)]
+
+ if not password:
+ raise UserError(_("Please enter a password."))
+
+ # delete posts
+ if board['board_type'] == 1 and len(to_delete) == 1:
+ # only delete a single post on textboards
+ # check if it's the last post and delete permanently if so
+ deltype = 0
+
+ post = FetchOne("SELECT id, timestamp, parentid FROM posts WHERE boardid = %s AND id = %s LIMIT 1", (board["id"], to_delete[0]) )
+ if not post:
+ raise UserError(_("There isn't a post with this ID. It was probably deleted."))
+
+ if post['parentid']:
+ op = get_parent_post(post['parentid'], board['id'])
+ if op['last'] != post['timestamp']:
+ deltype = 1
+
+ deletePost(to_delete[0], password, deltype, imageonly)
+ regenerateHome()
+ else:
+ # delete all checked posts on imageboards
+ deleted = 0
+ errors = 0
+ msgs = []
+
+ for pid in to_delete:
+ try:
+ deletePost(pid, password, board['recyclebin'], imageonly)
+ deleted += 1
+ msgs.append('No.%d: Eliminado' % pid)
+ except UserError as message:
+ errors += 1
+ msgs.append('No.%d: %s' % (pid, message))
+
+ # regenerate home
+ if deleted:
+ regenerateHome()
+
+ # show errors, if any
+ if errors:
+ raise UserError('No se pudieron eliminar todos los posts.<br />' + '<br />'.join(msgs))
+
+def deletePost(postid, password, deltype=0, imageonly=False):
"""
Remove post from database and unlink file (if present), along with all replies
if supplied post is a thread
@@ -705,7 +761,7 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False):
postid = int(postid)
# get post
- post = FetchOne("SELECT `id`, `timestamp`, `parentid`, `file`, `thumb`, `password`, `length` FROM `posts` WHERE `boardid` = %s AND `id` = %s LIMIT 1", (board["id"], postid))
+ post = FetchOne("SELECT `id`, `timestamp`, `parentid`, `file`, `thumb`, `password`, `length` FROM `posts` WHERE `boardid` = %s AND `id` = %s LIMIT 1", (board["id"], postid) )
# abort if the post doesn't exist
if not post:
@@ -713,13 +769,12 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False):
if password:
if password != post['password']:
- raise UserError("No tienes permiso para eliminar este mensaje.")
+ raise UserError("No tienes permiso para eliminar este post.")
elif not post["parentid"] and post["length"] >= Settings.DELETE_FORBID_LENGTH:
raise UserError("No puedes eliminar un hilo con tantas respuestas.")
elif (int(time.time()) - post["timestamp"]) > 86400:
raise UserError("No puedes eliminar un post tan viejo.")
- # just update the DB if deleting only the image, otherwise delete whole post
if imageonly:
if post["file"]:
deleteFile(post)
@@ -729,14 +784,14 @@ def deletePost(postid, password, deltype=0, imageonly=False, quick=False):
if not post["parentid"]:
deleteReplies(post)
- logging.info("Deleting post %d - parentid: %d" % (post["id"], post["parentid"]))
+ logging.debug("Deleting post %d - parentid: %d" % (post["id"], post["parentid"]))
if deltype != 0 and post["parentid"]:
# Soft delete (recycle bin)
- logging.info("Soft delete")
+ logging.debug("Soft delete")
UpdateDb("UPDATE `posts` SET `IS_DELETED` = %s WHERE `boardid` = %s AND `id` = %s LIMIT 1", (deltype, board["id"], post["id"]))
else:
# Hard delete
- logging.info("Hard delete")
+ logging.debug("Hard delete")
if post["file"]:
deleteFile(post)