Exemplo n.º 1
0
def view_exam(request, course_id, exam_id):
    variables = { 'user' : request.user }
    if not request.user.is_staff:
        variables['importantMessage'] = "You need to be a TA or Instructor."
    else:
        course = Course.objects.get(pk=course_id)
        exam = Exam.objects.get(pk=exam_id, course=course)
        variables['course'] = course
        variables['exam'] = exam
        if request.method == 'POST':
            form = GradeExamForm(request.POST)
            variables['form'] = form
            if form.is_valid():
                first = form.cleaned_data['firstName']
                last = form.cleaned_data['lastName']
                cu_id = form.cleaned_data['cu_id']
                score = form.cleaned_data['score']
                recorded_course = form.cleaned_data['course']
                ta = form.cleaned_data['ta']
                try:

                    students = get_all_user_matches(first, last, cu_id)
                    if students is None or len(students) != 1:
                        variables['importantMessage'] = "Not found or not unique"
                        variables['disambiguate'] = students
                    else:
                        student = students.pop()
                        exam_result = get_existing_exam_result(exam, student)
                        if exam_result is not None:
                            variables['importantMessage'] = "Already have a score. Fix in admin UI."
                        else:
                            exam_result = insert_grade(exam, student, score, recorded_course, ta)
                            variables['exam_result'] = exam_result
                            form = GradeExamForm(initial={'course' : course})                
                            variables['importantMessage'] = "Added score for " + student.first_name + " " + student.last_name + " <" + student.get_profile().cu_id + "> = " + str(score)
                    form = GradeExamForm(initial={'course' : course})
                    
                    variables['form'] = form
                except Exception as ex:
                    print ex
                    variables['importantMessage'] = "WHAT?"
            else:
                variables['importantMessage'] = "Got invalid data."
        else:
            form = GradeExamForm(initial={'course' : course})
            variables['form'] = form

        all_results = ExamResult.objects.filter(exam=exam)
        variables['all_results'] = all_results
        how_many = all_results.count()
        variables['how_many'] = how_many
        worst = all_results.aggregate(Min('score'), Max('score'), Avg('score'), StdDev('score'))
        variables['worst'] = worst['score__min']
        variables['best'] = worst['score__max']
        variables['avg'] = worst['score__avg']
        variables['std_dev'] = worst['score__stddev']

    return render(request, 'homework/exam_all.html', variables)
Exemplo n.º 2
0
def get_student(first, last, sid):
    ret = None
    try:
        users = get_all_user_matches(first, last, sid)
        if len(users) == 1:
            ret = users.pop()
    except:
        pass
    return ret