Beispiel #1
0
    def post(self, comment_id):
        """
        Attempt to create a new blog post
        """
        current_user = self.authenticate_user()

        if not current_user:
            self.redirect("/login")
        else:
            content = self.request.get("content")
            comment = Comment.get_by_id(long(comment_id))

            if not comment:
                self.redirect("/post/" + str(comment.post.id()))
            elif current_user.key != comment.user:
                self.redirect("/post/" + str(comment.post.id()))
            elif not content:
                self.render_front(
                    comment_id, content,
                    "Your comment does not contain any content.")
            else:
                comment.content = content
                comment.put()

                self.redirect("/post/" + str(comment.post.id()))
Beispiel #2
0
    def post(self, comment_id):
        '''
        Deletes the comment if the current
        user is the author of the comment
        '''
        current_user = self.authenticate_user()

        if not current_user:
            self.redirect("/login")
        else:
            comment = Comment.get_by_id(long(comment_id))

            if comment and comment.user == current_user.key:
                remove_user_comment(current_user, comment)
                comment.key.delete()

            self.redirect(self.request.referer)
Beispiel #3
0
    def render_front(self, comment_id="", content="", error=""):
        """
        Simplify the rendering of the new post template
        """
        current_user = self.authenticate_user()
        comment = Comment.get_by_id(long(comment_id))
        user = User.get_by_id(comment.user.id())

        if not content:
            content = comment.content

        if not current_user:
            self.redirect("/login")
        elif current_user.key != comment.user:
            self.write("You are not the author of this comment")
        else:
            self.render("edit_comment.html",
                        content=content,
                        error=error,
                        user=user,
                        current_user=current_user)
Beispiel #4
0
 def post(self, post_id, comment_id):
     if not self.user:
         self.render("/login")
         return
     
     # get the comment from the comment id
     comment = Comment.get_by_id(int(comment_id))
     # check if there is a comment associated with that id
     if comment:
         # check if this user is the author of this comment
         if comment.author == self.user.name:
             # delete the comment and redirect to the post page
             Comment.delete(comment_id)
             time.sleep(0.1)
             self.redirect('/post/%s' % str(post_id))
         # otherwise if this user is not the author of this comment throw an
         # error
         else:
             self.write("You cannot delete other user's comments")
     # otherwise if there is no comment associated with that id throw an
     # error
     else:
         self.write("This comment no longer exists")