Exemple #1
0
    def post(self, comment_id):
        if not self.user:
            return self.redirect('/signin')

        c = Comment.by_id(long(comment_id))
        if not c:
            return self.render_error("404")

        if not c.user_can_edit_delete(self.user):
            return self.render_error("403")

        content = self.request.get('comment_content')
        if content:
            c.content = content
            c.put()
            self.redirect("/post/%s" % c.post_id.id())
        else:
            p = Post.by_id(long(c.post_id.id()))
            p.prep_render()
            c.content = ""
            error_comment = "Write some words, please!"
            self.render("edit_comment.html",
                        post=p,
                        comment=c,
                        error_comment=error_comment)
Exemple #2
0
    def post(self, post_id):
        if not self.user:
            return self.redirect('/signin')

        p = Post.by_id(long(post_id))
        if not p:
            return self.render_error("404")

        if self.user.key.id() != p.user_id:
            return self.render_error("403")

        subject = self.request.get('subject')
        content = self.request.get('content')

        if subject and content:
            p.title = subject
            p.content = content
            p.put()
            self.redirect('/post/%s' % str(p.key.id()))
        else:
            pid = post_id
            error = "subject and content, please!"
            self.render("edit_post.html",
                        subject=subject,
                        content=content,
                        pid=pid,
                        error=error)
Exemple #3
0
 def get(self, post_id):
     p = Post.by_id(long(post_id))
     if p:
         p.prep_render()
         self.render("post.html", post=p)
     else:
         self.render_error("404")
Exemple #4
0
    def post(self, pid):
        """delete post by given id in url"""
        if not self.user_match_post_author(pid):
            self.redirect("/")
            return

        post = Post.by_id(long(pid))
        post.delete()

        self.redirect("/my_post")
Exemple #5
0
    def post(self, post_id):
        if not self.user:
            return self.redirect("/signin")

        p = Post.by_id(long(post_id))
        if not p:
            return self.render_error("404")

        if p.user_can_unlike(self.user):
            p.likes.remove(self.user.key)
            p.put()
            self.redirect("/post/%s" % post_id)
        else:
            self.render_error("403")
Exemple #6
0
    def get(self, comment_id):
        if not self.user:
            return self.redirect('/signin')

        c = Comment.by_id(long(comment_id))
        if not c:
            return self.render_error("404")

        if c.user_can_edit_delete(self.user):
            p = Post.by_id(long(c.post_id.id()))
            p.prep_render()
            self.render("edit_comment.html", post=p, comment=c)
        else:
            self.render_error("403")
Exemple #7
0
    def post(self, post_id):
        if not self.user:
            return self.redirect("/signin")

        p = Post.by_id(long(post_id))
        if not p:
            return self.render_error("404")

        if self.user.key.id() != p.user_id:
            return self.render_error("403")

        p.delete_comments()
        p.key.delete()
        self.redirect("/blog")
Exemple #8
0
    def get(self, pid):
        """render edit post page with editor
        including original content and a form"""
        if not self.user_match_post_author(pid):
            self.redirect("/")
            return

        post = Post.by_id(long(pid))
        title = post.title
        subtitle = post.subtitle
        content = post.content

        self.render("edit_post.html",
                    title=title,
                    subtitle=subtitle,
                    content=content)
Exemple #9
0
    def post(self, comment_id):
        if not self.user:
            return self.redirect("/signin")

        c = Comment.by_id(long(comment_id))
        if not c:
            return self.render_error("404")

        if c.user_can_edit_delete(self.user):
            p = Post.by_id(c.post_id.id())
            p.comments.remove(c.key)
            p.put()
            c.key.delete()
            self.redirect("/post/%s" % p.key.id())
        else:
            self.render_error("403")
Exemple #10
0
    def post(self):
        """increment post liked number by one"""
        pid = self.request.get("pid")
        if self.with_no_user() or self.user_match_post_author(pid):
            self.redirect("/")
            return

        pid = long(pid)
        post = Post.by_id(pid)
        post.liked += 1
        post.put()

        pid = long(pid)
        like = Like(uid=self.user.key().id(), pid=pid)
        like.put()

        self.redirect("/post/%s" % pid)
Exemple #11
0
    def get(self, post_id):
        if not self.user:
            return self.redirect('/signin')

        p = Post.by_id(long(post_id))
        if not p:
            return self.render_error("404")

        if self.user.key.id() != p.user_id:
            return self.render_error("403")

        subject = p.title
        content = p.content
        pid = post_id
        self.render("edit_post.html",
                    subject=subject,
                    content=content,
                    pid=pid)
Exemple #12
0
    def get(self, pid):
        """render post page including post content
        comments and liked number"""
        pid = long(pid)
        post = Post.by_id(pid)
        if post:
            author = User.by_id(post.uid)
            comments = Comment.by_pid(pid)

            like = None
            if not self.with_no_user():
                like = Like.by_uid_and_pid(self.user.key().id(), pid)
            self.render("post.html",
                        post=post,
                        author=author,
                        comments=comments,
                        like=like)
        else:
            self.render("404.html")
Exemple #13
0
    def post(self, post_id):
        if not self.user:
            return self.redirect("/signin")

        p = Post.by_id(long(post_id))
        if not p:
            return self.render_error("404")

        content = self.request.get('comment_content')
        if content:
            c = Comment.create(content=content,
                               username=self.user.username,
                               post_key=p.key,
                               user_key=self.user.key)
            c_key = c.put()
            p.comments.append(c.key)
            p.put()
            self.redirect("/post/%s" % post_id)
        else:
            p.prep_render()
            error_comment = "Write some words, please!"
            self.render("post.html", post=p, error_comment=error_comment)
Exemple #14
0
 def user_match_post_author(self, pid):
     self.initialize(self.request, self.response)
     user = self.user
     post = Post.by_id(long(pid))
     return user and user.key().id() == post.uid