def decorated_function(self, comment_id, *args, **kwargs): user_name = self.user.name comment = Comment.by_id(int(comment_id)) if user_name == comment.author.name: return f(self, comment_id, *args, **kwargs) else: self.redirect('/blog')
def decorated_function(self, *args, **kwargs): comment_id = args[1] comment = Comment.by_id(comment_id) if comment: kwargs['comment'] = comment return f(self, *args, **kwargs) else: self.error(404) return
def post(self, comment_id): if self.user: username = self.user.name commentid = int(comment_id) comment = Comment.by_id(commentid) if comment.created_by == username: comment.delete() self.redirect('/comment') else: error = "You can only delete comments created by you" self.render("delete-comment.html", comment=comment, error=error) else: self.redirect('/login')
def get(self, comment_id): if self.user: commentid = int(comment_id) comment = Comment.by_id(commentid) if not comment: self.error(404) return if self.user.name == comment.created_by: self.render_front(comment.title, comment.content) else: error = "You can only edit comments you created" self.render_front(error=error) else: self.redirect('/login')
def post(self, comment_id): content = self.request.get('content') commentid = int(comment_id) comment = Comment.by_id(commentid) if self.user.name == comment.created_by: if content: comment.title = comment.title comment.post_id = comment.post_id comment.content = content comment.created_by = self.user.name comment.put() self.redirect('/comment') else: error = "We need some content for the comment" self.render_front(title, content, error) else: error = "You can only edit comments you created." self.render_front(error)
def post(self): logging.debug("Inside Edit Comment handler Post method") data = json.loads(self.request.body) commentId = data['commentId'] editcommenttext = data['comment'] if self.isvalid_login(): user_id = self.getCookieValue("user_id") user = User.get_by_id(int(user_id)) comment = Comment.by_id(int(commentId)) if comment and comment.user and comment.user.username == user.username: comment.commenttext = editcommenttext comment.put() self.response.out.write(json.dumps(({'success': 'true'}))) else: self.response.out.write( json.dumps(({ 'errorMsg': "You cannot Edit This Comment" }))) else: logging.debug("Redirect to login") self.response.out.write( json.dumps(({ 'errorMsg': 'Login to Edit Comment' })))
def post(self): logging.debug("Inside Delete Comment handler Post method") data = json.loads(self.request.body) commentId = data['commentId'] if self.isvalid_login(): # TODO: Refactor to getUser Method Later to get user object user_id = self.getCookieValue("user_id") user = User.get_by_id(int(user_id)) comment = Comment.by_id(int(commentId)) # TODO: Refactor to getBlogbyId method to getBlogData Object if comment and comment.user and comment.user.username == user.username: comment.delete() self.response.out.write(json.dumps(({'success': 'true'}))) else: self.response.out.write( json.dumps(({ 'errorMsg': "You cannot Delete This Comment" }))) else: logging.debug("Redirect to login") self.response.out.write( json.dumps(({ 'errorMsg': 'Login to Delete Comment' })))
def post(self, comment_id): comment = Comment.by_id(int(comment_id)) comment.delete() time.sleep(0.1) self.redirect('/blog')
def get(self, comment_id): comment = Comment.by_id(int(comment_id)) self.render('comment-delete.html', comment=comment)
def post(self, comment_id): comment = Comment.by_id(int(comment_id)) comment.content = self.request.get('content') comment.put() time.sleep(0.1) self.redirect('/blog')