Beispiel #1
0
    def get(self, post_id):
        post = Post.getById(post_id)

        if not post:
            self.error(404)
            self.write(
                "<h1>404 Not Found</h1>The resource could not be found.")
            return

        comments = Comment.getByPostID(post_id)
        comments_count = Comment.countByPostID(post_id)

        likes_num = Like.countByPostID(post_id)
        # Get post status (liked or not) by a specific user
        like_btn_txt = "Like"
        if self.user:
            if Like.getByPostAndAuthor(post_id, self.user.name):
                like_btn_txt = "Unlike"

        self.render("post.html",
                    post=post,
                    comments_count=comments_count,
                    comments=comments,
                    likes_num=likes_num,
                    like_text=like_btn_txt)
Beispiel #2
0
    def post(self, post_id):
        # get the key for this blog post
        post = Post.getById(post_id)

        if not post:
            self.response.out.write("Not a valid post!")

        if not self.user:
            return self.redirect('/login')

        if post.author != self.user.name:
            self.render("post.html",
                        post=post,
                        title=post.subject,
                        error="You're not allowed to edit this article!")
            return

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

        if subject and content:
            # update the blog post and redirect to the post page
            post.subject = subject
            post.content = content
            post.put()
            time.sleep(0.1)
            self.redirect('/post/%s' % str(post.key.id()))

        else:
            post_error = "Please enter a subject and the blog content"
            self.render("editpost.html",
                        subject=subject,
                        content=content,
                        post_error=post_error)
Beispiel #3
0
    def get(self, post_id):
        post = Post.getById(post_id)

        if not post:
            self.response.out.write("Not a valid post!")

        if not self.user:
            self.redirect('/login')

        if post.author != self.user.name:
            self.render("post.html",
                        post=post,
                        title=post.subject,
                        error="You're not allowed to edit this article!")
            return

        self.render('editpost.html', post=post, post_id=post_id)
Beispiel #4
0
    def post(self, post_id):
        post = Post.getById(post_id)

        if not post:
            self.response.out.write("Not a valid post!")

        if not self.user:
            self.redirect('/login')

        if post.author != self.user.name:
            self.render("post.html",
                        post=post,
                        title=post.subject,
                        error="You're not allowed to delete this article!")
            return
        # Delete the post
        post.key.delete()
        time.sleep(0.1)
        self.redirect('/')