def post(self, post_id): a = Article.check_if_valid_post(post_id) if a: if self.user: key = db.Key.from_path('Article', int(post_id), parent=blog_key()) a = db.get(key) comment = self.request.get('comment') created_by = self.user.name if comment: c = Comment(parent=blog_key(), comment=comment, post_id=int(post_id), created_by=created_by) c.put() comments = db.GqlQuery( "select * from Comment where post_id = " + post_id + " order by created desc") self.render("permalink.html", a=a, comments=comments) else: self.redirect('/blog/login') else: self.error(404) return
def get(self, post_id): a = Article.check_if_valid_post(post_id) if a: comments = db.GqlQuery("select * from Comment where post_id = " + post_id + " order by created desc") else: self.error(404) return self.render("permalink.html", a=a, comments=comments)
def post(self, post_id, comment_id): a = Article.check_if_valid_post(post_id) c = Comment.check_if_user_owns_comment(comment_id, self.user.name) if a and c: comment = self.request.get('comment') if comment: c.comment = comment c.put() self.redirect('/blog/%s' % post_id) else: error = "Please input comment" self.redner("comment.html", error=error, c=c) else: error = "Oops, this is not your comment" self.render("error.html", error=error)
def get(self, post_id): a = Article.check_if_valid_post(post_id) uid = self.read_secure_cookie('user_id') if a: if a.created_by == self.user.name: error = "you can\'t like your own post" self.render('error.html', error=error) elif not self.user: self.redirect('/blog/login') elif a.likes and uid in a.likes: a.likes.remove(uid) a.put() self.redirect(self.request.referer) else: a.likes.append(uid) a.put() self.redirect(self.request.referer)