summaryrefslogtreecommitdiff
path: root/exam
diff options
context:
space:
mode:
Diffstat (limited to 'exam')
-rw-r--r--exam/urls.py1
-rw-r--r--exam/views.py28
2 files changed, 29 insertions, 0 deletions
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<quiz_id>\d+)/$', 'monitor'),
url(r'^user_data/(?P<username>[a-zA-Z0-9_.]+)/$', 'user_data'),
+ url(r'^grade_user/(?P<username>[a-zA-Z0-9_.]+)/$', 'grade_user'),
url(r'^(?P<q_id>\d+)/$', 'question'),
url(r'^(?P<q_id>\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))
+