def get(self, post_id): blog = Blog.by_id(int(post_id)) if blog: # only the blog author can edit it if blog.user_id == self.user_id: self.render('editblog.html', blog=blog) else: error = 'Only the Blog owner can edit this blog post.' comments = Comment.by_blog(post_id) self.render('blogpost.html', blog=blog, error=error, user_id=self.user_id, comments=comments) else: # Invalid blog - display error page self.render('permissionerror.html')
def post(self, post_id): blog = Blog.by_id(int(post_id)) if blog: # Only the blog author can delete the blog if blog.user_id == self.user_id: db.delete(blog.key()) # Adding a sleep of 1 second here # Observation - the database takes a while to reflect the # change time.sleep(1) self.redirect('/blog') else: error = 'Only the Blog owner can delete this blog post.' comments = Comment.by_blog(post_id) self.render('blogpost.html', blog=blog, error=error, user_id=self.user_id, comments=comments) else: self.render('permissionerror.html')
def get(self, post_id): comment = Comment.by_id(int(post_id)) if comment: # Only the commentor can edit the comment. if comment.user_id == self.user_id: self.render('editcomment.html', comment=comment) else: comment_error = """Only the Commenter can edit this comment.""" blog_id = comment.blog_id blog = Blog.by_id(blog_id) comments = Comment.by_blog(blog_id) self.render('blogpost.html', blog=blog, user_id=self.user_id, comments=comments, comment_error_id=int(post_id), comment_error=comment_error) else: self.render('permissionerror.html', error="Comment doesn't exist")
def post(self, post_id): user_id = self.user_id blog = Blog.by_id(int(post_id)) if blog: # Blog author can't like their own posts. if blog.user_id == user_id: error = "You can't like your own posts." comments = Comment.by_blog(post_id) self.render('blogpost.html', blog=blog, error=error, user_id=user_id, comments=comments) else: if user_id in blog.liked: blog.liked.remove(user_id) blog.put() else: blog.liked.append(user_id) blog.put() self.redirect('/blog/%d' % int(post_id)) else: self.render('permissionerror.html')
def post(self, post_id): title = self.request.get('subject') text = self.request.get('content') if title and text: blog = Blog.by_id(int(post_id)) if blog: # only the blog author can edit it if blog.user_id == self.user_id: blog.title = title blog.body = text blog.put() self.redirect("/blog/%d" % int(post_id)) else: error = "You don't have permission to edit this blog." self.render('permissionerror.html', error=error) else: self.render('permissionerror.html') else: error = 'Both fields are required.' self.render('editblog.html', error=error, title=title, text=text)
def post(self, post_id): blog = Blog.by_id(int(post_id)) text = self.request.get('text') if blog: if not text: comment_error = "Can't post empty comment." comments = Comment.by_blog(post_id) self.render('blogpost.html', blog=blog, add_comment_error=comment_error, user_id=self.user_id, comments=comments) else: comment = Comment(blog_id=int(post_id), user_id=self.user_id, text=text) comment.put() # Adding a sleep of 1 second here # Observation - the database takes a while to reflect the # change time.sleep(1) self.redirect('/blog/%d' % int(post_id)) else: self.render('permissionerror.html')
def post(self, post_id): # post_id is the comment id. comment = Comment.by_id(int(post_id)) if comment: blog_id = comment.blog_id blog = Blog.by_id(blog_id) # Only the commentor can delete the comment. if comment.user_id == self.user_id: db.delete(comment.key()) time.sleep(1) self.redirect('/blog/%d' % blog_id) else: comment_error = """Only the Commenter can delete this comment.""" comments = Comment.by_blog(blog_id) self.render('blogpost.html', blog=blog, user_id=self.user_id, comments=comments, comment_error_id=int(post_id), comment_error=comment_error) else: self.render('permissionerror.html', error="Comment doesn't exist")