示例#1
0
def student(request):
    if is_teacher(request.user):
        return teacher(request)

    student_courses = StudentCourses.objects.filter(student__person__username=request.user.username)
    return render_to_response('myexams/student.html',
        {'student_courses': student_courses, 'user': request.user})
示例#2
0
def exams(request, exam_id):

    if is_teacher(request.user):
        return teacher(request)

    exam = Exam.objects.get(pk=exam_id)
    return render_to_response('myexams/exam.html',
        {'exam': exam, 'user': request.user},
        context_instance=RequestContext(request))
示例#3
0
def new(request, course_id):

        if not is_teacher(request.user):
                return index(request)

        exam = Exam()
        exam.course__id = course_id
        exam.name = ""
        exam.date_created = datetime.datetime.now()
        exam.return_date = datetime.datetime.now() + datetime.timedelta(days=7)
        return render_to_response('myexams/new_exam.html',
            {'exam': exam}, context_instance=RequestContext(request))
示例#4
0
def create(request):

    if not is_teacher(request.user):
            return index(request)

    exam = Exam()
    exam.course_id = request.POST['id']
    exam.exam_name = request.POST['exam_name']
    exam.date_created = datetime.datetime.now()
    exam.return_date = request.POST['exam_return_date']
    exam.save()

    q_count = 1
    #find posted questions
    while(True):
        que_post = 'question_' + str(q_count)
        if que_post in request.POST:
            web_question = request.POST[que_post]
            question_value = request.POST['val_' + que_post]
            question = exam.question_set.create(question=web_question, number=q_count, value=question_value)
            a_count = 1
            #find posted answers
            while(True):
                ans_post = 'answer_' + str(q_count) + '_' + str(a_count)
                if ans_post in request.POST:
                    print ans_post
                    web_answer = request.POST[ans_post]

                    #check if answer is correct
                    correct = False
                    chk_post = 'answer_ck_' + str(q_count) + '_' + str(a_count)
                    if chk_post in request.POST:
                        correct = True

                    question.answer_set.create(answer=web_answer, number=0, is_correct=correct)
                else:
                    break
                a_count += 1
        else:
            break
        q_count += 1

    exam.save()

    return HttpResponseRedirect(reverse('myexams.views.index'))
示例#5
0
def course(request, course_id):
    if is_teacher(request.user):
        return teacher(request)

    exams = Exam.objects.filter(course__id=course_id)

    exams_taken = ExamsTaken.objects.filter(student__username=request.user.username)

    avg_grade = 0
    for exam_t in exams_taken:
        exams = exams.exclude(id=exam_t.exam.id)
        avg_grade += exam_t.exams_grade

    exams = exams.exclude(return_date__lte=datetime.datetime.now())
    len_exams_taken = len(exams_taken) if len(exams_taken) > 0 else 1

    avg_grade /= len_exams_taken
    c = Course.objects.get(pk=course_id)

    return render_to_response('myexams/course.html',
        {'course': c, 'exams': exams, 'user': request.user,
        'exams_taken': exams_taken, 'avg_grade': avg_grade})
示例#6
0
def index(request):
    # On index cheack if user is teacher or student
    if is_teacher(request.user):
        return teacher(request)
    else:
        return student(request)