diff options
author | adityacp | 2017-04-04 16:16:56 +0530 |
---|---|---|
committer | adityacp | 2017-04-04 16:16:56 +0530 |
commit | e3d289ca93047a1632a74ecfd5bc996433f3edb4 (patch) | |
tree | fdb69660ba853c4186ae2ca593be9257789423a9 /yaksh | |
parent | 734ad94d177be8ad400eb6f97e98612ce099e56a (diff) | |
download | online_test-e3d289ca93047a1632a74ecfd5bc996433f3edb4.tar.gz online_test-e3d289ca93047a1632a74ecfd5bc996433f3edb4.tar.bz2 online_test-e3d289ca93047a1632a74ecfd5bc996433f3edb4.zip |
Change in views and urls
- Change monitor and grade_user function in views
- Change url to get quiz id instead of question paper id
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/urls.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 43 |
2 files changed, 26 insertions, 19 deletions
diff --git a/yaksh/urls.py b/yaksh/urls.py index ad58985..9108b7b 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -40,7 +40,7 @@ urlpatterns = [ url(r'^manage/showquestionpapers/$', views.show_all_questionpapers), url(r'^manage/showquestionpapers/(?P<questionpaper_id>\d+)/$',\ views.show_all_questionpapers), - url(r'^manage/monitor/(?P<questionpaper_id>\d+)/$', views.monitor), + url(r'^manage/monitor/(?P<quiz_id>\d+)/$', views.monitor), url(r'^manage/user_data/(?P<user_id>\d+)/(?P<questionpaper_id>\d+)/$', views.user_data), url(r'^manage/user_data/(?P<user_id>\d+)/$', views.user_data), diff --git a/yaksh/views.py b/yaksh/views.py index 2adc2c3..c5aeb1c 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -284,9 +284,11 @@ def prof_manage(request, msg=None): user = request.user ci = RequestContext(request) if user.is_authenticated() and is_moderator(user): - question_papers = QuestionPaper.objects.filter(quiz__course__creator=user, - quiz__is_trial=False - ) + question_papers = QuestionPaper.objects.filter( + Q(quiz__course__creator=user) | + Q(quiz__course__teachers=user), + quiz__is_trial=False + ) trial_paper = AnswerPaper.objects.filter(user=user, question_paper__quiz__is_trial=True ) @@ -306,9 +308,9 @@ def prof_manage(request, msg=None): for paper in question_papers: answer_papers = AnswerPaper.objects.filter(question_paper=paper) users_passed = AnswerPaper.objects.filter(question_paper=paper, - passed=True).count() + passed=True).distinct().count() users_failed = AnswerPaper.objects.filter(question_paper=paper, - passed=False).count() + passed=False).distinct().count() temp = paper, answer_papers, users_passed, users_failed users_per_paper.append(temp) context = {'user': user, 'users_per_paper': users_per_paper, @@ -759,7 +761,7 @@ def show_statistics(request, questionpaper_id, attempt_number=None): @login_required -def monitor(request, questionpaper_id=None): +def monitor(request, quiz_id=None): """Monitor the progress of the papers taken so far.""" user = request.user @@ -767,14 +769,12 @@ def monitor(request, questionpaper_id=None): if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page!') - if questionpaper_id is None: - q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user) | - Q(quiz__course__teachers=user), - quiz__is_trial=False - ).distinct() - context = {'papers': [], - 'quiz': None, - 'quizzes': q_paper} + if quiz_id is None: + course_details = Course.objects.filter(Q(creator=user) | + Q(teachers=user), + is_trial=False).distinct() + context = {'papers': [], "course_details": course_details, + "msg": "Monitor"} return my_render_to_response('yaksh/monitor.html', context, context_instance=ci) # quiz_id is not None. @@ -782,7 +782,10 @@ def monitor(request, questionpaper_id=None): q_paper = QuestionPaper.objects.filter(Q(quiz__course__creator=user) | Q(quiz__course__teachers=user), quiz__is_trial=False, - id=questionpaper_id).distinct() + quiz_id=quiz_id).distinct() + quiz = get_object_or_404(Quiz, id=quiz_id) + if not quiz.course.is_creator(user) and not quiz.course.is_teacher(user): + raise Http404('This course does not belong to you') except QuestionPaper.DoesNotExist: papers = [] q_paper = None @@ -797,8 +800,8 @@ def monitor(request, questionpaper_id=None): 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,} + context = {'papers': papers, "quiz": quiz, "msg": "Quiz Results", + 'latest_attempts': latest_attempts} return my_render_to_response('yaksh/monitor.html', context, context_instance=ci) @@ -1082,7 +1085,11 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): .values("id") user_details = AnswerPaper.objects\ .get_users_for_questionpaper(questionpaper_id) - context = {"users": user_details, "quiz_id": quiz_id} + quiz = get_object_or_404(Quiz, id=quiz_id) + if not quiz.course.is_creator(current_user) and not \ + quiz.course.is_teacher(current_user): + raise Http404('This course does not belong to you') + context = {"users": user_details, "quiz_id": quiz_id, "quiz": quiz} if user_id is not None: attempts = AnswerPaper.objects.get_user_all_attempts\ |