summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/urls.py3
-rw-r--r--yaksh/views.py22
2 files changed, 14 insertions, 11 deletions
diff --git a/yaksh/urls.py b/yaksh/urls.py
index ea6f5e8..096f582 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -50,7 +50,8 @@ urlpatterns = patterns('yaksh.views',
url(r'^manage/designquestionpaper/manual$', 'manual_questionpaper'),
url(r'^manage/designquestionpaper/manual/(?P<questionpaper_id>\d+)/$',\
'manual_questionpaper'),
- url(r'^manage/statistics/question/(?P<questionpaper_id>\d+)/$','statistics'),
+ url(r'^manage/statistics/question/(?P<questionpaper_id>\d+)/$',
+ 'show_statistics'),
url(r'^ajax/questionpaper/(?P<query>.+)/$', 'ajax_questionpaper'),
url(r'^ajax/questions/filter/$', 'ajax_questions_filter'),
diff --git a/yaksh/views.py b/yaksh/views.py
index 4724f98..bbab12f 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1164,32 +1164,36 @@ def complete(request, reason=None, attempt_num=None, questionpaper_id=None):
else:
return my_redirect('/exam/')
+
@login_required
-def statistics(request, questionpaper_id):
+def show_statistics(request, questionpaper_id):
user = request.user
if not is_moderator(user):
raise Http404('You are not allowed to view this page')
questions_answered = []
question_stats = {}
papers = AnswerPaper.objects.filter(question_paper_id=questionpaper_id,
- status='completed')
+ status='completed')
+ total_attempt = papers.count()
+ if total_attempt == 0:
+ return my_redirect('/exam/manage/')
for paper in papers:
questions_answered += paper.questions_answered.split('|')
quiz_name = paper.question_paper.quiz.description
questions_answered = collections.Counter(map(int, filter(None,
- questions_answered)))
- total_attempt = papers.count()
- questions = Question.objects.filter(id__in=paper.questions.split('|')).\
- order_by('type')
+ questions_answered)))
+ questions = Question.objects.filter(
+ id__in=paper.questions.split('|')
+ ).order_by('type')
for question in questions:
if question.id in questions_answered:
question_stats[question] = questions_answered[question.id]
else:
question_stats[question] = 0
context = {'question_stats': question_stats, 'quiz_name': quiz_name,
- 'total': total_attempt}
+ 'total': total_attempt}
return my_render_to_response('yaksh/statistics_question.html', context,
- context_instance=RequestContext(request))
+ context_instance=RequestContext(request))
@login_required
@@ -1547,5 +1551,3 @@ def design_questionpaper(request):
context = {'form': form}
return my_render_to_response('yaksh/design_questionpaper.html',
context, context_instance=ci)
-
-