Aside from various form controls, the regional index is a sequence of entries, one per unique name that has been used for a circle that is all or partially in that region.
A primary entry represents the last or only name used for that circle. The name itself is a link to produce a report for just that circle. Each name is preceded by a checkbox so the user can select multiple circles in a combined report.
Each primary entry is followed by zero or more each of “as” entries, noting which other published counts shared either the name or the center coordinates with the related primary entry, and zero or more “overlaps” entries noting other circles that overlap the named primary entry.
A secondary entry represents any name that shares its center coordinates with a primary entry but used a different name or set of regional codes. The variant name is a link that jumps to the related primary entry on the same regional page.
Given a region code and the CBC database, we can represent everything on the regional index page by three classes:
BaseEntry
This class provides a uniform interface for primary
and secondary entries so that they can be placed
into a heterogeneous list, and then sorted using
the built-in Python .sort() method.
This base class also defines an abstract method
.html() that subclasses will use to
build the actual XHTML of the index page.
PrimaryEntry(BaseEntry)
Represents a primary entry. Contains an instance of
the Circle class of the CBC database.
SecondaryEntry(BaseEntry)
Represents a secondary entry. Contains the related
Circle instance and the variant
name.
This makes construction of the regional index page straightforward:
Create an empty page and an empty list.
For every row in the circle table,
create a PrimaryEntry for that circle,
and add that to the list.
For every row, also look through the related rows of
the effort table, and for each one
that has a different name, create a SecondaryEntry for the primary circle and
that name, and add that to the list.
Sort the list.
For each element of the sorted list, invoke its .html() method to add the appropriate XHTML
to the page.
Serialize the XHTML page.