summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/models.py63
-rw-r--r--yaksh/templates/manage.html15
-rw-r--r--yaksh/tests.py41
-rw-r--r--yaksh/views.py38
4 files changed, 79 insertions, 78 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 015916d..f1b0d33 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -69,11 +69,6 @@ class CourseManager(models.Manager):
trial_course.enroll(False, user)
return trial_course
- def delete_all_trial_courses(self, user):
- """Deletes all trial course for a user."""
- trial_course = self.filter(creator=user, is_trial=True)
- trial_course.delete()
-
###############################################################################
class Course(models.Model):
@@ -316,28 +311,27 @@ class QuizManager(models.Manager):
def create_trial_from_quiz(self, original_quiz_id, user, godmode):
"""Creates a trial quiz from existing quiz"""
- trial_quiz = self.get(id=original_quiz_id)
- trial_quiz.course.enroll(False, user)
- trial_quiz.pk = None
- trial_quiz.description += "_trial"
- trial_quiz.is_trial = True
- trial_quiz.time_between_attempts = 0
- trial_quiz.prerequisite = None
- if godmode:
- trial_quiz.duration = 1000
- trial_quiz.active = True
- trial_quiz.start_date_time = datetime.now()
- trial_quiz.end_date_time = datetime(2199, 1, 1, 0, 0, 0, 0)
- trial_quiz.save()
+ trial_quiz_name = "trial_orig_id_{0}".format(original_quiz_id)
+
+ if self.filter(description=trial_quiz_name).exists() and not godmode:
+ trial_quiz = self.get(description=trial_quiz_name)
+
+ else:
+ trial_quiz = self.get(id=original_quiz_id)
+ trial_quiz.course.enroll(False, user)
+ trial_quiz.pk = None
+ trial_quiz.description = trial_quiz_name
+ trial_quiz.is_trial = True
+ trial_quiz.time_between_attempts = 0
+ trial_quiz.prerequisite = None
+ if godmode:
+ trial_quiz.duration = 1000
+ trial_quiz.active = True
+ trial_quiz.start_date_time = timezone.now()
+ trial_quiz.end_date_time = datetime(2199, 1, 1, 0, 0, 0, 0)
+ trial_quiz.save()
return trial_quiz
- def delete_all_trial_quizzes(self, user):
- trial_quiz = self.filter(Q(course__creator=user) |
- Q(course__teachers=user), is_trial=True
- )
- trial_quiz.delete()
-
-
###############################################################################
class Quiz(models.Model):
"""A quiz that students will participate in. One can think of this
@@ -430,14 +424,17 @@ class QuestionPaperManager(models.Manager):
def create_trial_paper_to_test_quiz(self, trial_quiz, original_quiz_id):
"""Creates a trial question paper to test quiz."""
- trial_questionpaper, trial_questions = self._create_trial_from_questionpaper\
- (original_quiz_id)
- trial_questionpaper.quiz = trial_quiz
- trial_questionpaper.fixed_questions\
- .add(*trial_questions["fixed_questions"])
- trial_questionpaper.random_questions\
- .add(*trial_questions["random_questions"])
- trial_questionpaper.save()
+ if self.filter(quiz=trial_quiz).exists():
+ trial_questionpaper = self.get(quiz=trial_quiz)
+ else:
+ trial_questionpaper, trial_questions = self._create_trial_from_questionpaper\
+ (original_quiz_id)
+ trial_questionpaper.quiz = trial_quiz
+ trial_questionpaper.fixed_questions\
+ .add(*trial_questions["fixed_questions"])
+ trial_questionpaper.random_questions\
+ .add(*trial_questions["random_questions"])
+ trial_questionpaper.save()
return trial_questionpaper
diff --git a/yaksh/templates/manage.html b/yaksh/templates/manage.html
index 4b9e2ba..334f6a2 100644
--- a/yaksh/templates/manage.html
+++ b/yaksh/templates/manage.html
@@ -77,6 +77,21 @@
<h5>Click on the button given below to add a new course.</h5>
<button class="btn" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/add_course");'>Add New Course</button>
</center>
+ {% if trial_quiz %}
+ <h5/> You have trial papers.
+ <table class="bordered-table zebra-striped">
+ <form action="" method="post">
+ {% csrf_token %}
+ {% for quiz in trial_quiz %}
+ <tr>
+ <td> <input type = "checkbox" name="delete_quiz" value = {{quiz.id}}></input></td>
+ <td> <a href="{{URL_ROOT}}/exam/manage/gradeuser/{{quiz.id}}">{{quiz.description}}</td>
+ </tr>
+ {% endfor %}
+ </table>
+ <center><button class="btn" type="submit">Delete Selected</button></center>
+ </form>
+ {% endif %}
{% endblock %}
</div>
</div>
diff --git a/yaksh/tests.py b/yaksh/tests.py
index a5b02a6..bf3be04 100644
--- a/yaksh/tests.py
+++ b/yaksh/tests.py
@@ -204,7 +204,7 @@ class QuizTestCases(unittest.TestCase):
self.creator,
True
)
- self.assertEqual(trial_quiz.description, "demo quiz_trial")
+ self.assertEqual(trial_quiz.description, "trial_orig_id_1")
self.assertTrue(trial_quiz.is_trial)
self.assertEqual(trial_quiz.duration, 1000)
self.assertTrue(trial_quiz.active)
@@ -215,43 +215,22 @@ class QuizTestCases(unittest.TestCase):
def test_create_trial_from_quiz_usermode(self):
"""Test to check if a copy of original quiz is created in usermode"""
- trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz1.id,
+ trial_quiz = Quiz.objects.create_trial_from_quiz(self.quiz2.id,
self.creator,
False
)
- self.assertEqual(trial_quiz.description, "demo quiz_trial")
+ self.assertEqual(trial_quiz.description, "trial_orig_id_2")
self.assertTrue(trial_quiz.is_trial)
- self.assertEqual(trial_quiz.duration, self.quiz1.duration)
- self.assertEqual(trial_quiz.active, self.quiz1.active)
+ self.assertEqual(trial_quiz.duration, self.quiz2.duration)
+ self.assertEqual(trial_quiz.active, self.quiz2.active)
self.assertEqual(trial_quiz.start_date_time,
- self.quiz1.start_date_time
+ self.quiz2.start_date_time
)
self.assertEqual(trial_quiz.end_date_time,
- self.quiz1.end_date_time
+ self.quiz2.end_date_time
)
self.assertEqual(trial_quiz.time_between_attempts, 0)
- def test_delete_all_trial_quizzes_creator(self):
- Quiz.objects.create_trial_from_quiz(self.quiz1.id,
- self.creator,
- True
- )
- Quiz.objects.delete_all_trial_quizzes(self.creator)
- self.assertFalse(Quiz.objects.filter(course__creator=self.creator,
- is_trial=True).exists()
- )
-
- def test_delete_all_trial_quizzes_added_teacher(self):
- self.trial_course.add_teachers(self.teacher)
- Quiz.objects.create_trial_from_quiz(self.quiz1.id,
- self.creator,
- True
- )
- Quiz.objects.delete_all_trial_quizzes(self.teacher)
- self.assertFalse(Quiz.objects.filter(course__teachers=self.teacher,
- is_trial=True).exists()
- )
-
###############################################################################
class QuestionPaperTestCases(unittest.TestCase):
@@ -611,12 +590,6 @@ class CourseTestCases(unittest.TestCase):
)
self.assertTrue(trial_course.is_trial)
- def test_delete_all_trial_courses(self):
- Course.objects.create_trial_course(self.creator)
- Course.objects.delete_all_trial_courses(self.creator)
- self.assertFalse(Course.objects.filter(creator=self.creator,
- is_trial=True).exists())
-
###############################################################################
class TestCaseTestCases(unittest.TestCase):
diff --git a/yaksh/views.py b/yaksh/views.py
index 38d2a79..3db51a9 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -283,12 +283,20 @@ def prof_manage(request):
"""Take credentials of the user with professor/moderator
rights/permissions and log in."""
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
)
- trial_course = Course.objects.delete_all_trial_courses(user)
- trial_quiz = Quiz.objects.delete_all_trial_quizzes(user)
+ trial_quiz = Quiz.objects.filter(course__creator=user, is_trial=True)
+ if request.method == "POST":
+ delete_quiz = request.POST.getlist('delete_quiz')
+ for quiz_id in delete_quiz:
+ quiz = Quiz.objects.get(id=quiz_id)
+ if quiz.course.is_trial == True:
+ quiz.course.delete()
+ else:
+ quiz.delete()
users_per_paper = []
for paper in question_papers:
answer_papers = AnswerPaper.objects.filter(question_paper=paper)
@@ -298,8 +306,10 @@ rights/permissions and log in."""
passed=False).count()
temp = paper, answer_papers, users_passed, users_failed
users_per_paper.append(temp)
- context = {'user': user, 'users_per_paper': users_per_paper}
- return my_render_to_response('manage.html', context)
+ context = {'user': user, 'users_per_paper': users_per_paper,
+ 'trial_quiz': trial_quiz
+ }
+ return my_render_to_response('manage.html', context, context_instance=ci)
return my_redirect('/exam/login/')
@@ -354,6 +364,8 @@ def start(request, questionpaper_id=None, attempt_num=None):
return redirect("/exam/manage")
return redirect("/exam/quizzes")
if quest_paper.quiz.has_prerequisite() and not quest_paper.is_prerequisite_passed(user):
+ if is_moderator(user):
+ return redirect("/exam/manage")
return redirect("/exam/quizzes")
# if any previous attempt
last_attempt = AnswerPaper.objects.get_user_last_attempt(
@@ -362,6 +374,8 @@ def start(request, questionpaper_id=None, attempt_num=None):
return show_question(request, last_attempt.current_question(), last_attempt)
# allowed to start
if not quest_paper.can_attempt_now(user):
+ if is_moderator(user):
+ return redirect("/exam/manage")
return redirect("/exam/quizzes")
if attempt_num is None:
attempt_number = 1 if not last_attempt else last_attempt.attempt_number +1
@@ -848,15 +862,17 @@ def show_all_questions(request):
"{0}_questions.json"'.format(user)
return response
else:
- msg = "Please select atleast one question"
- context['msg'] = msg
+ context['msg'] = "Please select atleast one question to download"
if request.POST.get('test') == 'test':
question_ids = request.POST.getlist("question")
- trial_paper = test_mode(user, False, question_ids, None)
- trial_paper.update_total_marks()
- trial_paper.save()
- return my_redirect("/exam/start/1/{0}".format(trial_paper.id))
+ if question_ids:
+ trial_paper = test_mode(user, False, question_ids, None)
+ trial_paper.update_total_marks()
+ trial_paper.save()
+ return my_redirect("/exam/start/1/{0}".format(trial_paper.id))
+ else:
+ context["msg"] = "Please select atleast one question to test"
questions = Question.objects.filter(user_id=user.id)
form = QuestionFilterForm(user=user)
@@ -1189,7 +1205,7 @@ def allotted_courses(request):
@login_required
def remove_teachers(request, course_id):
""" remove user from a course """
-
+
user = request.user
if not is_moderator(user):
raise Http404('You are not allowed to view this page!')