def process(self, db, user, comment_id): comment = Comment.fromId(db, comment_id, user) if user != comment.user: raise OperationError( "can't delete comment written by another user") if comment.state != "draft": raise OperationError( "can't delete comment that has been submitted") cursor = db.cursor() cursor.execute( """UPDATE comments SET state='deleted' WHERE id=%s""", (comment.id, )) if comment.chain.state == "draft": # If the comment chain was a draft, then delete it as well. cursor.execute( """UPDATE commentchains SET state='empty' WHERE id=%s""", (comment.chain.id, )) db.commit() return OperationResult( draft_status=comment.chain.review.getDraftStatus(db, user))
def process(self, db, user, comment_id, new_text): comment = Comment.fromId(db, comment_id, user) if user != comment.user: raise OperationError, "can't edit comment written by another user" if comment.state != "draft": raise OperationError, "can't edit comment that has been submitted" if not new_text.strip(): raise OperationError, "empty comment" cursor = db.cursor() cursor.execute("""UPDATE comments SET comment=%s, time=now() WHERE id=%s""", (new_text, comment.id)) db.commit() return OperationResult(draft_status=comment.chain.review.getDraftStatus(db, user))
def process(self, db, user, comment_id, new_text): comment = Comment.fromId(db, comment_id, user) if user != comment.user: raise OperationError("can't edit comment written by another user") if comment.state != "draft": raise OperationError("can't edit comment that has been submitted") if not new_text.strip(): raise OperationError("empty comment") cursor = db.cursor() cursor.execute("""UPDATE comments SET comment=%s, time=now() WHERE id=%s""", (new_text, comment.id)) db.commit() return OperationResult(draft_status=comment.chain.review.getDraftStatus(db, user))
def process(self, db, user, comment_id): comment = Comment.fromId(db, comment_id, user) if user != comment.user: raise OperationError, "can't delete comment written by another user" if comment.state != "draft": raise OperationError, "can't delete comment that has been submitted" cursor = db.cursor() cursor.execute("""UPDATE comments SET state='deleted' WHERE id=%s""", (comment.id,)) if comment.chain.state == "draft": # If the comment chain was a draft, then delete it as well. cursor.execute("""UPDATE commentchains SET state='empty' WHERE id=%s""", (comment.chain.id,)) db.commit() return OperationResult(draft_status=comment.chain.review.getDraftStatus(db, user))