diff options
author | Greg S <enimihil@gmail.com> | 2009-04-01 16:45:59 (GMT) |
---|---|---|
committer | Greg S <enimihil@gmail.com> | 2009-04-01 16:45:59 (GMT) |
commit | 9287b97d1882e45e37b22a131e68a84c7136e965 (patch) | |
tree | 0169c3482dffbd6a963da5acddd703a8d0dc238c | |
parent | 0a2781f7a545f2242545a806fce7c745139a4f77 (diff) |
Skeleton of implementation.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | doc/quiz-api.rst | 16 | ||||
-rw-r--r-- | quizdata/__init__.py | 7 | ||||
-rw-r--r-- | quizdata/_format_gift.py | 6 | ||||
-rw-r--r-- | quizdata/_question.py | 63 | ||||
-rw-r--r-- | quizdata/_urlproc.py | 6 | ||||
-rw-r--r-- | quizdata/formats.py | 9 |
7 files changed, 100 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/doc/quiz-api.rst b/doc/quiz-api.rst index b810e2b..ba7e212 100644 --- a/doc/quiz-api.rst +++ b/doc/quiz-api.rst @@ -105,22 +105,22 @@ present and layout questions. type of question (multiple-choice/free-response) and handle the vents for those widgets. + :Question.response: + The answer the student has currently selected, or None if no + answer has been entered. + + :Question.submitted: + True if the student has submitted an answer for the Question, + False otherwise. + :Question.answered(): Returns True if the student has provided an answer for the Question. - :Question.submitted(): - Returns True if the student has submitted an answer for the - Question. - :Question.correct(): Returns True if the currently selected answer is correct for the Question. - :Question.answer(): - Returns the answer the student has currently selected, or None - if no answer has been entered. - :Question.clear(): Removes the widgets and drawings that show() set up, preparing the surface to receive the next question or other widgets. diff --git a/quizdata/__init__.py b/quizdata/__init__.py new file mode 100644 index 0000000..529d10c --- /dev/null +++ b/quizdata/__init__.py @@ -0,0 +1,7 @@ +''' + quizdata package +''' +from __future__ import absolute_import + +from ._question import Question +from ._urlproc import open diff --git a/quizdata/_format_gift.py b/quizdata/_format_gift.py new file mode 100644 index 0000000..527b2ab --- /dev/null +++ b/quizdata/_format_gift.py @@ -0,0 +1,6 @@ +''' + Parsing and support functions for the Moodle GIFT format. +''' + +def parse(text): + raise NotImplementedError() diff --git a/quizdata/_question.py b/quizdata/_question.py new file mode 100644 index 0000000..10f7c87 --- /dev/null +++ b/quizdata/_question.py @@ -0,0 +1,63 @@ +''' + quizdata.Question implementation and support functions +''' +from peak.util.symbols import Symbol + +TRUE_FALSE = Symbol('TRUE_FALSE', __name__) +MULTI_CHOICE = Symbol('MULTI_CHOICE', __name__) +SHORT_ANSWER = Symbol('SHORT_ANSWER', __name__) +MATCHING = Symbol('MATCHING', __name__) +MISSING_WORD = Symbol('MISSING_WORD', __name__) +NUMERICAL = Symbol('NUMERICAL', __name__) + +_FRIENDLY_NAMES = { + TRUE_FALSE : 'true/false', + MULTI_CHOICE : 'multiple choice', + SHORT_ANSWER : 'short answer', + MATCHING : 'matching', + MISSING_WORD : 'missing word', + NUMERICAL : 'numerical', + } + +class Question(object): + def __init__(self, text, type, answers=None, title=None, category=None, + diffculty=None, level=None, tags=None): + self.text = text + + if type not in [ TRUE_FALSE, MULTI_CHOICE, SHORT_ANSWER, MATCHING, + MISSING_WORD, NUMERICAL ]: + raise Exception("Type must be one of the defined question types") + self.type = type + + if answers is None and self.type != TRUE_FALSE: + raise Exception("Answers are required for questions of type %d" % self.type) + + if title is None: + self.title = self.text + + self.category = category + self.difficulty = difficulty + self.level = level + if tags is None: + self.tags = [] + + + self.submitted = False + self.response = None + + def show(self, surface, x, y, width=-1, height=-1): + raise NotImplementedError() + + def clear(self): + raise NotImplementedError() + + def answered(self): + return bool(self.response) + + def correct(self): + raise NotImplementedError() + + def __repr__(self): + return "<%s Question: %s>" % (_FRIENDLY_NAMES[self.type].title(), + self.title) + diff --git a/quizdata/_urlproc.py b/quizdata/_urlproc.py new file mode 100644 index 0000000..fc94cdc --- /dev/null +++ b/quizdata/_urlproc.py @@ -0,0 +1,6 @@ +''' + Module implementing the opening of a quizdata resource via URL. +''' + +def open(url, cached=False): + raise NotImplementedError() diff --git a/quizdata/formats.py b/quizdata/formats.py new file mode 100644 index 0000000..02a771c --- /dev/null +++ b/quizdata/formats.py @@ -0,0 +1,9 @@ +''' + Module defining the question data formats the quizdata API supports. +''' + +from ._format_gift import parse as parse_gift + +FORMATS = { + 'gift': parse_gift, + } |