Пример #1
0
    def render(self, username):
        """ Post class render method """
        self._render_text = self.content.replace('\n', '<br>')
        self._key = self.key().id()
        self._can_edit = False

        key = db.Key.from_path('Post', int(self._key), parent=utils.blog_key())

        if self.author.name == username:
            self._can_edit = True

        return utils.render_str("post.html",
                                p=self)
Пример #2
0
    def get(self, post_id):
        """ Render blog's post - get method """
        key = db.Key.from_path('Post', int(post_id), parent=utils.blog_key())
        post = db.get(key)

        if not post:
            self.error(404)
            return

        username = self.user and self.user.name

        self.render("permalink.html",
                    username=username,
                    post_id=post_id,
                    post=post)
Пример #3
0
    def get(self, post_id):
        """ Delete post - get method """
        key = db.Key.from_path('Post', int(post_id), parent=utils.blog_key())
        post = db.get(key)

        if not post:
            self.error(404)
            return

        if post.author.key().id() == self.user.key().id():
            post.delete()
            self.render('delete.html',
                        message="Post succesfully deleted")
        else:
            self.render('delete.html',
                        message="Error attempting to delete post")
Пример #4
0
    def get(self):
        """ New comment class - get method """
        post_id = self.request.get("key")
        key = db.Key.from_path('Post',
                               int(post_id),
                               parent=utils.blog_key())
        post = db.get(key)

        if not post:
            self.error(404)
            return

        if post.key().id():
            self.redirect('/blog/%s' % str(post.key().id()))
        else:
            self.redirect('/blog')
Пример #5
0
    def get(self, post_id):
        """ Like post - get method """
        key = db.Key.from_path('Post',
                               int(post_id),
                               parent=utils.blog_key())
        post = db.get(key)

        if not post:
            self.error(404)
            return

        if post.author.key().id() == self.user.key().id():
            message = "Authors can't like their own post"
            self.render('front.html', message=message)
        else:
            post.liked_by.append(post.author.key().id())
            post.save()

            self.redirect('/blog/%s' % str(post.key().id()))
Пример #6
0
 def post(self):
     valid_cookie = self.request.cookies.get('user_id')
     if valid_cookie:
         import globals 
         if globals.users != None:
             subject = self.request.get("subject")
             contents = self.request.get("content")
     
             if subject and contents:
                 s = Blog_db(parent = utils.blog_key(), subject = subject, content = contents)
                 s.put()
                 utils.cache_blog(True)
     
                 self.redirect("/blog/%s" % str(s.key().id()))
             else:
                 error = "We need both subject and content!"
                 self.render("newpost.html", subject = subject, content = contents, error = error, user = globals.users)
     else:
         self.redirect('/')
Пример #7
0
    def post(self):
        """ New comment class """
        post_id = self.request.get("key")
        key = db.Key.from_path('Post',
                               int(post_id),
                               parent=utils.blog_key())
        post = db.get(key)

        if not post:
            self.error(404)
            return

        content = self.request.get("content")
        author = User.by_name(self.user.name)

        if content:
            comm = Comment(post=post, content=content, author=author)
            comm.put()

        # Setting timer to give time for the Server to SAVE
        time.sleep(2)
        self.redirect('/blog/%s' % str(post.key().id()))
Пример #8
0
    def post(self):
        """ New post class - post method """
        subject = self.request.get("subject")
        content = self.request.get("content")
        author = User.by_name(self.user.name)
        error = ""

        if subject and content:
            to_post = Post(parent=utils.blog_key(),
                           subject=subject,
                           content=content,
                           author=author)
            to_post.put()
            self.redirect('/blog/%s' % str(to_post.key().id()))
        else:
            error = "subject and content, please!"
            self.render("newpost.html",
                        title="New Post",
                        username=self.user.name,
                        subject=subject,
                        content=content,
                        error=error)
Пример #9
0
    def post(self):
        """ Edit post class - post method """
        post_id = self.request.get("key")
        key = db.Key.from_path('Post',
                               int(post_id),
                               parent=utils.blog_key())
        post = db.get(key)

        if not post:
            self.error(404)
            return

        if post.author.key().id() == self.user.key().id():
            post.subject = self.request.get("subject")
            post.content = self.request.get("content")
            post.author = self.user
            error = ""

            if post.subject and post.content:
                post.save()

                # Setting timer to give time for the Server to SAVE
                time.sleep(2)

                self.redirect('/blog')
            else:
                error = "subject and content, please!"
                self.render("editpost.html",
                            title="Edit Post",
                            username=self.user.name,
                            subject=post.subject,
                            content=post.content,
                            author=post.author,
                            error=error)
        else:
            self.redirect("/login")