From: W. Trevor King Date: Thu, 14 Feb 2013 14:16:18 +0000 (-0500) Subject: quiz: Add Quiz.introduction for an optional intro message X-Git-Tag: v0.2~6 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fed5dd705504c8641dd9303024c3d1b4fee0f58b;p=quizzer.git quiz: Add Quiz.introduction for an optional intro message --- diff --git a/quizzer/quiz.py b/quizzer/quiz.py index 2ecf2ec..f1aed00 100644 --- a/quizzer/quiz.py +++ b/quizzer/quiz.py @@ -22,7 +22,9 @@ from . import question as _question class Quiz (list): - def __init__(self, questions=None, path=None, encoding=None): + def __init__(self, introduction=None, questions=None, path=None, + encoding=None): + self.introduction = introduction if questions is None: questions = [] super(Quiz, self).__init__(questions) @@ -43,6 +45,7 @@ class Quiz (list): if version != __version__: raise NotImplementedError('upgrade from {} to {}'.format( version, __version__)) + self.introduction = data.get('introduction', None) for state in data['questions']: question_class_name = state.pop('class', 'Question') question_class = _question.QUESTION_CLASS[question_class_name] @@ -57,6 +60,7 @@ class Quiz (list): state['class'] = type(question).__name__ data = { 'version': __version__, + 'introduction': self.introduction, 'questions': questions, } with self._open(mode='w', **kwargs) as f: diff --git a/quizzer/ui/cli.py b/quizzer/ui/cli.py index 60ce896..7d7c701 100644 --- a/quizzer/ui/cli.py +++ b/quizzer/ui/cli.py @@ -42,6 +42,8 @@ class QuestionCommandLine (_cmd.Cmd): def __init__(self, ui): super(QuestionCommandLine, self).__init__() self.ui = ui + if self.ui.quiz.introduction: + self.intro = '\n\n'.join([self.intro, self.ui.quiz.introduction]) def preloop(self): self.question = self.ui.get_question() diff --git a/quizzes/git.json b/quizzes/git.json index eb841b3..20c7aaf 100644 --- a/quizzes/git.json +++ b/quizzes/git.json @@ -1,5 +1,6 @@ { "version": "0.1", + "introduction": "Test your knowledge of the Git version control system.", "questions": [ { "class": "ScriptQuestion", diff --git a/quizzes/monty-python.json b/quizzes/monty-python.json index 13d6210..882af96 100644 --- a/quizzes/monty-python.json +++ b/quizzes/monty-python.json @@ -1,5 +1,6 @@ { "version": "0.1", + "introduction": "Test your knowledge of Monty Python and the Holy Grail!", "questions": [ { "class": "ChoiceQuestion", diff --git a/quizzes/posix-shell.json b/quizzes/posix-shell.json index 96d8a59..693f6e3 100644 --- a/quizzes/posix-shell.json +++ b/quizzes/posix-shell.json @@ -1,5 +1,6 @@ { "version": "0.1", + "introduction": "Test your knowledge of the POSIX shell.", "questions": [ { "class": "ScriptQuestion", diff --git a/quizzes/posix-utilities.json b/quizzes/posix-utilities.json index 1cb4f92..a7b6481 100644 --- a/quizzes/posix-utilities.json +++ b/quizzes/posix-utilities.json @@ -1,5 +1,6 @@ { "version": "0.1", + "introduction": "Test your knowledge of POSIX utilities.", "questions": [ { "class": "ScriptQuestion",