def get(self, post_id): if self.user: key = db.Key.from_path('Post', int(post_id), parent=blog_key()) post = db.get(key) # check if the post exist in the database if not post: # if post does not exist, redirect to login page return self.redirect('/login') if post.user_id == self.user.key().id(): post.delete() # delete all the comments associated with that post comments = Comment.all() comments.filter("post_id", int(post_id)) for comment in comments: comment.delete() self.redirect("/?deleted_post_id=" + post_id) else: self.redirect("/blog/" + post_id + "?error=You don't have " + "access to delete this record.") else: self.redirect("/login?error=You need to be logged, in order" + " to delete your post!!")
def get(self, post_id): if self.user: username = self.user.name else: username = None post_id_int = int(post_id) p = Blog_post.by_id(post_id_int) subject = p.subject content = p.content created = p.created owner = p.owner comment_count = p.comment_count like_count = p.like_count comment_key = p.key() source = self.request.url comments = Comment.all().ancestor(comment_key).order('-created').run() if username: liked = hasattr(p, username) else: liked = "" self.render_post(subject, content, created, comments, comment_count, like_count, username, owner, post_id, source, liked)
def get(self, post_id): key = db.Key.from_path('Post', int(post_id), parent=blog_key()) post = db.get(key) uid = self.read_secure_cookie('user_id') if post.likes and uid in post.likes: likeStatus = 'Unlike' else: likeStatus = 'Like' comments = Comment.all().filter('parent_id =', post_id).order('-created') if not post: self.render("404.html") self.render("post.html", post = post, uid = uid, likeStatus = likeStatus, comments = comments)
def comments(self): return Comment.all(where='topic_id = %s' % self.id())
def destroy(self): comments = Comment.all(where='topic_id = %s' % self.id()) [comment.destroy() for comment in comments] super(Topic, self).destroy()
def get_comments(self): """Get post comments.""" c = Comment.all().filter('post_id =', self.key().id()).get() return c
def comments(self): return Comment.all().filter("post_id = ", str(self.key().id()))