Beispiel #1
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))
Beispiel #2
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,
  }
Beispiel #3
0
def _get_announcements(user):
  student = user
  if Util.is_in_group(user, 'Parent'):
    relations = ParentStudentRelation.objects.filter(parent=user)
    if relations:
      #TODO: should be querying for all children
      student = relations[0].student
  registrations = CourseRegistration.objects.filter(student=student)
  course_ids = []
  for reg in registrations:
    course_ids.append(reg.course.id)
  announcements = Announcement.objects.filter(course__id__in=course_ids).\
                                       order_by('-created_at') 
  return announcements
Beispiel #4
0
def index(req):
  # Default is teacher
  all_courses = Course.objects.all().order_by('-id')
  if Util.is_in_group(req.user, 'Student'):
    registered_courses = \
      CourseRegistration.objects.filter(student__id=req.user.id)
    course_ids = []
    for reg in registered_courses:
      course_ids.append(reg.course.id) 
    all_courses = Course.objects.filter(id__in=course_ids)
    
  return render_to_response('courses/index.html',
                            { 'all_courses': all_courses },
                            context_instance=RequestContext(req))
Beispiel #5
0
def index(req):
  children = None
  if Util.is_in_group(req.user, 'Parent'):
    relations = ParentStudentRelation.objects.filter(parent=req.user).\
                                              order_by('student')
    children = []
    for rel in relations:
      children.append(rel.student)

  announcements = _get_announcements(req.user)
  return render_to_response('main/index.html', {
                              'announcements': announcements,
                              'children': children,
                            },
                            context_instance=RequestContext(req))
Beispiel #6
0
def view(req):
  # get calendar titles for classes that this student is registered in
  #   if a teacher, display everything
  cal_user = req.user
  if Util.is_in_group(req.user, 'Teacher'):
    course_calendars = CourseCalendar.objects.all()
  else:
    if Util.is_in_group(req.user, 'Student'):
      registrations = CourseRegistration.objects.filter(student=req.user)
    else:
      relation = ParentStudentRelation.objects.filter(parent=req.user)
      if relation:
        cal_user = relation[0].student
        registrations = \
          CourseRegistration.objects.filter(student=relation[0].student)
      else:
        #TODO: should return error message here
        return HttpResponseRedirect('/')

    registered_courses = []
    for reg in registrations:
      registered_courses.append(reg.course)
    course_calendars = CourseCalendar.objects.filter(course__in=registered_courses)

  # get calendar ids and colors
  get_params = []
  for cal in course_calendars:
    get_params.append(__generate_get_params(cal.calendar_id, cal.calendar_color))
    
  # generate embeddable HTML for calendar
  html = __gen_embeddable_html(get_params)
  return render_to_response('schedule/view.html', {
                              'cal_html': html,
                              'cal_user': cal_user, 
                            },
                            context_instance=RequestContext(req))
Beispiel #7
0
def view_announcements(req):
  student = req.user
  if Util.is_in_group(req.user, 'Parent'):
    relations = ParentStudentRelation.objects.filter(parent=req.user)
    if relations:
      #TODO: should be querying for all children
      student = relations[0].student
  registrations = CourseRegistration.objects.filter(student=student)
  course_ids = []
  for reg in registrations:
    course_ids.append(reg.course.id)
  announcements = Announcement.objects.filter(course__id__in=course_ids).\
                                       order_by('-created_at') 

  return render_to_response('messaging/view_announcements.html', {
                              'announcements': announcements,
                            },
                            context_instance=RequestContext(req))
Beispiel #8
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,
  }
Beispiel #9
0
def index(req):
  if Util.is_in_group(req.user, 'Parent'): 
    relations = ParentStudentRelation.objects.filter(parent=req.user) 
    children = []
    for rel in relations:
      children.append(rel.student)
    children_grades = {} 
    for child in children:
      registrations = CourseRegistration.objects.filter(student=child)
      #
      # grades_by_class: {
      #   'class 1': {
      #     'grades': [34.5, null],
      #     'avg': "[34.5, 50.6]",
      #     'labels: "['Assignment 1', 'Asgn 2']
      #   }
      # }
      #
      grades_by_class = {}
      for reg in registrations:
        grades_by_class[reg.course.title] = {} 
        grades = Grade.objects.filter(gradeable__course=reg.course,
                                      student=child).\
                               order_by('created_at')
        gradeables = Gradeable.objects.filter(course=reg.course).\
                                       order_by('created_at')
        
        # create list of all grades by this student on this class
        x_labels = []
        grade_list = []
        for gradeable in gradeables:
          score = __get_score(gradeable, grades)
          grade_list.append(score)
          x_labels.append(gradeable.name)

        # calc class avg ordered by gradeables
        cls_avg = [] 
        for gradeable in gradeables:
          all_grades = Grade.objects.filter(gradeable=gradeable,
                                            gradeable__course=reg.course)
          sum_grades = 0
          for grade in all_grades:
            sum_grades += grade.score
          avg = sum_grades / len(all_grades)
          cls_avg.append(avg)

        # need to serialize to JSON format
        grades_by_class[reg.course.title]['grades'] = json.dumps(grade_list)
        grades_by_class[reg.course.title]['avg'] = json.dumps(cls_avg)
        grades_by_class[reg.course.title]['labels'] = json.dumps(x_labels)

      children_grades[child] = grades_by_class

      # For now, let's just return grade's of one child
      return render_to_response('stats/index.html', {
                                  'student': child,
                                  'grades_by_class': grades_by_class,
                                },
                                context_instance=RequestContext(req))
  else:
    #TODO: return error message here
    return HttpResponseRedirect('/')