summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrabhu Ramachandran2011-11-21 17:45:22 +0530
committerPrabhu Ramachandran2011-11-21 17:45:22 +0530
commitf2309db2490ec0bd5b910c5acd1dc18026a14306 (patch)
tree0cd0f97c1d65bb7dd6d79f493b781a7fd4aba504
parent4df6fb51be0661aaf0f852e4f2bedc2bb72e1eef (diff)
downloadonline_test-f2309db2490ec0bd5b910c5acd1dc18026a14306.tar.gz
online_test-f2309db2490ec0bd5b910c5acd1dc18026a14306.tar.bz2
online_test-f2309db2490ec0bd5b910c5acd1dc18026a14306.zip
ENH: Added an active attribute to Questions.
This allows us to enable/disable questions in a question paper. Only questions that are active are used to create a question paper. I've also modified the load_exam/load_questions_xml to deactivate rather than delete old questions.
-rw-r--r--exam/management/commands/load_exam.py5
-rw-r--r--exam/management/commands/load_questions_xml.py5
-rw-r--r--exam/models.py12
-rw-r--r--exam/views.py2
4 files changed, 16 insertions, 8 deletions
diff --git a/exam/management/commands/load_exam.py b/exam/management/commands/load_exam.py
index 157a94a..3f247a1 100644
--- a/exam/management/commands/load_exam.py
+++ b/exam/management/commands/load_exam.py
@@ -8,9 +8,10 @@ from django.core.management.base import BaseCommand
from exam.models import Question, Quiz
def clear_exam():
- """Delete all questions from the database."""
+ """Deactivate all questions from the database."""
for question in Question.objects.all():
- question.delete()
+ question.active = False
+ question.save()
# Deactivate old quizzes.
for quiz in Quiz.objects.all():
diff --git a/exam/management/commands/load_questions_xml.py b/exam/management/commands/load_questions_xml.py
index 1e9cfde..aa403dd 100644
--- a/exam/management/commands/load_questions_xml.py
+++ b/exam/management/commands/load_questions_xml.py
@@ -18,9 +18,10 @@ def decode_html(html_str):
lambda m: unichr(name2codepoint[m.group(1)]), html_str)
def clear_questions():
- """Delete all questions from the database."""
+ """Deactivate all questions from the database."""
for question in Question.objects.all():
- question.delete()
+ question.active = False
+ question.save()
def load_questions_xml(filename):
"""Load questions from the given XML file."""
diff --git a/exam/models.py b/exam/models.py
index 09529b9..fb06576 100644
--- a/exam/models.py
+++ b/exam/models.py
@@ -15,9 +15,11 @@ class Profile(models.Model):
################################################################################
class Question(models.Model):
"""A question in the database."""
- # An optional one-line summary of the question.
+
+ # A one-line summary of the question.
summary = models.CharField(max_length=256)
- # The question text.
+
+ # The question text, should be valid HTML.
description = models.TextField()
# Number of points for the question.
@@ -26,7 +28,11 @@ class Question(models.Model):
# Test cases for the question in the form of code that is run.
# This is simple Python code.
test = models.TextField()
-
+
+ # Is this question active or not. If it is inactive it will not be used
+ # when creating a QuestionPaper.
+ active = models.BooleanField(default=True)
+
def __unicode__(self):
return self.summary
diff --git a/exam/views.py b/exam/views.py
index 729b1e6..b880c4d 100644
--- a/exam/views.py
+++ b/exam/views.py
@@ -133,7 +133,7 @@ def start(request):
| stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR \
| stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP)
- questions = [ str(_.id) for _ in Question.objects.all() ]
+ questions = [ str(_.id) for _ in Question.objects.filter(active=True) ]
random.shuffle(questions)
new_paper.questions = "|".join(questions)