Exemplo n.º 1
0
def index(request):
  floor_id = request.user.get_profile().floor_id
  
  # Get floor posts.
  posts = Post.objects.filter(
      floor=floor_id
  ).order_by("-id").select_related('user__profile')
  
  post_count = posts.count
  posts = posts[:DEFAULT_POST_COUNT]
  more_posts = True if post_count > DEFAULT_POST_COUNT else False
  
  # Get upcoming events.
  events = get_available_events(request.user)
  
  # Get the user's current commitments.
  commitment_members = get_current_commitment_members(request.user).select_related("commitment")
  
  # Get the floor members.
  floor_members = Profile.objects.filter(floor=floor_id).order_by(
      "-points", 
      "-last_awarded_submission"
  ).select_related('user')[:12]
  
  form = EventCodeForm()
    
  return render_to_response("news/index.html", {
    "posts": posts,
    "events": events,
    "wall_form": WallForm(),
    "more_posts": more_posts,
    "commitment_members": commitment_members,
    "floor_members": floor_members,
    "popular_tasks": get_popular_tasks(),
    "event_form":form,
  }, context_instance=RequestContext(request))