Exemple #1
0
 def post(self, post_id):
     if not self.user:
         return self.redirect('/login')
     key = db.Key.from_path('blog_post', int(post_id))
     post = db.get(key)
     # Check to see if post exists and handles error if it does not
     if post:
         postId = int(post_id)
         userId = self.user.key().id()
         author = self.user.username
         comment = self.request.get("comment")
         if comment:
             comment = Comments(postId=postId,
                                userid=userId,
                                author=author,
                                comment=comment)
             comment.put()
             time.sleep(1)
             comments = Comments.all().filter("postId =",
                                              postId).order("created")
             self.render("new_post_page.html",
                         post=post,
                         author=author,
                         userId=userId,
                         comments=comments)
         else:
             comments = Comments.all().filter("postId =",
                                              postId).order("created")
             self.render("new_post_page.html",
                         post=post,
                         author=author,
                         comments=comments,
                         userId=userId,
                         error="Please enter comment before submitting")
     else:
         self.redirect('/errorhandler/2/blog')
Exemple #2
0
 def get(self, post_id):
     key = db.Key.from_path('blog_post', int(post_id))
     post = db.get(key)
     # Check to see if post exists and handles error if it does not
     if post:
         author = blog_post.get_by_id(int(post_id)).author
         postId = int(post_id)
         userId = self.user.key().id()
         comments = Comments.all().filter("postId =",
                                          postId).order("created")
         self.render('new_post_page.html',
                     post=post,
                     author=author,
                     comments=comments,
                     userId=userId)
     else:
         self.redirect('/errorhandler/2/blog')