sprox.tablebase

fillerbase Module

Classes to help fill widgets with data

Copyright (c) 2008-10 Christopher Perkins Original Version by Christopher Perkins 2008 Released under MIT license.

Classes

class sprox.tablebase.TableBase(provider_hint=None, **provider_hints)

Bases: sprox.viewbase.ViewBase

This class allows you to create a table widget.

Modifiers :
Name Description Default
__base_widget_type__ Base widget for fields to go into. SproxDataGrid
__metadata_type__ Type the widget is based on. FieldsMetadata
__headers__ A dictionay of field/header pairs. {}
__column_widths__ A dictionay of field/width(string) pairs. {}
__default_column_width__ Header size to use when not specified in __column_widths__ ‘10em’
__xml_fields__ fields whos values should show as html  

see modifiers in sprox.viewbase

Here is an example listing of the towns in the test database.

>>> from sprox.tablebase import TableBase
>>> class TownTable(TableBase):
...    __model__ = Town
>>> town_table = TownTable(session)
>>> print town_table()
<div>
<table
       id="None" class="grid">
    <thead>
        <tr>
                <th  class="col_0">actions</th>
                <th  class="col_1">town_id</th>
                <th  class="col_2">name</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>
      No Records Found.
</div>

As you can see, this is none too interesting, because there is no data in the table. Here is how we fill the table with data using TableFillerBase

>>> from sprox.fillerbase import TableFiller
>>> class TownFiller(TableFiller):
...     __model__ = Town
>>> town_filler = TownFiller(session)
>>> value = town_filler.get_value()
>>> print town_table.__widget__(value=value) 
<div xmlns="http://www.w3.org/1999/xhtml">
<div>
<table
       id="None" class="grid">
    <thead>
        <tr>
                <th class="col_0">town_id</th>
                <th class="col_1">name</th>
        </tr>
    </thead>
    <tbody>
        <tr class="even">
            <td class="col_0">
                    1
            </td>
            <td class="col_1">
                    Arvada
            </td>
        </tr>
        <tr class="odd">
            <td class="col_0">
                    2
            </td>
            <td class="col_1">
                    Denver
            </td>
        </tr>
        <tr class="even">
            <td class="col_0">
                    3
            </td>
            <td class="col_1">
                    Golden
            </td>
        </tr>
        <tr class="odd">
            <td class="col_0">
                    4
            </td>
            <td class="col_1">
                    Boulder
            </td>
        </tr>
    </tbody>
</table>
</div>

And now you can see the table has some data in it, and some restful links to the data. But what if you don’t want those links? You can omit the links by adding ‘__actions__’ to omitted fields as follows:

>>> class TownTable(TableBase):
...     __model__ = Town
...     __omit_fields__ = ['__actions__']
>>> town_table = TownTable(session)
>>> print town_table.__widget__(value=value)
<div>
<table
       id="None" class="grid">
    <thead>
        <tr>
                <th  class="col_0">town_id</th>
                <th  class="col_1">name</th>
        </tr>
    </thead>
    <tbody>
        <tr class="even">
            <td class="col_0">
                    1
            </td>
            <td class="col_1">
                    Arvada
            </td>
        </tr>
        <tr class="odd">
            <td class="col_0">
                    2
            </td>
            <td class="col_1">
                    Denver
            </td>
        </tr>
        <tr class="even">
            <td class="col_0">
                    3
            </td>
            <td class="col_1">
                    Golden
            </td>
        </tr>
        <tr class="odd">
            <td class="col_0">
                    4
            </td>
            <td class="col_1">
                    Boulder
            </td>
        </tr>
    </tbody>
</table>
</div>

Discuss

blog comments powered by Disqus

Table Of Contents

Previous topic

sprox.formbase

Next topic

sprox.fillerbase

This Page