示例#1
0
    def post(self):
        subject = self.request.get("subject")
        content = self.request.get("content")

        if subject and content:
            post = BlogPost(subject=subject, content=content)
            post.put()

            self.redirect("/blog/%s" % str(post.key().id()))
        else:
            error = "subject and content are required"
            self.render_newpost(subject=subject, content=content, error=error)
 def get(self, **kwargs):
     ident = kwargs['id']        
     post = BlogPost.get_by_id(ident)
     
     self.response.headers.add_header('Content-Type', 'application/json; charset=utf-8')
     self.write( json.dumps( post.to_json() ) )            
     
示例#3
0
    def get(self):
        posts = BlogPost.get_all_posts()

        res = []
        for post in posts:
            post_json = post.to_json()
            res.append(post_json)

        self.response.headers.add_header("Content-Type", "application/json; charset=utf-8")
        self.write(json.dumps(res))
示例#4
0
    def get(self):
        posts = memcache.get(POSTS_KEY)
        t = memcache.get(POSTS_TIME_KEY)

        if not posts or not t:
            posts = BlogPost.get_all_posts()
            t = time.time()
            memcache.set(POSTS_KEY, posts)
            memcache.set(POSTS_TIME_KEY, t)

        t = int (time.time() - t)
            
        self.render('blog.html', posts = posts, posts_generated = t)
示例#5
0
    def get(self, **kwargs):
        ident = kwargs['id']
        
        post = memcache.get(POST_KEY % ident)
        t = memcache.get(POST_TIME_KEY % ident)
        
        if not post or not t:
            post = BlogPost.get_by_id(ident)
            t = time.time()
            memcache.set(POST_KEY % ident, post)
            memcache.set(POST_TIME_KEY % ident, t)

        t = int (time.time() - t)
        
        if not post:
            error = 'No such post'
            self.render_post(error=error)
        else:
            self.render_post(post = post, post_generated = t)