Ejemplo n.º 1
0
    def get(self, blog_id):
        blog_key = Blog.get_by_id(int(blog_id))
        comment_key = Comments.gql("WHERE blog_id = %s "
                                   "ORDER BY created DESC" % int(blog_id))

        # render the blog object and all of it's comment
        self.render("blogpost.html", blogs=[blog_key], comments=comment_key)
Ejemplo n.º 2
0
    def get(self, blog_id):
        key = Blog.get_by_id(int(blog_id))

        if self.user:
            # rendering the blog post using blog_id
            self.render("editpost.html", blogs=[key])
        else:
            self.redirect("/login")
Ejemplo n.º 3
0
    def post(self, blog_id):
        key = int(blog_id)  # get id and turns into integer
        post = Blog.get_by_id(key)  # use id to fine the blog post item

        if self.user.name == post.author.name:
            post.key.delete()  # delete the found item
            time.sleep(0.1)  # sleep is used because of replication lag time

        self.redirect('/')  # redirect to home
Ejemplo n.º 4
0
    def post(self, blog_id):
        key = int(blog_id)
        post = Blog.get_by_id(key)

        if post and self.user:
            post.like -= 1
            like = Likes(blog_id=key, author=self.user)
            like.put()
            post.put()
            time.sleep(0.2)
            self.redirect('/%s' % key)
        else:
            self.redirect('/login')
Ejemplo n.º 5
0
    def post(self, blog_id):
        key = int(blog_id)
        post = Blog.get_by_id(key)
        subject = self.request.get('subject')
        content = self.request.get('content')

        # current user.name has to match
        # with author's name
        if self.user.name == post.author.name:
            if subject and content:
                post.subject = subject  # updating the subject
                post.content = content  # updating the content
                post.put()
                time.sleep(0.1)
                self.redirect('/%s' % key)  # redirect to the blog post
            else:
                msg = "Something went wrong. Please try again."
                self.render("editpost.html", blogs=[key], error_message=msg)
        else:
            self.redirect('/login')