Ejemplo n.º 1
0
def sidebar(request):
  # TODO: order by course title
  if request.user.is_anonymous():
    return {}

  user_groups = request.user.groups.all()
  if user_groups:
    menus = NavigationTree.get_main_navi(user_groups)
  else:
    return {} 

  # check inbox
  unread_msg = Util.get_num_unread_msg(request.user)
  
  #TODO need a better way to check for groups
  if user_groups[0].name == 'Teacher': 
    #TODO: check which class this teacher belongs to 
    courses = Course.objects.all()
  elif user_groups[0].name == 'Student':
    regs = CourseRegistration.objects.filter(student=request.user)
    course_ids = []
    for reg in regs:
      course_ids.append(reg.course.id)
    courses = Course.objects.filter(id__in=course_ids)
  else:
    courses = []

  return {
    'courses': courses,
    'menus': menus,
    'unread_msg': unread_msg,
  }
Ejemplo n.º 2
0
def detail(req, course_id):
  default_url = req.GET.get('url')
  default_selected_id = "view_grades"
  if not default_url:
    default_url = reverse('connectus.courses.views.grades',
                          args=[course_id])
    if Util.is_in_group(req.user, 'Student'):
      default_url = reverse('connectus.courses.views.view_own_grades',
                            args=[course_id])

  try:
    view_func, args, kwargs = resolve(default_url)
    view_name = Util.construct_module_name(view_func)
    selected_cls_menu_id = \
      ViewMenuMapping.class_submenu_mapping.get(view_name, default_selected_id)
  except:
    selected_cls_menu_id = default_selected_id 

  course = Course.objects.get(id=course_id)
  #TODO: change default by passing view name through GET param
  permitted_actions = NavigationTree.get_class_detail(req.user.groups.all())
  return render_to_response('courses/grades.html', {
                              'course_id': course_id,
                              'course_title': course.title,
                              'default_url': default_url,
                              'permitted_actions': permitted_actions,
                              'selected_cls_menu_id': selected_cls_menu_id,
                            },
                            context_instance=RequestContext(req))
Ejemplo n.º 3
0
def navigation_view_solver(request):
  view_func, args, kwargs = resolve(request.path)
  view_name = Util.construct_module_name(view_func)
  selected_id = ViewMenuMapping.mapping.get(view_name, '')
  # construct navigation tree path
  tree_path = NavigationTree.get_nav_tree_path(view_name)
  reversed_tree_path = reverse_path(tree_path, kwargs.values())
  # presumably, if we can't find a path for this view, we're actually
  # coming from a view that we recognize 
  if not reversed_tree_path:
    last = NavTreeState.get_last()
    # worse case, we can't recognize a view name and we dont have any prev state
    # use Home in tree 
    reversed_tree_path = last if last else [('Home', '/')] 
  else:
    NavTreeState.save(reversed_tree_path)
  if kwargs and selected_id.endswith('_'):
    if len(kwargs) == 1:
      selected_id += kwargs.values()[0]
  return {
    'selected_id': selected_id,
    'tree_path': reversed_tree_path,
  }