Table Architecture

This page describes the TBWiki table architecture

Table data is managed in the TBWiki with the table module.

Table types [edit section]

The table code recognizes three distinct table types:

Attribute databases consist of records which have name-value pairs. These are usually read from multiple TBWiki page files.

Row-column databases consist of values which are associated with each other by row and column (similar to a relational database). These are usually read from a single TBWiki page file Currently, the data is formatted in MoinMoin table markup.

Writing code to handle these two different types of tables is challenging.

commonalities and differences [edit section]

Here are some commonalities and differences between the two database types:

Another possible database is the web-scraped database.

This database has records and fields which are "scraped" from existing TBWiki pages or from external web sites.

Form creation [edit section]

The current table code can create simple data entry forms for a database that consists of fields on type "single-line text".

The current table code supports user-specified data entry forms.

Forms for displaying the database and for adding or editing records are expressed as multi-line strings with python string variables where the field values or field form elements are to be placed. The rest of the form is expressed in HTML (not TBWiki markup).

For example, if a database 'People' has 'Name' and 'Phone' fields, a form for outputting this could look like this:

"""<table>
<tr><td>Name</td><td>Phone</td></tr>
<tr><td>%(Name)s</td><td>%(Phone)s</td></tr>
</table>"""
[This example is not complete.]
How do you specify the start, record portion and end of a formspec??


A record data entry form might look like this:
Name: %(NameField)s
Phone: %(PhoneField)s
%(SaveButton)s %(CancelButton)s

Forms can be stored as TBWiki pages, with the names: PeopleAddForm or PeopleEditForm.

It would be nice to auto-detect form elements for checkboxes, radio buttons, selects, and multi-line text.

(Maybe use schema-by-example...???)

Schema determination [edit section]

Field names are autodetected from the table data itself.

Field attributes, such as type (which can influence the type of form element used for inputing that field), possible values, and others, are expressed in a configuration block. These are referred to internally as the field_db.

Here's a sample field_db block:

field=Description
type=TextArea

field=Status
type=Select
possible_values="""not done
in progress
done"""
colors="""not done:red
in progress:yellow
done:green"""

Field attributes [edit section]

Possible types are:

Field attributes currently implemented are:

Field color [edit section]

The syntax for colors is: colors="""<cexpr>:<color> <cexpr2>:<color2> ..."""

<cexpr> can be a straight value, or an boolean expression. If it is a boolean expression, it must start with an open paren, '(', and do some comparison on the variable 'value'. A <cexpr> which is a straight variable is converted into the expression: "(value=="<variable>")"

The following are some examples:

colors="""not done: red
done:green"""

colors="""(int(value)<5):green
(int(value)>=6):red"""

Field attributes that I've thought about, but are not implemented yet are:

Current Code [edit section]

table.py

functions:

New Code (Refactor ideas) [edit section]

Split code into:

Allow different presentation modules and different editing modules:

[Describe different interfaces here]

Interface A - between table.py and db [edit section]

Interface B - between db and tbwiki_engine [edit section]