From 3375839bfc531329adc45994659be382295038b6 Mon Sep 17 00:00:00 2001 From: Prabhu Ramachandran Date: Fri, 25 Nov 2011 00:57:41 +0530 Subject: ENH: Adding a convenient grading interface. With this, you can grade a student's answer paper and give comments for each quiz paper they attempt. Also added a link to this grading interface to the user_data view. --- exam/urls.py | 1 + exam/views.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'exam') diff --git a/exam/urls.py b/exam/urls.py index 129a83f..34e329f 100644 --- a/exam/urls.py +++ b/exam/urls.py @@ -10,6 +10,7 @@ urlpatterns = patterns('exam.views', url(r'^monitor/$', 'monitor'), url(r'^monitor/(?P\d+)/$', 'monitor'), url(r'^user_data/(?P[a-zA-Z0-9_.]+)/$', 'user_data'), + url(r'^grade_user/(?P[a-zA-Z0-9_.]+)/$', 'grade_user'), url(r'^(?P\d+)/$', 'question'), url(r'^(?P\d+)/check/$', 'check'), ) diff --git a/exam/views.py b/exam/views.py index 1f92553..cd91ef8 100644 --- a/exam/views.py +++ b/exam/views.py @@ -311,3 +311,31 @@ def user_data(request, username): return my_render_to_response('exam/user_data.html', context, context_instance=RequestContext(request)) +def grade_user(request, username): + """Present an interface with which we can easily grade a user's papers + and update all their marks and also give comments for each paper. + """ + current_user = request.user + if not current_user.is_authenticated() and not current_user.is_staff: + raise Http404('You are not allowed to view this page!') + + data = get_user_data(username) + if request.method == 'POST': + papers = data['papers'] + for paper in papers: + for question, answers in paper.get_question_answers().iteritems(): + marks = float(request.POST.get('q%d_marks'%question.id)) + last_ans = answers[-1] + last_ans.marks = marks + last_ans.save() + paper.comments = request.POST.get('comments_%d'%paper.quiz.id) + paper.save() + + context = {'data': data} + return my_render_to_response('exam/user_data.html', context, + context_instance=RequestContext(request)) + else: + context = {'data': data} + return my_render_to_response('exam/grade_user.html', context, + context_instance=RequestContext(request)) + -- cgit