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

6.9. buildRegionCell(): Build one cell of the region radiobuttons table

pickaregion.cgi
# - - -   b u i l d R e g i o n C e l l

def buildRegionCell(tr, region):
    '''Build one td element in the table of region radiobuttons.

      [ (tr is a tr et.Element) and
        (region is a pycbc.Region instance) ->
          tr  +:=  a td element containing a radiobutton labeled with
                   the name from region, checked iff region.reg_code
                   is CHECKED_REGION ]
    '''

The first step is to extract the region code and use it to construct the id value of the radiobutton. We also construct a small dictionary for the for= attribute of the label element, since for is a Python reserved word.

pickaregion.cgi
    #-- 1
    # [ reg_code  :=  region code from region
    #   radioId  :=  (that region code) + REG_RADIO_SUFFIX ]
    reg_code = region.reg_code
    radioId = reg_code + REG_RADIO_SUFFIX

If this is the radiobutton for region CHECKED_REGION, set up a dictionary to add the checked='checked' attribute; otherwise this dictionary is empty.

pickaregion.cgi
    #-- 2
    if reg_code == CHECKED_REGION: checker = {'checked': 'checked'}
    else: checker = {}

    #-- 3
    # [ tr  +:=  a new td element containing an input element for
    #            the radiobutton and a label element showing region's
    #            name ]
    tr.append(
        E.td(
            E.input(checker, type='radio',
                    name=topform.REG_RADIOS,
                    value=reg_code, id=radioId),
            E.label(lib.FOR(radioId), region.reg_name)))