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:
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
This base class also defines an abstract method
.html() that subclasses will use to
build the actual XHTML of the index page.
Represents a primary entry. Contains an instance of
Circle class of the CBC database.
Represents a secondary entry. Contains the related
Circle instance and the variant
This makes construction of the regional index page straightforward:
Create an empty page and an empty list.
For every row in the
PrimaryEntry for that circle,
and add that to the list.
For every row, also look through the related rows of
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.