diff options
-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 | ||||
-rw-r--r-- | sample_questions.py | 9 |
4 files changed, 26 insertions, 11 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)) diff --git a/sample_questions.py b/sample_questions.py index 76d64c7..c77eb9d 100644 --- a/sample_questions.py +++ b/sample_questions.py @@ -1,4 +1,4 @@ -from exam.models import Question +from datetime import date questions = [ Question( @@ -23,4 +23,9 @@ import math assert sqr(3) == 9 assert abs(sqr(math.sqrt(2)) - 2.0) < 1e-14 '''), -]
\ No newline at end of file +] + +quiz = Quiz(start_date=date.today(), + duration=10, + description='Basic Python Quiz 1' + ) |