Add dependency storage (list of question IDs)
authorW. Trevor King <wking@tremily.us>
Tue, 5 Feb 2013 15:15:16 +0000 (10:15 -0500)
committerW. Trevor King <wking@tremily.us>
Tue, 5 Feb 2013 15:15:16 +0000 (10:15 -0500)
quiz.json
quizzer/question.py

index ea89d1d41f72b3e7353a1d2327b9f099c055916a..1789fd67d0be893eb82c9d691ec7dbe96ae4b1d4 100644 (file)
--- a/quiz.json
+++ b/quiz.json
@@ -9,17 +9,26 @@
                {
                        "prompt": "What is your quest?",
                        "answer": "To seek the Holy Grail",
-                       "hint": "Think like a Pythonista"
+                       "hint": "Think like a Pythonista",
+                       "dependencies": [
+                               "What is your name?"
+                               ]
                },
                {
                        "prompt": "What is your favourite color?",
                        "answer": "Blue",
-                       "hint": "Channel Sir Lancelot"
+                       "hint": "Channel Sir Lancelot",
+                       "dependencies": [
+                               "What is your quest?"
+                               ]
                },
                {
                        "prompt": "What is the capital of Assyria?",
                        "answer": "I don't know that",
-                       "hint": "Sir Robin didn't know it either"
+                       "hint": "Sir Robin didn't know it either",
+                       "dependencies": [
+                               "What is your quest?"
+                               ]
                }
        ]
 }
index 411d5e54c4396208ed1158e2bc3293c4e118153f..065b17e86dbb80ad0438c0fe2172e6da3fa82b88 100644 (file)
@@ -1,11 +1,15 @@
 class Question (object):
-    def __init__(self, id=None, prompt=None, answer=None, help=None):
+    def __init__(self, id=None, prompt=None, answer=None, help=None,
+                 dependencies=None):
         if id is None:
             id = prompt
         self.id = id
         self.prompt = prompt
         self.answer = answer
         self.help = help
+        if dependencies is None:
+            dependencies = []
+        self.dependencies = dependencies
 
     def __getstate__(self):
         return {
@@ -13,11 +17,14 @@ class Question (object):
             'prompt': self.prompt,
             'answer': self.answer,
             'help': self.help,
+            'dependencies': self.dependencies,
             }
 
     def __setstate__(self, state):
         if 'id' not in state:
             state['id'] = state.get('prompt', None)
+        if 'dependencies' not in state:
+            state['dependencies'] = []
         self.__dict__.update(state)
 
     def check(self, answer):