summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authormahesh2016-04-27 00:13:49 +0530
committermahesh2016-05-04 11:21:46 +0530
commit6eab6722046625f8bc02966be6a32e1fd43b4ac4 (patch)
tree8b4f4931d2965ef608cdd15bb4540820f885d571 /yaksh/views.py
parent03f0aa839e4d91a3d83d68d5301f1425f18cca73 (diff)
downloadonline_test-6eab6722046625f8bc02966be6a32e1fd43b4ac4.tar.gz
online_test-6eab6722046625f8bc02966be6a32e1fd43b4ac4.tar.bz2
online_test-6eab6722046625f8bc02966be6a32e1fd43b4ac4.zip
modified grade user, get_user_data, user_data
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py75
1 files changed, 44 insertions, 31 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 5cc9f99..ff5ff7e 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -759,16 +759,17 @@ def monitor(request, questionpaper_id=None):
return my_render_to_response('yaksh/monitor.html', context,
context_instance=ci)
-
-def get_user_data(username, questionpaper_id=None):
+def get_user_data(user_id, questionpaper_id=None, attempt_number = 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)
+ user = User.objects.get(id=user_id)
papers = AnswerPaper.objects.filter(user=user)
- if questionpaper_id is not None:
- papers = papers.filter(question_paper_id=questionpaper_id).order_by(
+ if questionpaper_id and attempt_number is not None:
+ papers = papers.filter(question_paper_id=questionpaper_id, attempt_number = attempt_number).order_by(
'-attempt_number')
+ if attempt_number == None:
+ papers = papers.filter(question_paper_id=questionpaper_id).order_by("-attempt_number")
data = {}
profile = user.profile if hasattr(user, 'profile') else None
@@ -779,6 +780,7 @@ def get_user_data(username, questionpaper_id=None):
return data
+
@login_required
def show_all_users(request):
"""Shows all the users who have taken various exams/quiz."""
@@ -842,14 +844,12 @@ def show_all_questions(request):
context_instance=ci)
@login_required
-def user_data(request, username, questionpaper_id=None):
+def user_data(request, user_id, 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, questionpaper_id)
+ data = get_user_data(user_id, questionpaper_id)
context = {'data': data}
return my_render_to_response('yaksh/user_data.html', context,
@@ -901,9 +901,9 @@ def download_csv(request, questionpaper_id):
writer.writerow(row)
return response
-
@login_required
-def grade_user(request, username, questionpaper_id=None):
+def grade_user(request, quiz_id = None, user_id=None, attempt_number = 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.
"""
@@ -911,26 +911,39 @@ def grade_user(request, username, questionpaper_id=None):
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, 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, 0))
- last_ans = answers[-1]
- last_ans.marks = marks
- last_ans.save()
- paper.comments = request.POST.get(
- 'comments_%d' % paper.question_paper.id, 'No comments')
- paper.save()
-
- context = {'data': data}
- return my_render_to_response('yaksh/user_data.html', context,
- context_instance=ci)
- else:
- context = {'data': data}
- return my_render_to_response('yaksh/grade_user.html', context,
- context_instance=ci)
+
+ course_details =Course.objects.filter(creator = current_user)
+ context = {"course_details": course_details}
+
+ if quiz_id != None:
+ questionpaper_id = QuestionPaper.objects.filter(quiz_id = quiz_id).values("id")
+ user_details = AnswerPaper.objects.get_users_for_questionpaper(questionpaper_id)
+ context = {"users": user_details, "quiz_id": quiz_id}
+
+ if user_id !=None:
+ attempts = AnswerPaper.objects.get_user_all_attempts(questionpaper_id, user_id)
+
+ if attempt_number == None:
+ attempt_number = attempts[0].attempt_number
+
+ data = get_user_data(user_id, questionpaper_id, attempt_number)
+ 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, 0))
+ last_ans = answers[-1]
+ last_ans.marks = marks
+ last_ans.save()
+ paper.comments = request.POST.get(
+ 'comments_%d' % paper.question_paper.id, 'No comments')
+ paper.save()
+
+ context = {'data': data,"quiz_id": quiz_id, "users": user_details,
+ "attempts": attempts,"user_id":user_id
+ }
+
+ return my_render_to_response('yaksh/grade_user.html', context, context_instance=ci)
@csrf_exempt