def get(self, post_id): key = db.Key.from_path('Post', int(post_id), parent=blog_key()) post = db.get(key) comments_count = Comment.count_by_post_id(post) post_comments = Comment.all_by_post_id(post) if post: if self.user and self.user.key().id() == post.user.key().id(): error = "You cannot dislike your own post" self.render("post.html", post=post, comments_count=comments_count, post_comments=post_comments, error=error) elif not self.user: self.redirect('/login') else: l = Like.all().filter('user ='******'post =', post).get() if l: l.delete() post.likes -= 1 post.put() self.redirect('/post/' + str(post.key().id())) else: self.redirect('/post/' + str(post.key().id()))
def get(self, post_id): key = db.Key.from_path('Post', int(post_id), parent=blog_key()) post = db.get(key) if not (post is None) and self.user and self.user.key().id( ) == post.user.key().id(): if post: db.delete(key) time.sleep(0.1) self.redirect('/') else: self.response.out.write("Not a valid post!") # otherwise if the user is not logged in take them to the # login page elif not self.user: self.redirect("/login") else: error = "You cannot delete other user's posts" likes = like = Like.all().filter('post_id =', post_id).get() comments_count = Comment.count_by_post_id(post) post_comments = Comment.all_by_post_id(post) self.render("post.html", post=post, likes=likes, comments_count=comments_count, post_comments=post_comments, error=error)
def get(self, post_id): post = db.get(db.Key.from_path("Post", int(post_id), parent=blog_key())) comments_count = Comment.count_by_post_id(post) post_comments = Comment.all_by_post_id(post) self.render("post.html", post=post, comments_count=comments_count, post_comments=post_comments)
def get(self, post_id): key = db.Key.from_path("Post", int(post_id), parent=blog_key()) post = db.get(key) comments_count = Comment.count_by_post_id(post) post_comments = Comment.all_by_post_id(post) if post: # check if the user is trying to like own post if self.user and self.user.key().id() == post.user.key().id(): error = "You cannot like your own posts" self.render("post.html", post=post, comments_count=comments_count, post_comments=post_comments, error=error) elif not self.user: self.redirect('/login') else: like = Like.all().filter('user ='******'post =', post).get() if like: self.redirect('/post/' + str(post.key().id())) else: like = Like(post=post, user=self.user) post.likes += 1 like.put() post.put() self.redirect('/post/' + str(post.key().id())) else: self.response.out.write("Not a valid post!")