summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testapp/exam/forms.py23
-rw-r--r--testapp/exam/models.py23
2 files changed, 44 insertions, 2 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py
index 7c66944..1f1a2af 100644
--- a/testapp/exam/forms.py
+++ b/testapp/exam/forms.py
@@ -27,6 +27,9 @@ QUESTION_TYPES = (
("mcq", "Multiple Choice"),
("code", "Code"),
)
+QUIZZES =[('select', 'Select a prerequisite quiz')]
+quizzes = Quiz.objects.all()
+QUIZZES = QUIZZES+[(quiz.id, quiz) for quiz in quizzes]
UNAME_CHARS = letters + "._" + digits
PWD_CHARS = letters + punctuation + digits
@@ -132,18 +135,31 @@ class QuizForm(forms.Form):
active = forms.BooleanField(required=False)
description = forms.CharField(max_length=256, widget=forms.Textarea\
(attrs={'cols': 20, 'rows': 1}))
+ pass_criteria = forms.FloatField(initial=40,
+ help_text='Will be taken as percentage')
+ language = forms.CharField(widget=forms.Select(choices=LANGUAGES))
+ prerequisite = forms.CharField(required=False,
+ widget=forms.Select(choices=QUIZZES))
def save(self):
start_date = self.cleaned_data["start_date"]
duration = self.cleaned_data["duration"]
active = self.cleaned_data['active']
description = self.cleaned_data["description"]
+ pass_criteria = self.cleaned_data["pass_criteria"]
+ language = self.cleaned_data["language"]
+ prerequisite = self.cleaned_data["prerequisite"]
+
new_quiz = Quiz()
new_quiz.start_date = start_date
new_quiz.duration = duration
new_quiz.active = active
new_quiz.description = description
+ new_quiz.pass_criteria = pass_criteria
+ new_quiz.language = language
+ if isinstance(prerequisite, int):
+ new_quiz.prerequisite_id = prerequisite
new_quiz.save()
@@ -191,3 +207,10 @@ class QuestionForm(forms.Form):
new_question.active = active
new_question.snippet = snippet
new_question.save()
+
+
+ class RandomQuestionForm(forms.Form):
+ question_type = forms.CharField(max_length=8, widget=forms.Select\
+ (choices=QUESTION_TYPES))
+ shuffle_questions = forms.BooleanField(required=False)
+
diff --git a/testapp/exam/models.py b/testapp/exam/models.py
index 42c5d5a..a6897a4 100644
--- a/testapp/exam/models.py
+++ b/testapp/exam/models.py
@@ -115,6 +115,15 @@ class Quiz(models.Model):
# Description of quiz.
description = models.CharField(max_length=256)
+ # Mininum passing percentage condition.
+ pass_criteria = models.FloatField("Passing percentage", default=40)
+
+ # List of prerequisite quizzes to be passed to take this quiz
+ prerequisite = models.ForeignKey("self", null=True)
+
+ # Programming language for a quiz
+ language = models.CharField(max_length=20, choices=LANGUAGES)
+
class Meta:
verbose_name_plural = "Quizzes"
@@ -137,6 +146,9 @@ class QuestionPaper(models.Model):
# Questions that will be fetched randomly from the Question Set.
random_questions = models.ManyToManyField("QuestionSet")
+ # Option to shuffle questions, each time a new question paper is created.
+ shuffle_questions = models.BooleanField(default=False)
+
# Total marks for the question paper.
total_marks = models.FloatField()
@@ -167,8 +179,9 @@ class QuestionPaper(models.Model):
+ datetime.timedelta(minutes=self.quiz.duration)
ans_paper.question_paper = self
questions = self._get_questions_for_answerpaper()
- question_ids = [str(x.id) for x in questions]
- shuffle(questions)
+ question_ids = [str(x.id) for x in questions]
+ if self.shuffle_questions:
+ shuffle(question_ids)
ans_paper.questions = "|".join(question_ids)
ans_paper.save()
return ans_paper
@@ -230,6 +243,12 @@ class AnswerPaper(models.Model):
# Teacher comments on the question paper.
comments = models.TextField()
+ # Result of the quiz, either PASS or FAIL.
+ result = models.CharField(max_length=4)
+
+ # Marks percent scored by the user
+ percent = models.FloatField(null=True)
+
def current_question(self):
"""Returns the current active question to display."""
qs = self.questions.split('|')