def get_post(self, post_id): '''Retrieves post id from url. If post id matches post in Blog database, returns post, if not, returns None''' if post_id: post = Blog.get_by_id(int(post_id)) if post: return post
def get(self, post_id, comment_id): post = Blog.get_by_id(int(post_id), parent=blog_key()) comment = Comment.get_by_id(int(comment_id)) username = self.user.name if comment and self.user: if comment.user.name == self.user.name: self.render("editcomment.html", comment_text=comment.text, username=username) else: error = "To edit a comment you must be the author'" self.render("editcomment.html", edit_error=error, username=username) else: error = "This comment no longer exists" self.render("editcomment.html", edit_error=error, username=username)
def get(self, post_id, comment_id): # get the blog and comment from blog id and comment id post = Blog.get_by_id(int(post_id), parent=blog_key()) comment = Comment.get_by_id(int(comment_id)) # check if there is a comment associated with that id if comment: # check if this user is the author of this comment if comment.user.name == self.user.name: # take the user to the edit comment page and load the content # of the comment self.render("editcomment.html", comment_text=comment.text) # otherwise if this user is the author of this comment throw and # error else: error = "You cannot edit other users' comments'" self.render("editcomment.html", edit_error=error) # otherwise if there is no comment associated with that ID throw an # error else: error = "This comment no longer exists" self.render("editcomment.html", edit_error=error)