Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg S <enimihil@gmail.com>2009-04-28 05:45:50 (GMT)
committer Greg S <enimihil@gmail.com>2009-04-28 05:45:50 (GMT)
commit70c921743862d622a1ae049b6d3c225a1ef736f5 (patch)
tree3e20b6817806c2bd65a852d1ac6b0c4490957ff3
parenta4b2efd6002ed877a8138899f7be9da6ddf3b250 (diff)
Starting to document question types.
-rw-r--r--quizdata/question.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/quizdata/question.py b/quizdata/question.py
index f0efcac..7c20a28 100644
--- a/quizdata/question.py
+++ b/quizdata/question.py
@@ -6,23 +6,47 @@ class Question(object):
Base question type, abstract.
'''
def __init__(self, *args, **kwargs):
+ '''
+ Takes all a the data elements for the construction of the question
+ object.
+
+ :Parameters:
+ title : str or unicode
+ the title of the question. optional. if not supplied, set
+ to None.
+ markup_type : type or factory
+ the type used to coerce or adapt the raw 'markup' supplied
+ by the backend to the correct format for use by the
+ application. if not supplied a default of 'str' is used.
+ text : str or unicode
+ the text of the question, assigned the result of
+ markup_type(text)
+ tags : list of str or unicode
+ a list of textual tags used to categorize or filter the
+ question.
+ '''
if 'title' in kwargs:
self.title = kwargs['title']
+ else:
+ self.title = None
+
if 'markup_type' in kwargs:
self.markup_type = kwargs['markup_type']
else:
self.markup_type = str
+
if 'text' in kwargs:
- if hasattr(self, 'markup_type'):
- self.title = self.markup_type(kwargs['text'])
- self.title = kwargs['text']
+ self.title = self.markup_type(kwargs['text'])
else:
raise Exception("Questions must have text!")
+
if 'tags' in kwargs:
self.tags = kwargs['tags']
+ else:
+ self.tags = []
def __repr__(self):
- if hasattr(self, 'title'):
+ if self.title:
txt = self.title
else:
txt = self.text
@@ -38,6 +62,7 @@ class MultipleChoiceQuestion(Question):
self.answers.append(self.markup_type(ans))
else:
raise Exception("MultipleChoiceQuestion requires answers!")
+
if 'correct' in kwargs:
self.correct = self.markup_type(kwargs['correct'])
else: