quiz: Add Quiz.introduction for an optional intro message
authorW. Trevor King <wking@tremily.us>
Thu, 14 Feb 2013 14:16:18 +0000 (09:16 -0500)
committerW. Trevor King <wking@tremily.us>
Thu, 14 Feb 2013 14:16:18 +0000 (09:16 -0500)
quizzer/quiz.py
quizzer/ui/cli.py
quizzes/git.json
quizzes/monty-python.json
quizzes/posix-shell.json
quizzes/posix-utilities.json

index 2ecf2ec23155f4abc973052b7dd275e0bc8be386..f1aed0038bf99a915c0eff2e5ee732193282ef4a 100644 (file)
@@ -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:
index 60ce8968df1b2b7f3217e7c826a4eadb346f43fe..7d7c70117907c889e417927cf9ed9a8ba6377c91 100644 (file)
@@ -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()
index eb841b3fd4cdf784f712d76d615305c6a1f9d83c..20c7aafcd2f32e3ee41d94e54311841017367ca2 100644 (file)
@@ -1,5 +1,6 @@
 {
        "version": "0.1",
+       "introduction": "Test your knowledge of the Git version control system.",
        "questions": [
                {
                        "class": "ScriptQuestion",
index 13d62103af66e6839228982f803321fa68e9c4d2..882af9695b2ea59bdc1b6d9583500e53e52d81ee 100644 (file)
@@ -1,5 +1,6 @@
 {
        "version": "0.1",
+       "introduction": "Test your knowledge of Monty Python and the Holy Grail!",
        "questions": [
                {
                        "class": "ChoiceQuestion",
index 96d8a59894f6ba320c0f725cd6c5f31545a2e1fd..693f6e34759e34df5afc2e8c5f1b04b4e1cdc2fa 100644 (file)
@@ -1,5 +1,6 @@
 {
        "version": "0.1",
+       "introduction": "Test your knowledge of the POSIX shell.",
        "questions": [
                {
                        "class": "ScriptQuestion",
index 1cb4f9293f6dc45bc51d90160f3c8d41555b8ced..a7b6481757866ef9ea3db2b9d6d621054479a476 100644 (file)
@@ -1,5 +1,6 @@
 {
        "version": "0.1",
+       "introduction": "Test your knowledge of POSIX utilities.",
        "questions": [
                {
                        "class": "ScriptQuestion",