Пример #1
0
    def post(self):
        logging.error(utils.blog_key())
        if not self.user:
            self.redirect('/blog')

        subject = self.request.get('subject')
        content = self.request.get('content')
        parent = utils.blog_key()

        if subject and content:
            logging.error(utils.age_str(12345))
            p = Post(parent = parent, subject = subject, content = content)
                    
            add_post(p)
                    
            self.redirect('/blog/%s' % str(p.key().id()))
        else:
            error = "subject and content, please!"
            self.render("newpost.html", subject = subject, content = content, error = error)
Пример #2
0
    def post(self):
        logging.error(utils.blog_key())
        if not self.user:
            self.redirect('/blog')

        subject = self.request.get('subject')
        content = self.request.get('content')
        parent = utils.blog_key()

        if subject and content:
            logging.error(utils.age_str(12345))
            p = Post(parent=parent, subject=subject, content=content)

            add_post(p)

            self.redirect('/blog/%s' % str(p.key().id()))
        else:
            error = "subject and content, please!"
            self.render("newpost.html",
                        subject=subject,
                        content=content,
                        error=error)
Пример #3
0
 def get(self, post_id):
     post_key = 'POST_' + post_id
     
     post, age = utils.age_get(post_key)
     
     #if post not returned, lookup from db
     #TODO: move db logic to utils or Post
     if not post:
         key = db.Key.from_path('Post', int(post_id), parent=utils.blog_key())
         post = db.get(key)
         utils.age_set(post_key, post)
         age = 0
     
     if not post:
         self.error(404)
         return
     
     if self.format == 'html':
         self.render("permalink.html", post = post, age = utils.age_str(age))
     elif self.format == 'json':
         self.render_json(post.as_dict())
Пример #4
0
    def get(self, post_id):
        post_key = "POST_" + post_id

        post, age = utils.age_get(post_key)

        # if post not returned, lookup from db
        # TODO: move db logic to utils or Post
        if not post:
            key = db.Key.from_path("Post", int(post_id), parent=utils.blog_key())
            post = db.get(key)
            utils.age_set(post_key, post)
            age = 0

        if not post:
            self.error(404)
            return

        if self.format == "html":
            self.render("permalink.html", post=post, age=utils.age_str(age))
        elif self.format == "json":
            self.render_json(post.as_dict())