diff options
author | Prabhu Ramachandran | 2011-11-19 16:08:05 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2011-11-19 16:08:05 +0530 |
commit | e263244c70e8c5db0bc89bfee84ce37fe8e40d16 (patch) | |
tree | bd0c511e9f1950ecce899033278430527a4a276f /exam | |
parent | db74ad784752eea326982c4e84faf9ec3768e006 (diff) | |
download | online_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')
-rw-r--r-- | exam/management/commands/load_exam.py (renamed from exam/management/commands/load_questions.py) | 23 | ||||
-rw-r--r-- | exam/models.py | 3 | ||||
-rw-r--r-- | exam/xmlrpc_clients.py | 2 |
3 files changed, 19 insertions, 9 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') diff --git a/exam/models.py b/exam/models.py index ea60f17..8fe803d 100644 --- a/exam/models.py +++ b/exam/models.py @@ -62,6 +62,9 @@ class Quiz(models.Model): # Description of quiz. description = models.CharField(max_length=256) + class Meta: + verbose_name_plural = "Quizzes" + def __unicode__(self): desc = self.description or 'Quiz' return '%s: on %s for %d minutes'%(desc, self.start_date, self.duration) diff --git a/exam/xmlrpc_clients.py b/exam/xmlrpc_clients.py index be2f8b1..5dc51c6 100644 --- a/exam/xmlrpc_clients.py +++ b/exam/xmlrpc_clients.py @@ -1,5 +1,5 @@ from xmlrpclib import ServerProxy -from ..settings import SERVER_PORT +from settings import SERVER_PORT # Connect to the python server. python_server = ServerProxy('http://localhost:%d'%(SERVER_PORT)) |