Example #1
0
  def get(self,post_id):
    session = get_current_session()
    if session.has_key('user'):
      user = session['user']
    

    try:
      post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get()
      if  post  == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories
        post = db.get( helper.parse_post_id( post_id ) ) 

      comments = Comment.all().filter("post =", post.key()).order("-karma").fetch(1000)
      comments = helper.order_comment_list_in_memory(comments)
      prefetch.prefetch_comment_list(comments)
      display_post_title = True
      prefetch.prefetch_posts_list([post])
      if helper.is_json(post_id):
        comments_json = [c.to_json() for c in comments if not c.father_ref()] 
        if(self.request.get('callback')):
          self.response.headers['Content-Type'] = "application/javascript"
          self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'post':post.to_json(),'comments':comments_json})+')')
        else:
          self.response.headers['Content-Type'] = "application/json"
          self.response.out.write(simplejson.dumps({'post':post.to_json(),'comments':comments_json}))
      else:
        helper.killmetrics("Pageview","Post", "view", session, "",self)
        self.response.out.write(template.render('templates/post.html', locals()))
    except db.BadKeyError:
      self.redirect('/')
Example #2
0
  def get(self,post_id):
    session = get_current_session()
    if session.has_key('user'):
      user = session['user']
    
    try:
      post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get()
      if  post  == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories
        post = db.get( helper.parse_post_id( post_id ) ) 

      comments = Comment.all().filter("post =", post.key()).order("-karma").fetch(1000)
      comments = helper.order_comment_list_in_memory(comments)
      prefetch.prefetch_comment_list(comments)
      display_post_title = True
      prefetch.prefetch_posts_list([post])
      if helper.is_json(post_id):
        comments_json = [c.to_json() for c in comments if not c.father_ref()] 
        if(self.request.get('callback')):
          self.response.headers['Content-Type'] = "application/javascript"
          self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'post':post.to_json(),'comments':comments_json})+')')
        else:
          self.response.headers['Content-Type'] = "application/json"
          self.response.out.write(simplejson.dumps({'post':post.to_json(),'comments':comments_json}))
      else:
        self.response.out.write(template.render('templates/post.html', locals()))
    except db.BadKeyError:
      self.redirect('/')
Example #3
0
 def get(self, post_id):
     session = get_current_session()
     if session.has_key('user'):
         user = session['user']
     try:
         post = db.get(helper.parse_post_id(post_id))
         comments = Comment.all().filter(
             "post =", post.key()).order("-karma").fetch(1000)
         comments = helper.order_comment_list_in_memory(comments)
         prefetch.prefetch_comment_list(comments)
         display_post_title = True
         prefetch.prefetch_posts_list([post])
         if helper.is_json(post_id):
             comments_json = [
                 c.to_json() for c in comments if not c.father_ref()
             ]
             if (self.request.get('callback')):
                 self.response.headers[
                     'Content-Type'] = "application/javascript"
                 self.response.out.write(
                     self.request.get('callback') + '(' +
                     simplejson.dumps({
                         'post': post.to_json(),
                         'comments': comments_json
                     }) + ')')
             else:
                 self.response.headers['Content-Type'] = "application/json"
                 self.response.out.write(
                     simplejson.dumps({
                         'post': post.to_json(),
                         'comments': comments_json
                     }))
         else:
             self.response.out.write(
                 template.render('templates/post.html', locals()))
     except db.BadKeyError:
         self.redirect('/')