Next / Previous / Contents / TCC Help System / NM Tech homepage

8.8. regx.cgi: buildIndexSection(): Add the primary and secondary index entries

To build the index, we need the base class defined in Section 21, “class BaseIndex: Base class for regional page index entries” and its two derived classes Section 22, “class PriIndex: Primary regional index entry” and Section 23, “class SecIndex: Secondary regional index entry”. The work proceeds in three phases.

  1. Find every circle that occurs all or partly in the region whose code is specified by RegArgs().reg_code and which has at least one effort in the date range specified by RegArgs().firstYear and RegArgs().lastYear. Then, for each qualified circle, build a PriIndex instance, plus zero or more SecIndex instances representing other names with the same center coordinates, and throw all these instances into a list.

  2. Sort the list using the function defined in Section 21.2, “BaseIndex.__cmp__(): Comparator”.

  3. For each element of the sorted list, call its .html() method to generate the XHTML form of the index entry.

# - - -   b u i l d I n d e x S e c t i o n

def buildIndexSection(form, db, firstYear, lastYear, isOverlap):
    '''Build the index of all circles.

      [ (form is an et.Element) and
        (db is a pycbc.CBCDatabase instance) and
        (firstYear is the first included year number in
        year-number format) and
        (lastYear is the last included year number in year-number
        format) and
        (isOverlap is True iff overlap is desired) ->
          form  :=  form with index entries added for circles in
              the region with code RegArgs().reg_code that fall within the
              year range specified by RegArgs() ]          

For the logic that builds the primary and secondary entries, see Section 8.9, “regx.cgi: buildEntries(): Build all the BaseIndex instances”.

    #-- 1
    # [ entryList  :=  instances of BaseEntry representing index
    #       elements from db for region code RegArgs().reg_code ]
    entryList = buildEntries(db, RegArgs().reg_code, firstYear,
                             lastYear, isOverlap)

    #-- 2
    # [ entryList  :=  entryList ordered by the .__cmp__() method of
    #                  its elements ]

    #-- 3
    # [ form  +:=  XHTML renderings of the elements of entryList in
    #              the same order ]
    for entry in entryList: