FrontPage 

TB Wiki

Login

Regression Test

Expected HTML for page "DocTables"


expected html
nothing
t1TBWiki includes a feature for very easy creation and editing of simple databases.  These are referred to as "tables".t
2<p>
3 
4<table align="right"><tr><td><div class="toc">
5Contents:
6<ul>
7  <li><a href="#Table_Data_Formats">Table&nbsp;Data&nbsp;Formats</a></li>
8  <ul>
9    <li><a href="#MoinMoin_Tables">MoinMoin&nbsp;Tables</a></li>
10    <li><a href="#Attribute_files">Attribute&nbsp;files</a></li>
11    <li><a href="#Inline_Tables">Inline&nbsp;Tables</a></li>
12    <li><a href="#Parsed_data_Tables">Parsed&nbsp;data&nbsp;Tables</a></li>
13    <li><a href="#TBWikiDB_Tables">TBWikiDB&nbsp;Tables</a></li>
14  </ul>
15  <li><a href="#Table_type_specifiers">Table&nbsp;type&nbsp;specifiers</a></li>
16  <ul>
17    <li><a href="#source_spec">source_spec</a></li>
18    <li><a href="#match_spec">match_spec</a></li>
19  </ul>
20  <li><a href="#Declaring_a_Table">Declaring&nbsp;a&nbsp;Table</a></li>
21  <ul>
22    <li><a href="#Macro_Syntax">Macro&nbsp;Syntax</a></li>
23    <li><a href="#Processor_Syntax_(with_examples)">Processor&nbsp;Syntax&nbsp;(with&nbsp;examples)</a></li>
24  </ul>
25  <li><a href="#Table_configuration">Table&nbsp;configuration</a></li>
26  <ul>
27    <li><a href="#field_attributes">field&nbsp;attributes</a></li>
28    <ul>
29      <li><a href="#dynamic_default_values">dynamic&nbsp;default&nbsp;values</a></li>
30      <li><a href="#color_specifiers">color&nbsp;specifiers</a></li>
31      <ul>
32        <li><a href="#field_attribute_samples">field&nbsp;attribute&nbsp;samples</a></li>
33      </ul>
34    </ul>
35    <li><a href="#Configuration_blocks">Configuration&nbsp;blocks</a></li>
36    <li><a href="#Query_blocks">Query&nbsp;blocks</a></li>
37  </ul>
38  <li><a href="#Views">Views</a></li>
39  <ul>
40    <li><a href="#Custom_forms_and_views">Custom&nbsp;forms&nbsp;and&nbsp;views</a></li>
41    <ul>
42      <li><a href="#View">View</a></li>
43      <li><a href="#Add_Form">Add&nbsp;Form</a></li>
44      <li><a href="#Edit_form">Edit&nbsp;form</a></li>
45    </ul>
46    <li><a href="#Field_format_strings_for_edit_forms">Field&nbsp;format&nbsp;strings&nbsp;for&nbsp;edit&nbsp;forms</a></li>
47    <li><a href="#Special_form_elements">Special&nbsp;form&nbsp;elements</a></li>
48  </ul>
49  <li><a href="#Spreadsheets">Spreadsheets</a></li>
50  <ul>
51    <li><a href="#formulas">formulas</a></li>
52    <li><a href="#cell_addressing">cell&nbsp;addressing</a></li>
53    <li><a href="#examples">examples</a></li>
54  </ul>
55  <li><a href="#Things_to_Describe">Things&nbsp;to&nbsp;Describe</a></li>
56  <ul>
57    <li><a href="#not_implemented_yet">not&nbsp;implemented&nbsp;yet</a></li>
58  </ul>
59</ul>
60</div></td></tr></table>
61<p>
62<h1><a name="Table_Data_Formats">Table Data Formats</a>
63<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Table_Data_Formats">edit section</a>]</font></span>
64</h1>
65Table data is stored in regular tbwiki pages. [FIXTHIS - maybe change this to a database directory?], or it can be parsed from an external source.
66For data in tbwiki pages, you can edit the data in a table via the normal tbwiki page editor, or using table forms.
67<p>
68There are several types of tables, which vary depending on their storage format:
69<ul><li><b>MoinMoin</b> - tb_type="moinmoin"
70<ul><li>data is in a separate page (or block on a page), and is specified in MoinMoin syntax (using double vertical bars to delimit fields)
71</ul><li><b>attribute files</b> - tb_type="attr_files"
72<ul><li>multiple files, with one table record per file
73<li>data values for the record (field values) are listed as name-value pairs
74<li>at least one attribute file must exist
75<li>attribute files can list different fields (that is, they can be sparse)
76<ul><li>HOWEVER - every attribute file must have a 'record' field, which corresponds to 'record_id' in other places.
77</ul></ul><li><b>inline</b> - tb_type="inline"
78<ul><li>places the data in moin-moin format inline in the same processor block
79   used to declare the table
80</ul><li><b>parsed data files</b> - data tb_type="parsed"
81<ul><li>data is parsed from an external source using using the scanning information provided in a "match_spec"
82<li>this uses the <i>data_scan</i> module
83<li>this is currently a read-only data source (no record editing allowed)
84</ul><li><b>tbwikidb files</b> - data db_type="tbwikidb"
85<ul><li>data is parsed from tbwiki pages specified using a source_spec
86<li>set match_spec="&lt;tbwikidb&gt;"
87<li>must have a a  page named "&lt;base_name&gt;template" to use to add new pages
88<ul><li>example: _bug_template
89</ul></ul><li><b>test data</b> - db_type="test_data"
90<ul><li>this is a special set of test data internal to the table.py module.
91   It is used for testing only.
92</ul>
93</ul>
94<p>
95<h2><a name="MoinMoin_Tables">MoinMoin Tables</a>
96<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=MoinMoin_Tables">edit section</a>]</font></span>
97</h2>
98MoinMoin tables are stored in a single file.  The records are stored one per line, with the field names in the first row of the table, and the record_ids
99in the first column of the table.
100<p>
101Sample source spec: source_spec=PhoneDatabase
102<pre>
103||Name||Phone||
104||Tim ||555-1212||
105||Nadine||444-2323||
106</pre>
107<p>
108<h2><a name="Attribute_files">Attribute files</a>
109<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Attribute_files">edit section</a>]</font></span>
110</h2>
111Attribute files are a collection of files, each containing a single record,
112where the fields for each record are stored as name-value pairs.
113<p>
114Sample source spec: source_spec=Book.*
115<p>
116Any file starting with "Book" would be considered a record in the table.
117<p>
118Attributes are listed in the file as name=value pairs.
119Values can be single-line or multi-line.  Multi-line values are
120<p>
121The first attribute of the record must the name: 'record', which should
122correspond to a unique identifier for records in this table.  Internally,
123this is referred to as the record_id.
124<p>
125The names in the records are NOT required to be perfectly consistent between
126records.  That is, one record may have a 'phone' attribute, while others do not.
127For purposes of display and editing, the set of fields for the tables is the
128union of all fields encountered in all records in the set of files in the
129database.
130<p>
131<h2><a name="Inline_Tables">Inline Tables</a>
132<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Inline_Tables">edit section</a>]</font></span>
133</h2>
134Inline tables are stored inline on a regular tbwiki page.  They currently only
135support moinmoin table syntax, and can be either named or unnamed.
136<p>
137An inline table is embedded inside a #!Table processor block,
138and each line of the table has fields separated by double vertical bars.
139<p>
140Here's an example:
141<pre>
142 
143{{{#!Table
144||Name||Job||
145||Tim||engineer||
146||Fred||pilot||
147}} }
148 
149</pre>
150<p>
151Only one unnamed table may be used on a single wiki page.
152<p>
153Multiple named tables may be used on a wiki page.
154A named table uses a block with a name.
155<p>
156<pre>
157{{{BlockName
158&lt;data&gt;
159}} }
160</pre>
161<p>
162Also, the table processor declaration can include a block name:
163<pre>
164{{{#!Table:BlockName
165&lt;data&gt;
166}} }
167</pre>
168<p>
169<h2><a name="Parsed_data_Tables">Parsed data Tables</a>
170<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Parsed_data_Tables">edit section</a>]</font></span>
171</h2>
172Using the <i>scan_data</i> module, you can parse data from multiple sources.
173<p>
174These can be tbwiki pages, local files, or web pages.
175<p>
176Parsing data from external web pages (scraping them) may introduce long
177delays in displaying a table.
178<p>
179This produces a read-only database.
180<p>
181Here is a sample table declaration for the FIXTHIS list for the tbwiki software:
182<p>
183<pre>
184{{{#!Table
185source_spec=/home/tbird/work/tbwiki/cgi-bin/.*[.]py$:/home/tbird/work/tbwiki/cgi-bin/plugins/.*[.]py$
186 
187match_spec="""
188record_start=.*FIXTHIS
189description=.*FIXTHIS[ -]*(.*)$
190file=%(basename)s
191line_no=%(line_no)s
192"""
193 
194cols=file:line_no:description
195sortby=file:alpha,line_no:int
196}} }
197</pre>
198<p>
199For more information, see <a href="/tbwiki/DocParsedTables">DocParsedTables</a>
200<p>
201<h2><a name="TBWikiDB_Tables">TBWikiDB Tables</a>
202<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=TBWikiDB_Tables">edit section</a>]</font></span>
203</h2>
204This reads a database from regular tbwiki page files in the current wiki.
205<p>
206The source_spec for such a table should be a page name prefix, followed by
207a wildcard (.*).  And the match_spec for the table definition should be
208the exact string "&lt;tbwikidb&gt;".  (see source_spec below for more details)
209<pre>
210{{{#!Table
211source_spec=Bug_.*
212match_spec=&lt;tbwikidb&gt;
213}} }
214</pre>
215<p>
216DB fields are parsed from each page, with a definition creating a single-line value and a level-1 section creating a multi-line value.
217<p>
218Here's an example format:
219<pre>
220; Summary: summary of item
221; Responsible: Tim
222 
223 = Description =
224This is a description of the
225first item, and can have:
226 * regular tbwiki markup
227</pre>
228<p>
229To add records, you need to make a "template" page, from which new
230pages will be created.  This is a regular tbwiki page, with a name
231that ends in the word 'template'.  When a user selects "Add Row", a new file will be created using the filename prefix and the wildcard replaced with a
232record id, with the initial contents being from the template.  In the example
233provided above the template would be named "Bug_template".
234<p>
235<h1><a name="Table_type_specifiers">Table type specifiers</a>
236<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Table_type_specifiers">edit section</a>]</font></span>
237</h1>
238The following fields, that are part of the table configuration, determine how the table is parsed:
239<p>
240<h2><a name="source_spec">source_spec</a>
241<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=source_spec">edit section</a>]</font></span>
242</h2>
243For the source_spec, if there is a leading slash, the spec indicates
244local files (in the server file system). (This is a huge security issue!)
245<p>
246If there is no leading slash, the spec indicates pages in the tbwiki data
247area.  This spec can contain wildcards.  (At least, trailing wildcards.)
248If the spec contains a colon, ':', then the first part is the page name
249and the second part is a block name.  If the table name is '#', then the
250current page is used as the page name.
251<p>
252If the string starts with "http", then it indicates a URL for a web page from
253which the data is loaded.
254<p>
255Here are some examples:
256<ul><li>source_spec=/home/user/big/security/hole/file - read table data from the indicated file in the host filesystem
257<li>source_spec=page_name - read table data from page "page_name" in the set of tbwiki pages
258<li>source_spec=page_name:table_block_name - read table data from the block named "table_block_name" in the page "page_name" (from the tbwiki pages).
259<li>source_spec=page_name_.* - read table data from multiple pages - from all tbwiki pages that start with "page_name_"
260<li>source_spec=<a href="http://domain.com/foo.html">http://domain.com/foo.html</a> - read table data from the indicated web page (this is usually used with a match_spec to parse the data on the page into records).
261<li>source_spec=/tmp/file1:/tmp/file2.* - read table data from multiple files in the local filesystem (usually used with a match_spec to parse the data in the files into records)
262</ul>
263<p>
264<h2><a name="match_spec">match_spec</a>
265<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=match_spec">edit section</a>]</font></span>
266</h2>
267A match_spec is used to describe the regular expressions which are used to gather the record fields and values from the data.
268<p>
269The match_spec is a specified with a set of lines, one-per regular expression, enclosed in triple-quotes (three double-quotes in a row).
270<p>
271To identify the beginning of each record, the
272"record_start=" special variable is used.
273<p>
274Named fields are parsed according to the regular expressions given in the match_spec.
275<p>
276By default, each record will have the named fields, and those will be displayed in the resulting table.  Each record also has a 'record_id' field, which will have the same value as the first field listed in the match_spec.
277<p>
278See <a href="/tbwiki/DocWebSed">DocWebSed</a> for details about pattern matching and regular expressions
279that are supported by the <i>data_scan</i> module.
280<p>
281<p>
282<i>basename</i> and
283<p>
284<i>line_no</i> are special values which hold the name
285of the file being read and the line_no in the data where the record_start
286is found.  These can be assigned to arbitrary field names for the record,
287and used in the table.
288<p>
289<h1><a name="Declaring_a_Table">Declaring a Table</a>
290<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Declaring_a_Table">edit section</a>]</font></span>
291</h1>
292<p>
293Table data is stored in one or more files (or parsed from some other
294source).  To show a view of a table on a page, you create a table
295declaration, usually with a processor block:
296<p>
297<h2><a name="Macro_Syntax">Macro Syntax</a>
298<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Macro_Syntax">edit section</a>]</font></span>
299</h2>
300Here is a sample macro referencing a simple table:
301<pre>
302{{Table(Table1Data)}}
303</pre>
304<p>
305<h2><a name="Processor_Syntax_(with_examples)">Processor Syntax (with examples)</a>
306<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Processor_Syntax_(with_examples)">edit section</a>]</font></span>
307</h2>
308Here is a sample processor syntax for a simple table (with data
309specified in an external file (another page):
310<p>
311<pre>
312{{{#!Table
313source_spec=Table1Data
314}} }
315</pre>
316<p>
317Here is the sample processor syntax for a multi-file table:
318<pre>
319{{{#!Table
320source_spec=bug_.*
321}} }
322</pre>
323<p>
324You can also specify data in a named block on either the current
325page or another page:
326<pre>
327{{{#!Table
328source_spec=#:DataBlock1
329}} }
330</pre>
331<p>
332<pre>
333{{{#!Table
334source_spec=DataPage:DataBlock1
335}} }
336</pre>
337<p>
338<h1><a name="Table_configuration">Table configuration</a>
339<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Table_configuration">edit section</a>]</font></span>
340</h1>
341Table configuration is specified as a list of attributes in name/value pairs, using standard tbwiki configuration syntax (use triple-quotes for multi-line values).
342<p>
343Here are some of the attributes you can use with the Table processor:
344<ul><li><b>source_spec</b> - specifies the source of the data
345<li><b>match_spec</b> - used for parsed-data and tbwikidb tables
346<ul><li>see below
347</ul><li><b>cols</b> - specify the columns of the table to output (and their order)
348<ul><li>e.g. cols=field2:field1:field4
349</ul><li><b>sortby</b> - specify the sort order for displayed records
350<ul><li>multiple fields can be specified, along with their sort type
351<li>e.g. sortby=age:int,name:alpha
352<li>sort types are:
353<ul><li><b>alpha</b> - alphanumeric order (default)
354<li><b>alphai</b> - alphanumeric, case-insensitive
355<li><b>rev_alpha</b> (reverse alpha)
356<li><b>rev_alphai</b>
357<li><b>int</b> - integer order
358<li><b>rev_int</b>
359<li><b>month</b> - by month name
360<li><b>rev_month</b>
361<li><b>possible_values</b> - by order in possible_values list
362<li><b>rev_possible_values</b>
363</ul></ul><li><b>field</b> - specify field type information (multiple declarations allowed)
364<ul><li>these are specified as one or more "field=" statements, using standard attribute syntax
365<li>each "field=" line begins a new field type declaration
366<li>see below for details
367</ul><li><b>row_filter</b> - specify an expression used to filter records in the table
368<ul><li>you can test for string equality, numeric inequality or a regular expression match
369<li>the format of the row_filter is: row_filter=&lt;expression&gt;, where &lt;expression&gt; consists of &lt;field_name&gt;&lt;operator&gt;&lt;value&gt;
370<ul><li>No extraneous spaces are allowed between the word 'row_filter=' and the expression, or between the field_name, operator or value
371<ul><li>this allows for testing values with leading spaces
372</ul><li>the operator can be one of: =, ==, !=. &lt;, &gt;, &lt;=, &gt;=, *=
373<li>'=' and '==' are used for string equality tests:
374<ul><li>ex: row_filter=name=Tim
375</ul><li>either != or &lt;&gt; can be used for string inequality tests:
376<ul><li>ex: row_filter=status!=done
377</ul><li>&lt;, &gt;, &lt;=, &gt;=, &lt;&gt; are used for numeric inequality tests
378<ul><li>ex: row_filter=age&gt;=30
379<li>ex: row_filter=pressure&lt;&gt;10
380</ul><li>*= is used for regular expression matches
381<ul><li>ex: row_filter=status*=closed|fixed
382<li>ex: row_filter=uses_linux*=[Yy]es
383<li>ex: row_filter=uses_linux*=.*es
384</ul><li>if the value has both a leading and trailing double-quote, they are removed
385<ul><li>ex: row_filter=name=="spaces at end  "
386</ul>
387</ul>
388</ul>
389</ul>
390<p>
391<ul><li><b>add_form</b> - specify a form used for adding a new record to the table
392<ul><li>see <a style="color:red;" href="/tbwiki/TestTableUser">TestTableUser</a>
393</ul><li><b>edit_form</b> - specify a form used for editing an existing record in the table
394<li><b>conf</b> - specify the configuration in a separate block
395<ul><li>see below for details
396</ul><li><b>query</b> - specify a block containing query attributes
397<ul><li>Usually, this specifies a block of configuration information, along with a row-filter, to generate a particular view of the data
398<li>see below for details
399</ul><li><b>is_spreadsheet</b> - set to 1 to indicate that the table contains formulas that should be evaluated
400<li><b>show_sort_links</b> - set to 0 to indicate that sort-links should NOT be shown in the table header.  This refers to the small caret that links to a version of the table sorted by that column.
401<li><b>show_edit_links</b> - set to 0 to indicate that edit links should not be shown as part of table output.  This refers to the links underneath the table that allow someone to edit items in the table.  This is mostly useful for inline tables that are for presentation only. That is, that are to be edited as part of wiki text, and not with a table form.
402<li><b>show_as_markup</b> - set to 0 to show data in each cell of the table as plain text.  Defaults to 1, which indicates that the table data is processed as tbwiki markup.
403<li><b>show_template</b> - set to 1 to show the template file in a tbwikidb (so it appears in the table).  By default the template file is not shown in the table.
404</ul>
405<p>
406<h2><a name="field_attributes">field attributes</a>
407<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=field_attributes">edit section</a>]</font></span>
408</h2>
409You can specify the attributes of individual fields, so that TBWiki can
410process them properly (generate appropriate default forms, and display
411the values properly).
412<p>
413field attributes are:
414<ul><li><b>field</b> - specify the name of the field for which attributes are being declared
415<li><b>type</b> - specify the type of the field
416<ul><li>possible types are: Text, Textarea, Select, Checkbox, Radio
417</ul><li><b>default_value</b> - specify a value to pre-populate in the field in an Add form
418<li><b>possible_values</b> - list of possible values for the field
419<ul><li>specified with a multi-line value, one value per line
420</ul><li><b>colors</b> - list of specifiers used to define the background color for a field, based on the field's current value
421<ul><li>see below for definitions and syntax
422</ul>
423</ul>
424<p>
425<h3><a name="dynamic_default_values">dynamic default values</a>
426<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=dynamic_default_values">edit section</a>]</font></span>
427</h3>
428There are some special default values that allow you to automatically populate a field differently
429for each new record created.  To use a dynamic default value, use one of the strings below:
430<ul><li>%(timestamp)s - yields a string in the format: yyyy-mm-dd_HH:MM:SS.SS
431<li>%(next_int)s - yields a value one higher than all other integer values in this field in the table already
432<li>%(next_page_num)s = yields a number one higher than all other page numbers already used for this table (for attrdb and tbwikidb databases only).  This number is used in the filename to create a new file.
433</ul>
434<p>
435<h3><a name="color_specifiers">color specifiers</a>
436<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=color_specifiers">edit section</a>]</font></span>
437</h3>
438The table configuration can provide a list of color specifiers that indicate
439what the background color of a particular cell should be, based on the value
440of the field in that cell
441<ul><li>the 'colors' field attribute is used to provide a list of tests and colors
442<ul><li>each line in the list is of the form:
443<ul><li>test:color
444</ul><li>these list of tests are matched against the field value, and if a match is found, the background color of the cell for that item is shaded in the specified color
445</ul><li>a tests consists of either a word or phrase, or a python expression enclosed in parenthesis, using the term 'value'a colon
446<ul><li>an expression can be a single word or phrase, in which case if the field value matches the word or phrase exactly, the test passes (and the color is used)
447<ul><li>ex:
448<pre>
449colors="""good:green
450bad:red
451more than one word:yellow"""
452</pre>
453</ul><li>colors can be color names or hex triples
454<li>expressions can be any valid python expression
455<ul><li>expressions can include boolean operators (not, and, or)
456<li>expressions can test for equality or inequality
457</ul><li>ex: (int(value)&lt;20):blue - show a blue cell for items with value&lt;20
458<li>ex: show "good" cells in green and "bad" cells in red
459<pre>
460colors="""(value=="good"):green
461(value=="bad"):ff0000"""
462</pre>
463<li>ex: show particular values in yellow
464<pre>
465colors="""(int(value)&gt;5 and int(value)&lt;10):00ffff"""
466</pre>
467<li>ex: show some words in orange
468<pre>
469colors="""(value in ["lemon", "banana"]):orange
470(value in ["apple", "cherry", "stawberry", "tomato"]):red"""
471</pre>
472</ul>
473</ul>
474<p>
475<h4><a name="field_attribute_samples">field attribute samples</a>
476<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=field_attribute_samples">edit section</a>]</font></span>
477</h4>
478Field types and possible values:
479<pre>
480{{{SampleDataConf
481field=Summary
482type=Text
483field=Description
484type=Textarea
485field=Done
486type=Select
487possible_values="""Yes
488No"""
489field=Happy
490type=Checkbox
491field=OS
492type=Radio
493possible_values="""Linux
494BeOs
495DOS
496Windows"""
497default_value=Linux
498}} }
499</pre>
500<p>
501Color Expressions:
502<pre>
503{{{#!Table
504source_spec=#:ReactorTable
505field=reactor_temperature
506colors="""(int(value)&lt;10):ffffd0
507(int(value)&gt;=10 and int(value)&lt;50):ffff80
508(int(value)&gt;500):ffd0d0"""
509}} }
510</pre>
511<p>
512<h2><a name="Configuration_blocks">Configuration blocks</a>
513<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Configuration_blocks">edit section</a>]</font></span>
514</h2>
515You can specify several "configuration" attributes of a table,
516and use them repeatedly (i.e. from different processor blocks), using
517the "conf=" attribute
518<p>
519Configuration blocks are used to describe any of the attributes of the
520table.
521<p>
522<h2><a name="Query_blocks">Query blocks</a>
523<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Query_blocks">edit section</a>]</font></span>
524</h2>
525You can specify a "query" block, which has a set of table attributes
526(usually including a row_filter) to show a subset of the data.
527These can be referenced via a URL, to show different views of the same
528data.
529<p>
530<h1><a name="Views">Views</a>
531<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Views">edit section</a>]</font></span>
532</h1>
533To show a table on a page, you use the table processor, which has the format:
534<pre>
535{{{#!Table
536&lt;source spec&gt;
537}} }
538</pre>
539<p>
540You can also specify view a table that references a query configuration block,
541to show a different view of the table.
542<p>
543<h2><a name="Custom_forms_and_views">Custom forms and views</a>
544<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Custom_forms_and_views">edit section</a>]</font></span>
545</h2>
546You can create custom views of table data, by creating a view file.
547<h3><a name="View">View</a>
548<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=View">edit section</a>]</font></span>
549</h3>
550To create a custom view for a record, ...
551<p>
552<ul><li>line_edit_form_spec, get_default_line_edit_form_spec
553</ul>
554<p>
555<ul><li>there is no way to do a custom view right now.
556</ul>
557<p>
558<ul><li>see def html_string()
559<ul><li>should support non-table views?
560<ul><li>need view_header, view_record, view_footer definitions in config
561<li>view_record needs could have:
562<pre>
563view_record_form="""
564&lt;tr&gt;&lt;td&gt;%(nameField)s&lt;/td&gt;&lt;td&gt;custom text...%(phoneField)s&lt;/td&gt;&lt;/tr&gt;
565&lt;tr&gt;&lt;td&gt;next line:%(addr1Field)s&lt;/td&gt;&lt;td&gt;%(addr2Field)s&lt;/td/&lt;/tr&gt;
566"""
567</pre>
568</ul>
569</ul>
570</ul>
571<p>
572<ul><li>or, not in a table format:
573<pre>
574view_record_form="""Name: %(nameField)s&lt;br&gt;
575Phone: %(phoneField)s&lt;br&gt;
576Address: %(addr1Field)&lt;br&gt;%addr2Field)
577&lt;HR&gt;
578"""
579</pre>
580</ul>
581<p>
582Maybe need to use "Value" instead of "Field".  Field is used for edit forms.
583With a different keyword, you could have a mix of read-only and editable fields.  This is desirable.
584<p>
585Example:
586<pre>
587add_form="""Name: %(nameValue)s&lt;br&gt;
588Phone: %(phoneField)s&lt;br&gt;
589"""
590</pre>
591<p>
592<h3><a name="Add_Form">Add Form</a>
593<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Add_Form">edit section</a>]</font></span>
594</h3>
595To create a custom form to add a record, use the "add_form" attribute
596in the configuration for a database.  This is (almost always) a multi-line
597attribute in the table configuration, and consists of the HTML used to
598display the edit fields for the record.
599<p>
600Edit fields are placed in the HTML wherever a named python format string
601occurs, of the type:
602  "%(&lt;field-name&gt;Field)s"
603or
604  "%(&lt;field-name&gt;File&lt;field-type&gt;)s"
605<p>
606Ex: To create a custom add form for the Book.* database, add the following
607attribute in the DBBookConf file, along with the other config:  In this file, put HTML (FIXTHIS - should allow tbwiki markup also) to display the form.
608Whereever you want the form input element for a field of the record, you can
609place a python named string format item.
610<p>
611Here is an example showing fields in an HTML table.
612<pre>
613add_form="""&lt;table&gt;
614&lt;tr&gt;
615&lt;td&gt;User name:&lt;/td&gt;&lt;td&gt; %(record_idField) s&lt;/td&gt;
616&lt;/tr&gt;&lt;tr&gt;
617&lt;td&gt;Phone number:&lt;/td&gt;&lt;td&gt; %(phoneField) s&lt;/td&gt;
618&lt;/tr&gt;&lt;tr&gt;
619&lt;td&gt;Description:&lt;/td&gt;&lt;td&gt; %(descriptionFieldTextarea) s&lt;/td&gt;
620&lt;/tr&gt;&lt;tr&gt;
621&lt;td&gt;%(ok_flagFieldCheckbox) s Is OK?&lt;/td&gt;
622&lt;/tr&gt;
623&lt;/table&gt;
624%(SaveButton) s %(CancelButton) s&lt;br&gt;
625"""
626</pre>
627<p>
628Note that any default values specified in the database config will
629be pre-filled in, in the form.  Any values that don't have defaults
630in the configuration will start blank.
631<p>
632<h3><a name="Edit_form">Edit form</a>
633<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Edit_form">edit section</a>]</font></span>
634</h3>
635An edit form is specified the same way, but using the configuration attribute "edit_form".  Note that the field values in the form will be pre-filled in with
636values from the record edited.
637<p>
638<h2><a name="Field_format_strings_for_edit_forms">Field format strings for edit forms</a>
639<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Field_format_strings_for_edit_forms">edit section</a>]</font></span>
640</h2>
641Field format strings are python named format strings.  The name of the
642python variable consist of the field name, followed by "Field", followed
643by the type of form element to display.
644<p>
645If no type is specified, (either in the field format string, or in the
646database configuration) a single-line text entry box is used (that is, an HTML INPUT form element).
647<p>
648Possible types are:
649<ul><li>Text
650<li>TextArea
651<li>Checkbox
652<li>Select
653<li>Radio
654</ul>
655<p>
656If something besides one of these types is specified, it is used
657as the INPUT field type in the HTML file element.
658<p>
659<h2><a name="Special_form_elements">Special form elements</a>
660<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Special_form_elements">edit section</a>]</font></span>
661</h2>
662The following are special form elements that can be placed anywhere in the
663form specification:
664<ul><li>SaveButton - this shows the button to submit the form data
665<li>CancelButton - this cancels the operation and doesn't save the form data
666</ul>
667<p>
668<h1><a name="Spreadsheets">Spreadsheets</a>
669<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Spreadsheets">edit section</a>]</font></span>
670</h1>
671Tables may contain formulas which are calculated at runtime to produce a final value for a "cell".
672<p>
673In order for the table processor to process formulas, it needs to know that a table is to be interpreted as a spreadsheet.  To do this, add the attribute
674is_spreadsheet=1 to the table configuration (usually this is the first
675line after the #!Table processor directive at the top of the block).
676<p>
677<h2><a name="formulas">formulas</a>
678<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=formulas">edit section</a>]</font></span>
679</h2>
680Formulas can consist of simple arithmetic, or functions.  Formulas
681operate on data obtained from other cells, including individual cells and
682ranges, and on literals.
683<p>
684A formula always starts with an equal sign ('=').   Here is a very simple
685formula: '=2+2'
686<p>
687Currently supported functions are:
688<ul><li>SUM(&lt;range&gt;) - calculates the sum of the numbers in the indicated range of cells
689<li>COUNT(&lt;range&gt;) - show the number of cells in a range that have numeric values
690<li>COUNTA(&lt;range&gt;) - show the number of non-empty cells in a range
691<li>AVERAGE(&lt;range&gt;) - show the average for cells containing numeric values in a range of cells
692<li>AVERAGEA(&lt;range&gt;) - show the average for cells containing non-empty values in a range of cells (TRUE is calculated as 1, any other non-numeric value is 0, but counts towards the count of cells)
693<li>MAX(&lt;list&gt;) or MAX(&lt;range&gt;) - show the maximum value from a list of values or a from a given range
694<li>MIN(&lt;list&gt;) or MAX(&lt;range&gt;) - show the minimum value from a list of values or from a given range
695</ul>
696<p>
697FIXTHIS - add support for COUNTIF
698<p>
699<h2><a name="cell_addressing">cell addressing</a>
700<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=cell_addressing">edit section</a>]</font></span>
701</h2>
702To unlock the power of formulas, you will want to use values from other cells.
703Currently, the spreadsheet only does a single pass over the data in the table,
704going row-by-row, in the order of records in the table database internally.
705formulas may refer to rows and columns that precede the formula in the table.
706<p>
707cells are looked up by row name and column name, with special syntax to allow
708for referring to the current row and current column.  A cell reference starts with a dollar sign ('$'), and then has the row identifier followed by the column identifier.
709<p>
710Let's say we had the following table:
711<table border=1>
712<tr bgcolor="#d0d0ff">
713  <td align="center"><b>item</b>&nbsp;&nbsp;<a href="/tbwiki/DocTables?sortby=item">^</a></td>
714  <td align="center"><b>count</b>&nbsp;&nbsp;<a href="/tbwiki/DocTables?sortby=count">^</a></td>
715  <td align="center"><b>price</b>&nbsp;&nbsp;<a href="/tbwiki/DocTables?sortby=price">^</a></td>
716  <td align="center"><b>total</b>&nbsp;&nbsp;<a href="/tbwiki/DocTables?sortby=total">^</a></td>
717</tr>
718<tr>
719  <td>paper</td>
720  <td>5</td>
721  <td>.07</td>
722  <td>=$paper.count * paper.price</td>
723</tr>
724<tr>
725  <td>pencil</td>
726  <td>2</td>
727  <td>.50</td>
728  <td>=$pencil.count * $pencil.price</td>
729</tr>
730</table>
731<a href="/tbwiki/DocTables?action=Table.query_form&source_spec=DocTables%3Aexample1&conf=&table_block=DocTables%3Aexample1">
732            <font size=-1>Query</font></a>
733<br>
734 
735<p>
736The row identifier is the name specified as the record_id, or first cell
737in a row.  The column identifiers is a name specified in the first
738row of the cells.
739<p>
740You can omit the row identifier OR column identifier, but not both.
741Thus, the formula in the last cell in the above table (the one that contains "=$pencil.count * $pencil.price") could be written more shortly by referring to the current row.  That is, you could omit the current row name (pencil) and re-write that cell as: "=$.count * $.price", with the same meaning.
742<p>
743An empty row identifier means
744"the current row", and an empty column identifier means "the current column".  Notice that this allows the same formula to be used in multiple rows.
745Also since formulas use names, they don't have to be adjusted if more rows
746or columns are added to the table.  They do have to be adjusted, however,
747if the names that are referenced are changed.  (That is, if you changed the column name of "price" to "cost", you would need to adjust any formulas
748that used that column name.)
749<p>
750You may also refer to cells by absolute or relative position in the table.
751The absolute position depends on the row_output_list and col_output_list.
752That is, it may depend on your query.  Rows and columns are numbered from 0.
753Row absolute references must be exactly 5 digits long, with leading zeros.
754<p>
755So $00003.5 would refer to the cell in the fourth row and sixth column in the table.  Usually, the first row is the header, and the first column is the record key.  You can think of the numbering as being 1-based, within the actual
756data portion of the table.  In the sample table above, the address $00001.1 and $paper.count refer to the same cell (with value of 5).
757<p>
758You can refer to cells with relative references as well.  Use '-' or '+' as
759the prefix to indicate a backward reference or forward reference, respectively.
760Here are some examples of relative references:
761<ul><li>'$-1.' indicates the cell one row previous (the cell just above the current one)
762<li>'$.-1' indicates the cell one column previous (the cell just to the left of the current one)
763<li>'$+2.-1' indicates a cell 2 rows down and one column back from the current cell.
764</ul>
765<p>
766Functions often operate on ranges.  A range is just two cell references,
767separated by a colon.  Like so:
768<pre>
769  =SUM($paper.total:$pencil.total)
770</pre>
771Currently, ranges are evaluated left-to-right and top-to-bottom.
772<p>
773<h2><a name="examples">examples</a>
774<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=examples">edit section</a>]</font></span>
775</h2>
776See <a style="color:red;" href="/tbwiki/TestSpreadsheetStuff">TestSpreadsheetStuff</a> for examples.
777<p>
778<h1><a name="Things_to_Describe">Things to Describe</a>
779<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=Things_to_Describe">edit section</a>]</font></span>
780</h1>
781<ul><li>sequencing of records
782<li>filtering
783<li>sorting
784<li>views
785<li>default values
786<li>spreadsheets
787<li>match_spec conf description and examples
788</ul>
789<p>
790<h2><a name="not_implemented_yet">not implemented yet</a>
791<span align=right class="section_edit_link">[<a href="/tbwiki/DocTables?action=edit&section=not_implemented_yet">edit section</a>]</font></span>
792</h2>
793Support generated default values for fields:
794<ul><li>%(cur_date)s
795<li>%(next_int)s
796</ul>
797<p>
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

Differences for page "DocTables"


expected html
generated html
t No Differences Found t No Differences Found 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

Update saved output

Back to diff page

Return to Regression_Test page
TBWiki engine 1.9.3 by Tim Bird