Welcome | Get started | Dive into Lino | Contribute | Topics | Reference | 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):

../_images/tickets.SiteDetail.png

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:

../_images/tickets.SiteDetail-2.png

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

../_images/tickets.SiteDetail-3.png

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:

@classmethod
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.obj2href(ar)
        if ci is not None and ci[0] is obj.state:
            ci[1].append(btn)
        else:
            ci = (obj.state, [btn])
            items.append(ci)

    # 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