예제 #1
0
    def post(self):
        if not self.user:
            self.redirect('/blog')

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

        if subject and content:
            p = Post(subject = subject, content = content)
            p.put()
            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 top_posts(self, update = False):
     key = "top"
     tops = memcache.get(key)
     now = int(time.time())
     if tops is None or update:
         tops = Post.all().order('-created')
         memcache.set(key, tops)
         memcache.set("time", now)
     secondsAgo = now - int(memcache.get("time"))
     return [tops, secondsAgo]
예제 #3
0
    def get(self, post_id):
        post = Post.get_by_id(int(post_id))

        if not post:
            self.error(404)
            return

        now = int(time.time())
        postTimeKey = "time" + post_id
        postTimeCached = memcache.get(postTimeKey)
        if not postTimeCached:
            memcache.set(postTimeKey, now)

        secondsAgo = now - int(memcache.get(postTimeKey))

        self.render("post.html", post = post, secondsAgo = secondsAgo)