Пример #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:
        self.response.out.write(template.render('templates/post.html', locals()))
    except db.BadKeyError:
      self.redirect('/')
Пример #2
0
def filter_user_comments(all_comments, user):
    """ This function removes comments that belong to a thread
  which had a comment by the same user as a parent """
    res_comments = []
    for user_comment in all_comments:  ### Cycle all the comments and find the ones we care
        linked_comment = user_comment
        while True:
            if Comment.father.get_value_for_datastore(linked_comment) is None:
                if not [c for c in res_comments if c.key() == user_comment.key()]:
                    res_comments.append(user_comment)  # we care about the ones that are topmost
                break
            if linked_comment.father.user.key() == user.key():
                if not [c for c in res_comments if c.key() == linked_comment.father.key()]:
                    res_comments.append(
                        linked_comment.father
                    )  # But we also want to append the "father" ones to avoid having pages with 0 comments
                break
            linked_comment = linked_comment.father
    # Add Childs here
    child_list = []
    for comment in res_comments:
        comment.is_top_most = True
        child_list.extend(add_childs_to_comment(comment))
    prefetch.prefetch_comment_list(
        res_comments + child_list
    )  # Finally we prefetch everything, 1 super call to memcache
    return res_comments
Пример #3
0
def filter_user_comments(all_comments, user):
    """ This function removes comments that belong to a thread
  which had a comment by the same user as a parent """
    res_comments = []
    for user_comment in all_comments:  ### Cycle all the comments and find the ones we care
        linked_comment = user_comment
        while (True):
            if Comment.father.get_value_for_datastore(linked_comment) is None:
                if not [
                        c
                        for c in res_comments if c.key() == user_comment.key()
                ]:
                    res_comments.append(
                        user_comment
                    )  # we care about the ones that are topmost
                break
            if linked_comment.father.user.key() == user.key():
                if not [
                        c for c in res_comments
                        if c.key() == linked_comment.father.key()
                ]:
                    res_comments.append(
                        linked_comment.father
                    )  # But we also want to append the "father" ones to avoid having pages with 0 comments
                break
            linked_comment = linked_comment.father
    # Add Childs here
    child_list = []
    for comment in res_comments:
        comment.is_top_most = True
        child_list.extend(add_childs_to_comment(comment))
    prefetch.prefetch_comment_list(
        res_comments +
        child_list)  #Finally we prefetch everything, 1 super call to memcache
    return res_comments
Пример #4
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('/')
Пример #5
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('/')