# - - - a d d R a d i o s def addRadios(form, db): '''Build the table of radiobuttons [ (form is a form et.Element) and (db is a pycbc.CBCDatabase instance) -> form +:= radiobuttons to select regions in db ] '''
We arrange the regional radiobuttons into columns using an ordinary XHTML table. It would be easier to spread the regions across the row first and then down the table, but this, in the author's opinion, is extremely crass. People expect to look across the tops of the columns to locate the correct column, then down the column.
If the number of regions is not an exact multiple of the
number of columns, we also want the short column to be the
last one. To compute the number of rows, we use Section 51, “
divCeil(): Discrete rounding
#-- 1 # [ regionList := all the Region instances from db, in ascending # order by region name # nRows := number of rows necessary to arrange those instances # into columns with the last column short ] regionList = [ reg for reg in db.genRegions() ] nRows = lib.divCeil(len(regionList), N_REG_COLS)
#-- 2 # [ form +:= a new table element with N_REG_COLS columns # table := that table element ] table = subElement(form, E.table(cellpadding='8', border='0', frame='void')) for k in range(N_REG_COLS): table.append(E.col(align='left'))
For the logic that builds each row of the table, see Section 6.8, “
buildRow(): Build one row of region
#-- 3 # [ table +:= rows displaying regionList as nRows rows by # N_REG_COLS columns ] for rowx in range(nRows): #-- 3 body # [ rowx is an index in regionList -> # table +:= a row displaying a slice across regionList # for row (rowx) displayed as nRows rows by # N_REG_COLS columns ] buildRow(table, regionList, nRows, rowx)