Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

Table summaries

A table summary is an alternative non-tabular way of displaying the data in the table.

You can see the summary of a table by setting its display_mode to 'summary' (instead of its default value 'grid').

For any table you can define a customized summary view by writing a get_table_summary method.

For example the detail window of a Site in Lino Noi (the team demo project):


Here is the layout for this window:

class SiteDetail(SiteDetail):

    main = """general more history"""

    general = dd.Panel("""
    id name
    company contact_person reporting_type workflow_buttons:20
    stars.StarsByController:30 TicketsBySite
    """, label=_("General"))

    more = dd.Panel(...)
    history = dd.Panel(...)

Note that the lower part of the General tab is occupied by two slave tables, stars.StarsByController and TicketsBySite.

The display_mode of TicketsBySite is 'summary', while for stars.StarsByController it is the default ('grid').

If we changed the display mode of TicketsBySite to grid, we would get:


If the display_mode of StarsByController was summary, we would get:


Note that StarsByController has no custom summary view defined, so when we ask a summary, we get the default view, which simply displays all items using their __str__() method, which for a lino_xl.lib.stars.Star object is defined as follows:

def __str__(self):
    return _("{} starring {}").format(self.user, self.owner)

Here is how the customized summary for TicketsBySite is defined:

def get_table_summary(self, master, ar):

    # request the rows of the slave table:
    sar = self.request_from(ar, master_instance=master)

    # rows are ordered by state. we just group them
    # every element of `items` is a tuple `(state,
    # list-of-objects)`.
    items = []
    ci = None

    for obj in sar:
        btn = obj.as_summary_item(ar)
        if ci is not None and ci[0] is obj.state:
            ci = (obj.state, [btn])

    # now render them as a UL containing on LI per item
    items = [E.li(str(i[0]), ' : ', *join_elems(i[1], ", "))
             for i in items]

    return E.ul(*items)

Other usage examples of custom table summaries:

  • lino_xl.lib.households.models.SiblingsByPerson