Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/doc/new_format.rst
blob: 42a8cdfa7471a890e50875b4bdb0db04d6f30a42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Writing a New Format for the API
================================

Writing a new format plugin for the question API is simple.  All that needs to
happen is to insert a string -> function pair into the
``quizdata.formats.FORMATS`` dictionary. The function takes a file-like object
to the data and returns a list of questions.

The recommended implementation strategy is to make a module named
``_format_[formatname]`` in the ``quizdata`` package and import the
appropriate function in the ``quizdata.formats`` module to add to the
dictionary.

If parsing is required, the recommended tool is pyparsing, though XML/HTML
would be better served by using a library like BeautifulSoup.  

New Question Types
==================

New Question types can be implemented as subclasses of the base Question type,
or not.  So long as the generic functions dealing with questions are also
extended appropriately.   Adding a new type is best left as an exercise to
those reading the code, though it should be simple enough, as the required
behavior of a question object is minimal. (Additional behavior for specific
types of questions should be documented).