diff options
author | Prabhu Ramachandran | 2016-02-18 18:33:07 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2016-02-18 18:33:07 +0530 |
commit | b1cb1ece826e39639d339f5dee71743044402b74 (patch) | |
tree | 53e15d2f377fa7008c1cc8576cc1e1a6348ed3e0 | |
parent | 7e10b82ed3bceb0a2327309f634f8e4d4f8ca27b (diff) | |
parent | ce4732b65c378a38cac5a504a606872ab25918ec (diff) | |
download | online_test-b1cb1ece826e39639d339f5dee71743044402b74.tar.gz online_test-b1cb1ece826e39639d339f5dee71743044402b74.tar.bz2 online_test-b1cb1ece826e39639d339f5dee71743044402b74.zip |
Merge pull request #74 from prathamesh920/monitorUI
Monitor shows latest attempt of a student for a given quiz
-rw-r--r-- | yaksh/templates/yaksh/grade_user.html | 12 | ||||
-rw-r--r-- | yaksh/templates/yaksh/monitor.html | 7 | ||||
-rw-r--r-- | yaksh/templates/yaksh/user_data.html | 15 | ||||
-rw-r--r-- | yaksh/urls.py | 4 | ||||
-rw-r--r-- | yaksh/views.py | 36 |
5 files changed, 53 insertions, 21 deletions
diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html index f0d9520..dd05670 100644 --- a/yaksh/templates/yaksh/grade_user.html +++ b/yaksh/templates/yaksh/grade_user.html @@ -27,11 +27,16 @@ Institute: {{ data.profile.institute }} <br/> {% for paper in data.papers %} +{% if forloop.counter == 2 and data.questionpaperid %} +<hr> +<u><h2> Previous attempts </h2></u> +{% endif %} {{ paper.total_marks }} <h2> Quiz: {{ paper.question_paper.quiz.description }} </h2> <p> +Attempt Number: {{ paper.attempt_number }}<br/> Questions correctly answered: {{ paper.get_answered_str }} <br/> Total attempts at questions: {{ paper.answers.count }} <br/> Marks obtained: {{ paper.get_total_marks }} <br/> @@ -56,7 +61,12 @@ Start time: {{ paper.start_time }} <br/> <h3> Answers </h3><br> <form name=frm id="q{{ paper.quiz.id }}_form" - action="{{URL_ROOT}}/exam/manage/gradeuser/{{data.user.username}}/" method="post"> + {% if data.questionpaperid %} + action="{{URL_ROOT}}/exam/manage/gradeuser/{{data.user.username}}/{{data.questionpaperid}}/" + {% else %} + action="{{URL_ROOT}}/exam/manage/gradeuser/{{data.user.username}}/" + {% endif %} + method="post"> {% csrf_token %} {% for question, answers in paper.get_question_answers.items %} diff --git a/yaksh/templates/yaksh/monitor.html b/yaksh/templates/yaksh/monitor.html index 7df0569..ecb8b42 100644 --- a/yaksh/templates/yaksh/monitor.html +++ b/yaksh/templates/yaksh/monitor.html @@ -38,7 +38,6 @@ {% if quiz %} {% if papers %} -{# <p> Quiz: {{ quiz_name }}</p> #} <p>Number of papers: {{ papers|length }} </p> <table border="1" cellpadding="3"> <tr> @@ -51,10 +50,10 @@ <th> Attempts </th> <th> Status </th> </tr> - {% for paper in papers %} + {% for paper in latest_attempts %} <tr> - <td> <a href="{{URL_ROOT}}/exam/manage/user_data/{{paper.user.username}}">{{ paper.user.get_full_name.title }}</a> </td> - <td> <a href="{{URL_ROOT}}/exam/manage/user_data/{{paper.user.username}}">{{ paper.user.username }}</a> </td> + <td> <a href="{{URL_ROOT}}/exam/manage/user_data/{{paper.user.username}}/{{paper.question_paper.id}}">{{ paper.user.get_full_name.title }}</a> </td> + <td> {{ paper.user.username }} </td> <td> {{ paper.user.profile.roll_number }} </td> <td> {{ paper.user.profile.institute }} </td> <td> {{ paper.get_answered_str }} </td> diff --git a/yaksh/templates/yaksh/user_data.html b/yaksh/templates/yaksh/user_data.html index 61a3a97..3350763 100644 --- a/yaksh/templates/yaksh/user_data.html +++ b/yaksh/templates/yaksh/user_data.html @@ -21,15 +21,24 @@ Last login: {{ data.user.last_login }} </p> {% if data.papers %} -<p><a href="{{URL_ROOT}}/exam/manage/gradeuser/{{ data.user.username }}/"> +{% if data.questionpaperid %} +<p><a href="{{URL_ROOT}}/exam/manage/gradeuser/{{ data.user.username }}/{{ data.questionpaperid }}"> Grade/correct paper</a> </p> +{% else %} +<p><a href="{{URL_ROOT}}/exam/manage/gradeuser/{{ data.user.username }}"> + Grade/correct paper</a> +{% endif %} {% for paper in data.papers %} - -<h2> Quiz: {{ paper.quiz.description }} </h2> +{% if forloop.counter == 2 and data.questionpaperid %} +<hr> +<U><h2> Previous attempts </h2></U> +{% endif %} +<h2> Quiz: {{ paper.question_paper.quiz.description }} </h2> <p> +Attempt Number: {{ paper.attempt_number }}<br/> Questions correctly answered: {{ paper.get_answered_str }} <br/> Total attempts at questions: {{ paper.answers.count }} <br/> Marks obtained: {{ paper.get_total_marks }} <br/> diff --git a/yaksh/urls.py b/yaksh/urls.py index 66159f0..61222b8 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -28,6 +28,8 @@ urlpatterns = patterns('yaksh.views', url(r'^manage/editquestion/$', 'edit_question'), url(r'^manage/addquiz/(?P<quiz_id>\d+)/$', 'add_quiz'), url(r'^manage/gradeuser/$', 'show_all_users'), + url(r'^manage/gradeuser/(?P<username>.*)/(?P<questionpaper_id>\d+)/$', + 'grade_user'), url(r'^manage/gradeuser/(?P<username>.*)/$', 'grade_user'), url(r'^manage/questions/$', 'show_all_questions'), url(r'^manage/showquiz/$', 'show_all_quiz'), @@ -36,6 +38,8 @@ urlpatterns = patterns('yaksh.views', url(r'^manage/showquestionpapers/(?P<questionpaper_id>\d+)/$',\ 'show_all_questionpapers'), url(r'^manage/monitor/(?P<questionpaper_id>\d+)/$', 'monitor'), + url(r'^manage/user_data/(?P<username>.*)/(?P<questionpaper_id>\d+)/$', + 'user_data'), url(r'^manage/user_data/(?P<username>.*)/$', 'user_data'), url(r'^manage/designquestionpaper/$', 'design_questionpaper'), url(r'^manage/designquestionpaper/(?P<questionpaper_id>\d+)/$',\ diff --git a/yaksh/views.py b/yaksh/views.py index 5c81eb8..755b33b 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -10,7 +10,7 @@ from django.contrib.auth import login, logout, authenticate from django.shortcuts import render_to_response, get_object_or_404, redirect from django.template import RequestContext from django.http import Http404 -from django.db.models import Sum +from django.db.models import Sum, Max from django.views.decorators.csrf import csrf_exempt from django.contrib.auth.decorators import login_required from taggit.models import Tag @@ -1188,20 +1188,30 @@ def monitor(request, questionpaper_id=None): papers = [] q_paper = None else: - papers = AnswerPaper.objects.filter(question_paper=q_paper).annotate( - total=Sum('answers__marks')).order_by('-total') - - context = {'papers': papers, 'quiz': q_paper, 'quizzes': None} + latest_attempts = [] + papers = AnswerPaper.objects.filter(question_paper=q_paper).order_by( + 'user__profile__roll_number') + users = papers.values_list('user').distinct() + for auser in users: + last_attempt = papers.filter(user__in=auser).aggregate( + last_attempt_num=Max('attempt_number')) + latest_attempts.append(papers.get(user__in=auser, + attempt_number=last_attempt['last_attempt_num'])) + context = {'papers': papers, 'quiz': q_paper, 'quizzes': None, + 'latest_attempts': latest_attempts,} return my_render_to_response('yaksh/monitor.html', context, context_instance=ci) -def get_user_data(username): +def get_user_data(username, questionpaper_id=None): """For a given username, this returns a dictionary of important data related to the user including all the user's answers submitted. """ user = User.objects.get(username=username) papers = AnswerPaper.objects.filter(user=user) + if questionpaper_id is not None: + papers = papers.filter(question_paper_id=questionpaper_id).order_by( + '-attempt_number') data = {} try: @@ -1212,6 +1222,7 @@ def get_user_data(username): data['user'] = user data['profile'] = profile data['papers'] = papers + data['questionpaperid'] = questionpaper_id return data @@ -1393,14 +1404,14 @@ def show_all_questions(request): @login_required -def user_data(request, username): +def user_data(request, username, questionpaper_id=None): """Render user data.""" current_user = request.user if not current_user.is_authenticated() or not is_moderator(current_user): raise Http404('You are not allowed to view this page!') - data = get_user_data(username) + data = get_user_data(username, questionpaper_id) context = {'data': data} return my_render_to_response('yaksh/user_data.html', context, @@ -1408,7 +1419,7 @@ def user_data(request, username): @login_required -def grade_user(request, username): +def grade_user(request, username, questionpaper_id=None): """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. """ @@ -1416,18 +1427,17 @@ def grade_user(request, username): ci = RequestContext(request) if not current_user.is_authenticated() or not is_moderator(current_user): raise Http404('You are not allowed to view this page!') - - data = get_user_data(username) + data = get_user_data(username, questionpaper_id) 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)) + marks = float(request.POST.get('q%d_marks' % question.id, 0)) last_ans = answers[-1] last_ans.marks = marks last_ans.save() paper.comments = request.POST.get( - 'comments_%d' % paper.question_paper.id) + 'comments_%d' % paper.question_paper.id, 'No comments') paper.save() context = {'data': data} |