Beispiel #1
0
def thread(request, post_id, starting_index = None):
  if starting_index == '':
    starting_index = None
    
  if starting_index is None:
    replies, next_id = request.post.get_all_replies(None, 49)
  else:
    replies, next_id = request.post.get_all_replies(int(starting_index), 50)

  p = build_template_params(_('View Thread'), '/', request.user)
  if next_id is not None:
    p['next_index'] = next_id
    
  if starting_index is None:
    p['post'] = request.post
    counter.increment('THREAD_READS:'+str(request.post.key().id()))

  if request.user is not None:
    if (users.is_current_user_admin()
        or request.post.forum.is_moderator(request.user)):
      p['admin_mode']=True
    
  p['forum'] = request.forum
  p['replies'] = replies
  return render_to_response(request, 'post/thread.html', p)
Beispiel #2
0
 def delete_post(self, post):
   """Deletes a post from a thread.
   
   Args:
     post: the post to be deleted.
   """
   if post.is_deleted:
     counter.increment('POST_COUNT:'+str(self.key().id()))
     if post.root_post is not None:
       counter.increment('THREAD_REPLIES:'+str(post.root_post.key().id()))
     else:
       counter.decrement('THREAD_COUNT:'+str(self.key().id()))
   else:
     counter.decrement('POST_COUNT:'+str(self.key().id()))
     if post.root_post is not None:
       counter.decrement('THREAD_REPLIES:'+str(post.root_post.key().id()))
     else:
       counter.decrement('THREAD_COUNT:'+str(self.key().id()))
   post.is_deleted = not post.is_deleted
   post.put()
Beispiel #3
0
 def add_post(self, post):
   """Adds a forum post to the forum
   
   Args:
     post: the post to be added to the forum.
   
   Returns:
     the added post.
   """
   post.post_index = str(post.post_time) +'|' + post.author.key().name()
   if post.root_post is None:
     counter.increment('THREAD_COUNT:'+str(self.key().id()))
     post.last_reply_index = post.post_index
     post.put()
   else:
     post.root_post.last_reply_index = post.post_index
     db.put([post.root_post, post])
     counter.increment('THREAD_REPLIES:'+str(post.root_post.key().id()))
       
   counter.increment('POST_COUNT:'+str(self.key().id()))