question: Use Question._state_attributes in __init__ and __setstate__
authorW. Trevor King <wking@tremily.us>
Tue, 5 Feb 2013 16:39:43 +0000 (11:39 -0500)
committerW. Trevor King <wking@tremily.us>
Tue, 5 Feb 2013 16:39:43 +0000 (11:39 -0500)
quizzer/question.py

index f2e8ed037cb725f24189ad1b088b3665040b78cc..7cebd3013c6e92722879f7bef22e3b3864f3a3f6 100644 (file)
@@ -14,17 +14,8 @@ class Question (object):
         'dependencies',
         ]
 
-    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 __init__(self, **kwargs):
+        self.__setstate__(kwargs)
 
     def __str__(self):
         return '<{} id:{!r}>'.format(type(self).__name__, self.id)
@@ -42,6 +33,9 @@ class Question (object):
             state['id'] = state.get('prompt', None)
         if 'dependencies' not in state:
             state['dependencies'] = []
+        for attr in self._state_attributes:
+            if attr not in state:
+                state[attr] = None
         self.__dict__.update(state)
 
     def check(self, answer):