summaryrefslogtreecommitdiff
path: root/exam/management
diff options
context:
space:
mode:
authorPrabhu Ramachandran2011-11-19 16:08:05 +0530
committerPrabhu Ramachandran2011-11-19 16:08:05 +0530
commite263244c70e8c5db0bc89bfee84ce37fe8e40d16 (patch)
treebd0c511e9f1950ecce899033278430527a4a276f /exam/management
parentdb74ad784752eea326982c4e84faf9ec3768e006 (diff)
downloadonline_test-e263244c70e8c5db0bc89bfee84ce37fe8e40d16.tar.gz
online_test-e263244c70e8c5db0bc89bfee84ce37fe8e40d16.tar.bz2
online_test-e263244c70e8c5db0bc89bfee84ce37fe8e40d16.zip
Changed load_questions to load_exam
Added option to define quizzes in the file we load from. Also fixed bug in import for the xmlrpc_clients.py and changed the verbose name for Quiz objects.
Diffstat (limited to 'exam/management')
-rw-r--r--exam/management/commands/load_exam.py (renamed from exam/management/commands/load_questions.py)23
1 files changed, 15 insertions, 8 deletions
diff --git a/exam/management/commands/load_questions.py b/exam/management/commands/load_exam.py
index 3906056..5b8aa81 100644
--- a/exam/management/commands/load_questions.py
+++ b/exam/management/commands/load_exam.py
@@ -5,17 +5,21 @@ from os.path import basename
from django.core.management.base import BaseCommand
# Local imports.
-from exam.models import Question
+from exam.models import Question, Quiz
-def clear_questions():
+def clear_exam():
"""Delete all questions from the database."""
for question in Question.objects.all():
question.delete()
+
+ for quiz in Quiz.objects.all():
+ quiz.delete()
-def load_questions(filename):
- """Load questions from the given Python file. The Python file should
- declare a list of name "questions" which define all the questions in pure
- Python.
+def load_exam(filename):
+ """Load questions and quiz from the given Python file. The Python file
+ should declare a list of name "questions" which define all the questions
+ in pure Python. It can optionally load a Quiz from an optional 'quiz'
+ object.
"""
# Simply exec the given file and we are done.
exec(open(filename).read())
@@ -26,6 +30,9 @@ def load_questions(filename):
for question in questions:
question.save()
+
+ if 'quiz' in locals():
+ quiz.save()
class Command(BaseCommand):
args = '<q_file1.py q_file2.py>'
@@ -35,11 +42,11 @@ class Command(BaseCommand):
def handle(self, *args, **options):
"""Handle the command."""
# Delete existing stuff.
- clear_questions()
+ clear_exam()
# Load from files.
for fname in args:
self.stdout.write('Importing from {0} ... '.format(basename(fname)))
- load_questions(fname)
+ load_exam(fname)
self.stdout.write('Done\n')