def post(self): user = users.get_current_user() comment = Comment( email=user.nickname(), time=datetime.now(), content=self.request.get('comment'), type=self.request.get('type'), ) comment.put() time.sleep(.2) self.redirect('/studentforum') template = env.get_template('studentforum.html') self.response.write(template.render())
def post(self, post_id): post = db.get(db.Key.from_path('Post', int(post_id), parent=blog_key())) #print "post_id:",post_id all_comments = db.GqlQuery( "SELECT * FROM Comment WHERE parent_post = " + post_id + "order by created desc") all_likes = db.GqlQuery("SELECT * FROM Like WHERE parent_post = " + post_id) if not post: self.error(404) return """ On posting comment, new comment tuple is created and stored, with relationship data of user and post. """ if (self.user): if (self.request.get('comment')): #Create comment tuple cmt = Comment(parent=blog_key(), author=self.user.key().id(), comment=self.request.get('comment'), parent_post=int(post_id)) cmt.put() self.redirect('/blog/%s' % post_id) if (self.request.get('like') and (self.request.get('like') == "true")): #Create Like object liker = self.user.key().id() liked_by_all = db.GqlQuery( "SELECT DISTINCT liked_by FROM Like WHERE parent_post = " + post_id) liked_list = liked_by_all.fetch(limit=10000) likes_list = str([x.liked_by for x in liked_list]) previous_like = str(liker) in likes_list if liker == post.author: error_msg = "It goes without saying that you like your own post." num_likes = all_likes.count() self.render("permalink.html", post=post, comments=all_comments, error=error_msg, num_likes=num_likes, post_id=post_id) return elif not previous_like: new_like = Like(parent=blog_key(), liked_by=self.user.key().id(), parent_post=int(post_id)) new_like.put() else: error_msg = "You already liked this post." num_likes = all_likes.count() self.render("permalink.html", post=post, comments=all_comments, error=error_msg, num_likes=num_likes, post_id=post_id) return else: self.render( "login-form.html", error= "You need to be logged in to like posts or submit comments.") #return self.redirect('/blog/%s' % post_id)