コード例 #1
0
 def post(self):
     logging.info(self.request.body)
     data = json.loads(self.request.body)
     user_id = self.request.cookies.get("user_id")
     if user_id and len(user_id) > 0:
         l = user_id.split("|")
         if (user_id == Utilities.make_cookie_val(l[0])):
             # Get the comment from data store
             c = Comments.get_by_id(long(data['commentid']))
             blogid = c.blogid
             # and the blogpost itself
             bp = BlogPosts.get_by_id(long(blogid))
             commentsnum = self.deleteCommentInDB(c, bp)
             self.response.out.write(
                 json.dumps(({
                     'blogid': str(blogid),
                     'commentsnum': commentsnum
                 })))
         else:
             self.response.headers.add_header('set-cookie',
                                              str('user_id=;Path=/'))
             self.redirect('/blog')
     else:
         self.response.headers.add_header('set-cookie',
                                          str('user_id=;Path=/'))
         self.redirect('/blog')
コード例 #2
0
ファイル: main.py プロジェクト: iwnelson/blog-project
 def get_comment(self, comment_id):
     '''Retrieves comment id from url. If comment id matches comment in Comments
     database, returns comment, if not, returns None'''
     if comment_id:
         comment = Comments.get_by_id(int(comment_id))
     if comment:
         return comment
コード例 #3
0
    def get(self, post_id, comment_id):
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)

        comment = Comments.get_by_id(int(comment_id))
        if self.user and comment:
            if comment.user.name == self.user.name:
                self.render("editcomment.html", comment=comment)
            else:
                return self.redirect("/blog/%s" % str(post.key().id()))
コード例 #4
0
    def post(self, post_id, comment_id):
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)

        if self.request.get("save"):
            comment = Comments.get_by_id(int(comment_id))
            if self.user and comment:
                if comment.user.name == self.user.name:
                    comment.comment = self.request.get("comment")
                    comment.put()
                    return self.redirect("/blog/%s" % str(post.key().id()))
                else:
                    save_error = \
                        "Only the author of the comment can make changes."
                    self.render("editcomment.html",
                                comment=comment,
                                error=save_error)

        if self.request.get("cancel"):
            return self.redirect("/blog/%s" % str(post.key().id()))
コード例 #5
0
    def post(self):
        post_id = self.request.get("post_id")
        comment_id = self.request.get("comment_id")
        key = db.Key.from_path('Post', int(post_id), parent=blog_key())
        post = db.get(key)

        if not post:
            self.error(404)
            return

        if self.user:
            comment = Comments.get_by_id(int(comment_id))
            if comment is not None and comment.user.name == self.user.name:
                db.delete(comment)
                return self.redirect("/blog/%s" % str(post.key().id()))
            else:
                delete_error = "Failed to delete comment"
                self.render("permalink.html",
                            post=post,
                            delete_error=delete_error)
        else:
            return self.redirect("/blog")
コード例 #6
0
 def post(self):
     logging.info(self.request.body)
     data = json.loads(self.request.body)
     # Get the comment from data store
     user_id = self.request.cookies.get("user_id")
     if user_id and len(user_id) > 0:
         l = user_id.split("|")
         if (user_id == Utilities.make_cookie_val(l[0])):
             c = Comments.get_by_id(long(data['commentid']))
             c.comment = data['updatedcomment']
             c.put()
             self.response.out.write(
                 json.dumps(({
                     "added":
                     datetime.strftime(c.added, '%b %d,  %Y %I:%M %p')
                 })))
         else:
             self.response.headers.add_header('set-cookie',
                                              str('user_id=;Path=/'))
             self.redirect('/blog')
     else:
         self.response.headers.add_header('set-cookie',
                                          str('user_id=;Path=/'))
         self.redirect('/blog')