def post(self, post_id): # checks if user is logged in if not user_logged_in(self): return self.redirect('/') key = db.Key.from_path('Post', int(post_id), parent=post_key()) post = db.get(key) if not post: return self.error(404) # checks if the user owns the post if not user_owns_post(self, post): return self.redirect('/') title = self.request.get('title') content = self.request.get('content') if title and content: post.title = title post.content = content post.put() self.redirect('/blog') else: error = "Both subject and content are required!" self.render("newPostPage.html", title=title, content=content, error=error)
def post(self, post_id, comment_id): # checks if user is logged in if user_logged_in(self): key = db.Key.from_path('Post', int(post_id), parent=post_key()) post = db.get(key) if not post: return self.error(404) key = db.Key.from_path('Comment', int(comment_id), parent=comment_key()) comment = db.get(key) if not comment: return self.error(404) # checks if the user owns the comment if user_owns_comment(self, comment): content = self.request.get('content') if content: comment.content = content comment.put() time.sleep(0.1) self.redirect('/blog/%s/comment' % str(post_id)) else: error = "Some content is required!" self.render("editComment.html", content=content, error=error) else: return self.redirect('/')
def get(self, post_id): if user_logged_in(self): key = db.Key.from_path('Post', int(post_id), parent=post_key()) post = db.get(key) if not post: return self.error(404) if user_owns_post(self, post): post.delete() self.redirect('/blog') else: self.redirect('/')
def get(self, post_id): if not user_logged_in(self): return self.redirect('/') key = db.Key.from_path('Post', int(post_id), parent=post_key()) post = db.get(key) if not post: return self.error(404) if user_owns_post(self, post): params = dict(title=post.title, content=post.content, user=self.user) self.render('editPostPage.html', **params) else: return self.redirect('/')
def get(self, post_id): if user_logged_in(self): key = db.Key.from_path('Post', int(post_id), parent=post_key()) post = db.get(key) if not post: return self.error(404) comments = db.GqlQuery( "SELECT * FROM Comment WHERE parent_post = :post ORDER BY created DESC", post=post) self.render('postComments.html', post=post, comments=comments, user=self.user) else: return self.redirect('/')
def get(self, post_id, comment_id): if user_logged_in(self): key = db.Key.from_path('Post', int(post_id), parent=post_key()) post = db.get(key) if not post: return self.error(404) key = db.Key.from_path('Comment', int(comment_id), parent=comment_key()) comment = db.get(key) if not comment: return self.error(404) if user_owns_comment(self, comment): comment.delete() time.sleep(0.1) self.redirect('/blog/%s/comment' % str(post_id)) else: self.redirect('/')
def get(self, post_id, comment_id): if user_logged_in(self): key = db.Key.from_path('Post', int(post_id), parent=post_key()) post = db.get(key) if not post: return self.error(404) key = db.Key.from_path('Comment', int(comment_id), parent=comment_key()) comment = db.get(key) if not comment: return self.error(404) # checks if the user owns the comment if user_owns_comment(self, comment): params = dict(content=post.content, user=self.user) self.render('editComment.html', **params) else: return self.redirect('/')
def post(self, post_id): if user_logged_in(self): key = db.Key.from_path('Post', int(post_id), parent=post_key()) post = db.get(key) if not post: return self.error(404) # Only posts non-owners can comment if not user_owns_post(self, post): content = self.request.get('content') comment = Comment(parent=comment_key(), content=content, author=self.user, parent_post=post) comment.put() time.sleep(0.1) self.redirect('/blog/%s/comment' % str(post_id)) else: return self.redirect('/blog')
def post(self): if not user_logged_in(self): self.redirect('/') title = self.request.get('title') content = self.request.get('content') if title and content: p = Post(parent=post_key(), title=title, content=content, author=self.user) p.put() self.redirect('/blog') else: error = "Both subject and content are required!" self.render("newPostPage.html", title=title, content=content, error=error)
def get(self, post_id): if user_logged_in(self): key = db.Key.from_path('Post', int(post_id), parent=post_key()) post = db.get(key) if not post: return self.error(404) if not user_owns_post(self, post): self.redirect('/') if post.liked(self.user): l = db.GqlQuery( "SELECT * FROM Like WHERE author=:user AND parent_post=:post", user=self.user, post=post).get() l.delete() self.redirect('/blog') else: l = Like(author=self.user, parent_post=post) l.put() self.redirect('/blog') else: return self.redirect('/')