diff options
-rw-r--r-- | yaksh/tasks.py | 37 | ||||
-rw-r--r-- | yaksh/templates/manage.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/grade_user.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/view_notifications.html | 4 | ||||
-rw-r--r-- | yaksh/test_views.py | 88 |
5 files changed, 49 insertions, 84 deletions
diff --git a/yaksh/tasks.py b/yaksh/tasks.py index c68faa9..1c4658b 100644 --- a/yaksh/tasks.py +++ b/yaksh/tasks.py @@ -4,7 +4,6 @@ from textwrap import dedent # Django and celery imports from celery import shared_task -from celery.utils.log import get_task_logger from django.urls import reverse from django.shortcuts import get_object_or_404 @@ -24,31 +23,31 @@ def regrade_papers(data): quiz_name = data.get("quiz_name") course_name = data.get("course_name") - logger = get_task_logger(__name__) + url = reverse("yaksh:grade_user", args=[quiz_id, course_id]) try: if answerpaper_id is not None and question_id is None: # Regrade specific user for all questions answerpaper = AnswerPaper.objects.get(id=answerpaper_id) + url = reverse("yaksh:grade_user", + args=[quiz_id, answerpaper.user_id, course_id]) for question in answerpaper.questions.all(): answerpaper.regrade(question.id) course_status = CourseStatus.objects.filter( user=answerpaper.user, course=answerpaper.course) if course_status.exists(): course_status.first().set_grade() - url = reverse("yaksh:grade_user", - args=[quiz_id, answerpaper.user_id, course_id]) elif answerpaper_id is not None and question_id is not None: # Regrade specific user for a specific question answerpaper = AnswerPaper.objects.get(pk=answerpaper_id) + url = reverse("yaksh:grade_user", + args=[quiz_id, answerpaper.user_id, course_id]) answerpaper.regrade(question_id) - course_status = CourseStatus.objects.filter(user=answerpaper.user, - course=answerpaper.course) + course_status = CourseStatus.objects.filter( + user=answerpaper.user, course=answerpaper.course) if course_status.exists(): course_status.first().set_grade() - url = reverse("yaksh:grade_user", - args=[quiz_id, answerpaper.user_id, course_id]) elif questionpaper_id is not None and question_id is not None: # Regrade all users for a specific question @@ -61,23 +60,23 @@ def regrade_papers(data): user=answerpaper.user, course=answerpaper.course) if course_status.exists(): course_status.first().set_grade() - url = reverse("yaksh:grade_user", args=[quiz_id, course_id]) message = dedent(""" - Quiz re-evaluation is complete Click <a href="{0}">here</a> to view + Quiz re-evaluation is complete. + Click <a href="{0}">here</a> to view """.format(url) ) - nm = NotificationMessage.objects.add_single_message( - user_id, "{0} re-evaluation status".format(quiz_name), - message, "success" - ) + notification_type = "success" except Exception as e: - nm = NotificationMessage.objects.add_single_message( - user_id, "{0} re-evaluation status".format(quiz_name), - "Unable to regrade {0}. Try again later".format(quiz_name), - "warning" + message = dedent(""" + Unable to regrade please try again. + Click <a href="{0}">here</a> to view""".format(url) ) - logger.error(e) + notification_type = "warning" + nm = NotificationMessage.objects.add_single_message( + user_id, "{0} re-evaluation status".format(quiz_name), + message, notification_type + ) notification = Notification.objects.add_single_notification( user_id, nm.id ) diff --git a/yaksh/templates/manage.html b/yaksh/templates/manage.html index 1b3527d..6047fc5 100644 --- a/yaksh/templates/manage.html +++ b/yaksh/templates/manage.html @@ -24,7 +24,7 @@ </li> <li class="nav-item"> <a class="nav-link" href="{% url 'yaksh:grade_user' %}"> - Grader + Quizzes </a> </li> </ul> diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html index 223ff36..fdfcc4e 100644 --- a/yaksh/templates/yaksh/grade_user.html +++ b/yaksh/templates/yaksh/grade_user.html @@ -126,7 +126,7 @@ $(document).ready(function() <div id="accordian-questions" class="card"> <div class="card-header"> <a class="card-link" data-toggle="collapse" href="#questions"> - Regrade all papers by Questions <i class="fa fa-angle-down"></i> + Regrade papers by questions <i class="fa fa-angle-down"></i> </a> </div> <div id="questions" class="collapse hide" data-parent="#accordion-questions"> diff --git a/yaksh/templates/yaksh/view_notifications.html b/yaksh/templates/yaksh/view_notifications.html index 72f90f8..48193ed 100644 --- a/yaksh/templates/yaksh/view_notifications.html +++ b/yaksh/templates/yaksh/view_notifications.html @@ -39,7 +39,9 @@ </a> </div> <div class="toast-body"> - <p><b>From: </b>{{message.creator.get_full_name}}</p> + {% if user.id != message.creator.id %} + <p><b>From: </b>{{message.creator.get_full_name}}</p> + {% endif %} <p><b>Description:</b></p> {{message.description|safe}} </div> diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 8f811c5..b137435 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -32,6 +32,8 @@ from yaksh.models import ( from yaksh.views import add_as_moderator from yaksh.decorators import user_has_profile +from notifications_plugin.models import Notification + class TestUserRegistration(TestCase): def setUp(self): @@ -575,9 +577,9 @@ class TestMonitor(TestCase): ) self.assertEqual(response.status_code, 404) - def test_monitor_display_quizzes(self): + def test_monitor_quiz_not_found(self): """ - Check all the available quizzes in monitor + Check if quiz is not found """ self.client.login( username=self.user.username, @@ -586,10 +588,7 @@ class TestMonitor(TestCase): response = self.client.get(reverse('yaksh:monitor'), follow=True ) - self.assertEqual(response.status_code, 200) - self.assertTemplateUsed(response, "yaksh/monitor.html") - self.assertEqual(response.context['objects'][0], self.course) - self.assertEqual(response.context['msg'], "Monitor") + self.assertEqual(response.status_code, 404) def test_monitor_display_quiz_results(self): """ @@ -3687,41 +3686,20 @@ class TestGrader(TestCase): AnswerPaper.objects.all().delete() self.mod_group.delete() - def test_grader_denies_anonymous(self): - # Given - redirect_destination = ('/exam/login/?next=/exam/manage/grader/') - - # When - response = self.client.get(reverse('yaksh:grader'), follow=True) - - # Then - self.assertRedirects(response, redirect_destination) - - def test_grader_denies_students(self): - # Given - self.client.login( - username=self.student.username, - password=self.student_plaintext_pass - ) - - # When - response = self.client.get(reverse('yaksh:grader'), follow=True) - - # Then - self.assertEqual(response.status_code, 404) - def test_regrade_denies_anonymous(self): # Given - url = "/exam/login/?next=/exam/manage/regrade/answerpaper" + url = "/exam/login/?next=/exam/manage/regrade/user/question" redirect_destination = ( - url + "/{}/{}/{}/".format( - self.course.id, self.question.id, self.answerpaper.id) + url + "/{}/{}/{}/{}/".format( + self.course.id, self.question_paper.id, + self.answerpaper.id, self.question.id) ) # When response = self.client.get( - reverse('yaksh:regrade', + reverse('yaksh:regrade_by_question', kwargs={'course_id': self.course.id, + 'questionpaper_id': self.question_paper.id, 'question_id': self.question.id, 'answerpaper_id': self.answerpaper.id}), follow=True @@ -3739,8 +3717,9 @@ class TestGrader(TestCase): # When response = self.client.get( - reverse('yaksh:regrade', + reverse('yaksh:regrade_by_question', kwargs={'course_id': self.course.id, + 'questionpaper_id': self.question_paper.id, 'question_id': self.question.id, 'answerpaper_id': self.answerpaper.id}), follow=True @@ -3749,21 +3728,6 @@ class TestGrader(TestCase): # Then self.assertEqual(response.status_code, 404) - def test_grader_by_moderator(self): - # Given - self.client.login( - username=self.user1.username, - password=self.user1_plaintext_pass - ) - - # When - response = self.client.get(reverse('yaksh:grader'), follow=True) - - # Then - self.assertEqual(response.status_code, 200) - self.assertTrue('courses' in response.context) - self.assertTemplateUsed(response, 'yaksh/regrade.html') - def test_regrade_by_moderator(self): # Given self.client.login( @@ -3773,44 +3737,43 @@ class TestGrader(TestCase): # When response = self.client.get( - reverse('yaksh:regrade', + reverse('yaksh:regrade_by_question', kwargs={'course_id': self.course.id, + 'questionpaper_id': self.question_paper.id, 'question_id': self.question.id, 'answerpaper_id': self.answerpaper.id}), follow=True) # Then + messages = [m.message for m in get_messages(response.wsgi_request)] self.assertEqual(response.status_code, 200) - self.assertTrue('courses' in response.context) - self.assertTrue('details' in response.context) - self.assertTemplateUsed(response, 'yaksh/regrade.html') + self.assertIn("demo quiz is submitted for re-evaluation", messages[0]) # When response = self.client.get( - reverse('yaksh:regrade', + reverse('yaksh:regrade_by_user', kwargs={'course_id': self.course.id, + 'questionpaper_id': self.question_paper.id, 'answerpaper_id': self.answerpaper.id}), follow=True) # Then + messages = [m.message for m in get_messages(response.wsgi_request)] self.assertEqual(response.status_code, 200) - self.assertTrue('courses' in response.context) - self.assertTrue('details' in response.context) - self.assertTemplateUsed(response, 'yaksh/regrade.html') + self.assertIn("demo quiz is submitted for re-evaluation", messages[0]) # When response = self.client.get( - reverse('yaksh:regrade', + reverse('yaksh:regrade_by_quiz', kwargs={'course_id': self.course.id, 'question_id': self.question.id, 'questionpaper_id': self.question_paper.id}), follow=True) # Then + messages = [m.message for m in get_messages(response.wsgi_request)] self.assertEqual(response.status_code, 200) - self.assertTrue('courses' in response.context) - self.assertTrue('details' in response.context) - self.assertTemplateUsed(response, 'yaksh/regrade.html') + self.assertIn("demo quiz is submitted for re-evaluation", messages[0]) def test_regrade_denies_moderator_not_in_course(self): # Given @@ -3822,8 +3785,9 @@ class TestGrader(TestCase): self.mod_group.user_set.remove(self.user2) # When response = self.client.get( - reverse('yaksh:regrade', + reverse('yaksh:regrade_by_question', kwargs={'course_id': self.course.id, + 'questionpaper_id': self.question_paper.id, 'question_id': self.question.id, 'answerpaper_id': self.answerpaper.id}), follow=True) |