From: W. Trevor King Date: Tue, 5 Feb 2013 15:15:16 +0000 (-0500) Subject: Add dependency storage (list of question IDs) X-Git-Tag: v0.1~68 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=31a37086df83562f1c955ca68d4ea50f2a7cb7bd;p=quizzer.git Add dependency storage (list of question IDs) --- diff --git a/quiz.json b/quiz.json index ea89d1d..1789fd6 100644 --- 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?" + ] } ] } diff --git a/quizzer/question.py b/quizzer/question.py index 411d5e5..065b17e 100644 --- a/quizzer/question.py +++ b/quizzer/question.py @@ -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):