| t | Here are some notes on table internals | t | |
| <p> | | |
| | | |
| <table align="right"><tr><td><div class="toc"> | | |
| Contents: | | |
| <ul> | | |
| <li><a href="#classes">classes</a></li> | | |
| <ul> | | |
| <li><a href="#table_class">table_class</a></li> | | |
| <ul> | | |
| <li><a href="#table_conf_class">table_conf_class</a></li> | | |
| </ul> | | |
| <li><a href="#form_fields_generator_class">form_fields_generator_class</a></li> | | |
| <li><a href="#io_handle_*_classes">io_handle_* classes</a></li> | | |
| <li><a href="#class_capture_stderr">class capture_stderr</a></li> | | |
| </ul> | | |
| <li><a href="#global_routines">global routines</a></li> | | |
| <li><a href="#Table_Processor">Table Processor</a></li> | | |
| <li><a href="#Notes">Notes</a></li> | | |
| </ul> | | |
| </div></td></tr></table> | | |
| <p> | | |
| <h1><a name="classes">classes</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/DocTablesInternals?action=edit§ion=classes">edit section</a>]</font></span> | | |
| </h1> | | |
| <h2><a name="table_class">table_class</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/DocTablesInternals?action=edit§ion=table_class">edit section</a>]</font></span> | | |
| </h2> | | |
| A table consist of a instance of table_class with the following attributes: | | |
| <ul><li>.records - a map of actual records of the database | | |
| <li>header_record - a record with header values for the fields | | |
| <li>.source_spec - indicates the origin of the data | | |
| <li>.field_list - a list of records containing information about the fields in the db | | |
| <li>col_names - a map of column names | | |
| <li>row_names - a map of row names | | |
| <li>row_output_list - list of record_ids for rows to show | | |
| <li>row_filter - | | |
| <li>col_output_list - list of col_names for columns to show | | |
| <li>page_name | | |
| <li>conf | | |
| <li>rmap | | |
| <li>num_fields | | |
| <li>message - a message to print out, for debugging or errors | | |
| <li>conf - the database configuration | | |
| <ul><li>see below | | |
| </ul><li>handler - the io handler for the database | | |
| <ul><li>see below | | |
| </ul><li>req = the request that fetched this database | | |
| <li>data_dir = the directory where the data was read from (e.g. data or admin or backup) | | |
| </ul> | | |
| <p> | | |
| <h3><a name="table_conf_class">table_conf_class</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/DocTablesInternals?action=edit§ion=table_conf_class">edit section</a>]</font></span> | | |
| </h3> | | |
| Has all kinds of configuration information (the raw text) for a class: | | |
| <ul><li>conf_spec | | |
| <li>source_spec | | |
| <li>row_filter | | |
| <li>cols | | |
| <li>sortby | | |
| <li>row_output_list | | |
| <li>query | | |
| <li>query_list | | |
| <li>sort_col_list | | |
| <li>add_form | | |
| <li>edit_form | | |
| <li>show_header | | |
| <li>show_record | | |
| <li>show_footer | | |
| <li>field_spec | | |
| <li>field_db - map of attributes for the fields in the database | | |
| <ul><li>a field_db element (field record) can have the following attributes: | | |
| <ul><li>type | | |
| <li>possible_values | | |
| <li>color_list | | |
| </ul> | | |
| </ul> | | |
| </ul> | | |
| <p> | | |
| methods: | | |
| <ul><li>__init__ | | |
| <li>set_color_lists | | |
| <li>get_conf - get the configuration. This is a merge of the base conf and the dynamic conf | | |
| * | | |
| </ul> | | |
| <p> | | |
| The base conf is read from a block on the page, and the dynamic conf is read | | |
| from the URL. This allows things like a base configuration specifying the | | |
| field types, while the dynamic conf specifies the sortby order (or some other complex query, like from a query form. | | |
| <p> | | |
| table_class methods: | | |
| <p> | | |
| <ul><li>__init__ | | |
| <li>add_or_edit_numbered_record | | |
| <li>remove_numbered_record | | |
| <li>set_col_output_list | | |
| <li>set_row_filter | | |
| <li>filter_match | | |
| <li>add_to_message | | |
| <li>html_string - main routine to render the table to HTML | | |
| <li>get_default_edit_form_spec | | |
| <li>show_record_edit_form | | |
| <li>show_edit_table_form | | |
| <li>get_default_line_edit_form_spec | | |
| <li>show_edit_table_in_place_form | | |
| <li>edit_link | | |
| <li>show_query_form | | |
| </ul> | | |
| <p> | | |
| <h2><a name="form_fields_generator_class">form_fields_generator_class</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/DocTablesInternals?action=edit§ion=form_fields_generator_class">edit section</a>]</font></span> | | |
| </h2> | | |
| The form_fields_generator_class is used to create an instance of a | | |
| form_fields_generator. This is used with a form_spec to create | | |
| an actual form. It generates the correct HTML for each field, on | | |
| the fly, by acting like a map where the string substitutions in | | |
| the form get converted into appropriate HTML input elements. | | |
| <p> | | |
| <h2><a name="io_handle_*_classes">io_handle_* classes</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/DocTablesInternals?action=edit§ion=io_handle_*_classes">edit section</a>]</font></span> | | |
| </h2> | | |
| These classes handle I/O operations for the different types of databases | | |
| supported: | | |
| <ul><li>test | | |
| <li>moin_file | | |
| <li>moin_in_page (inline in table block or named block) | | |
| <li>attr_files | | |
| <li>parsed_files | | |
| </ul> | | |
| <p> | | |
| An io_handler instance has the following attributes: | | |
| <ul><li>req - the request used to fetch the database | | |
| <li>tb - the table instance | | |
| <li>data_dir - the directory used to read the data from | | |
| <li>source_spec | | |
| </ul> | | |
| <p> | | |
| The io_handle_base class is a stub class, with methods for: | | |
| <ul><li>read - read the whole database | | |
| <li>get_record - (does not appear to be used) | | |
| <li>add_record - (does not appear to be used) | | |
| <li>update_record - (does not appear to be used) | | |
| <li>remove_record - remove an individual record | | |
| <li>write - write the whole database (not used?? see save_table_data) | | |
| </ul> | | |
| <p> | | |
| Different classes implement these methods, according to the database type. | | |
| <p> | | |
| <h2><a name="class_capture_stderr">class capture_stderr</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/DocTablesInternals?action=edit§ion=class_capture_stderr">edit section</a>]</font></span> | | |
| </h2> | | |
| In order to capture errors, a class is used to grab the errors and put | | |
| them in a buffer. This is to capture exceptions and put them in the | | |
| message log, in case of unhandled error conditions. | | |
| <p> | | |
| <h1><a name="global_routines">global routines</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/DocTablesInternals?action=edit§ion=global_routines">edit section</a>]</font></span> | | |
| </h1> | | |
| <ul><li>print_error | | |
| <li>generate_field_input - used to generate an input field for a form element | | |
| <li>value_trans | | |
| <li>parse_attrs - given a block of data, create a map with key-value pairs | | |
| <li>rec_sort - used to sort records (according to 'sortby' setting) | | |
| <ul><li>cmp_rev(), cmp_int(), cmp_rev_int() | | |
| </ul><li>set_sort_col_list | | |
| <li>gen_row_output_list - generate a default row output list, based on the sortby spec. The list is ordered and filtered. | | |
| <li>setup_conf_and_db - set up configuration and source_spec, possibly reading from multiple blocks (table block, data block, conf block) | | |
| <li>macro_get_table | | |
| <li>get_table - an action? | | |
| <li>add_record_form - an action in the table module | | |
| <li>query_form - an action in the table module | | |
| <li>edit_table - an action in the table module | | |
| <li>edit_table_in_place | | |
| <li>parse_moin_table | | |
| <li>read_page_or_block | | |
| <li>parse_attrdb_data | | |
| <li>read_attrdb_file | | |
| <li>get_filelist | | |
| <li>db_from_attrdb_files | | |
| <li>db_from_parsed_files | | |
| <li>save_attrs_to_file | | |
| <li>save_attrdb | | |
| <li>remove_attrdb | | |
| <li>convert_table_to_dict | | |
| <li>render_moin_table | | |
| <li>get_table_type - examines source_spec and conf, to determine the type of | | |
| database to handle | | |
| <li>get_table_data | | |
| <li>save_table_data - routine that implements save of data based on data type | | |
| <ul><li>this appears to be a hold-over from before the implementation of the | | |
| io_handler_class | | |
| <li>currently, the write() io_handlers call save_table_data | | |
| </ul><li>action - multiplexor for table sub_actions, from the set: | | |
| <ul><li>add_record | | |
| <li>remove_record | | |
| <li>edit_record_form | | |
| <li>edit_record | | |
| <li>save_all | | |
| <li>add_column - not implemented | | |
| <li>edit_column - not implemented | | |
| <li>remove_column - not implemented | | |
| <li>query | | |
| </ul> | | |
| </ul> | | |
| <p> | | |
| <h1><a name="Table_Processor">Table Processor</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/DocTablesInternals?action=edit§ion=Table_Processor">edit section</a>]</font></span> | | |
| </h1> | | |
| The table processor has the following actions: | | |
| <p> | | |
| <ul><li>Table - main routine to return a table (from get_table() above) | | |
| <li>add_record_form | | |
| <li>query_form | | |
| <li>edit_table - | | |
| <li>edit_table_in_place - | | |
| <li>action - process form actions (sub_actions) | | |
| <ul><li>this performs some action, like processing a form or operation, then | | |
| sets a results message, and then shows the page (with results, hopefully). | | |
| </ul> | | |
| </ul> | | |
| <p> | | |
| <h1><a name="Notes">Notes</a> | | |
| <span align=right class="section_edit_link">[<a href="/tbwiki/DocTablesInternals?action=edit§ion=Notes">edit section</a>]</font></span> | | |
| </h1> | | |
| A table configuration can have the following attributes: | | |
| <ul><li>conf= | | |
| <li>query= | | |
| <li>source_spec= | | |
| <li>and all the fields shown in the table_conf_class list | | |
| <ul><li>these are read like a map into the conf's attributes as strings directly from the configuration block | | |
| </ul><li>a list of field attributes (in attrdb format, with 'field' as the record indicator) | | |
| </ul> | | |
| <p> | | |
| The conf and query lines can "chain" to other blocks, so that a multiple | | |
| "Views" can be constructed from the same data. | | |
| <p> | | |
| For example, a table could be defined like: | | |
| <p> | | |
| <pre> | | |
| {{ {Data | | |
| ||foo||bar||baz|| | | |
| ||1 ||yes ||5|| | | |
| ||3 ||no ||100|| | | |
| | | |
| }} } | | |
| </pre> | | |
| <p> | | |
| <pre> | | |
| {{ {#Conf1 | | |
| source_spec=#:Data | | |
| sortby=bar,int | | |
| field=bar | | |
| possible_values="""yes | | |
| no""" | | |
| field=baz | | |
| color_list="""(int(value))<50:red | | |
| (int(value)<100:yellow""" | | |
| }} } | | |
| </pre> | | |
| <p> | | |
| <pre> | | |
| {{ {#Query1 | | |
| col_list=foo,baz | | |
| filter=foo=1 | | |
| }} } | | |
| </pre> | | |
| <p> | | |
| <pre> | | |
| {{ {!#Table | | |
| conf=#:Conf1 | | |
| query=#:Query1 | | |
| }} } | | |
| </pre> | | |
| <p> | | |
| source_specs indicate the source and type of data for the database: | | |
| <ul><li>test_data = use the special built-in test data (read-only) | | |
| <li>endswith '.*' = attr_files | | |
| <li>startswith '#' = inline | | |
| <li>startswith '_inline_' = inline | | |
| <li>config has 'match_spec' = parsed | | |
| <li>otherwise it's a moinmoin db in a file | | |
| </ul> | | |
| <p> | | |
| sortby can have the following types: | | |
| <ul><li>alpha | | |
| <li>rev_alpha | | |
| <li>int | | |
| <li>rev_int | | |
| </ul> | | |
| <p> | | |