# - - - H i s t A r g s . _ _ i n i t _ _
def __init__(self):
'''Constructor.
'''
#-- 1
if HistArgs.initialized:
return
else:
HistArgs.initialized = True
#-- 2
# [ form := the incoming CGI arguments as a cgi.FieldStorage
# instance ]
form = cgi.FieldStorage()
For the logic that retrieves both the first and last year
entry values, see Section 54, “yearCheck(): Validate a year number form
entry”.
#-- 3
# [ if form has a valid regform.FIRST_YEAR_ENTRY value ->
# self.firstYear := that value in year-number format
# else -> raise ScriptError ]
self.firstYear = lib.yearCheck(form, regform.FIRST_YEAR_ENTRY,
"First year number", lib.MIN_YEAR)
#-- 4
# [ if form has a valid regform.LAST_YEAR_ENTRY value ->
# self.lastYear := that value in year-number format
# else -> raise ScriptError ]
self.lastYear = lib.yearCheck(form, regform.LAST_YEAR_ENTRY,
"Last year number", lib.MAX_YEAR)
For checkboxes, we receive a value only if the user checked
the checkbox. We can test for this by using Python's
“in” operator; we don't care
about the actual value, just whether or not the
dictionary-like FieldStorage instance has that
key.
#-- 5
# [ if form has a value for field LUMP_SUBSP_CB ->
# self.lumpSubsp := True
# else ->
# self.lumpSubsp := False ]
self.lumpSubsp = regform.LUMP_SUBSP_CB in form
#-- 6
self.nmAlias = regform.NM_ALIAS_CB in form
Because year lumping of columns is selected by two
radiobuttons instead of a checkbox (the better to explain the
consequences of each choice), we use the FieldStorage.getfirst() method to return the value of
the selected radiobutton. If for some reason there is no
value for this field, we default to true.
#-- 7
# [ if form has a YEAR_LUMP_RADIOS value ->
# self.yearLumping := that value as a bool
# else ->
# self.yearLumping := True ]
self.yearLumping = bool(int(
form.getfirst(regform.YEAR_LUMP_RADIOS, 0)))
There was a subtle bug in the previous line: the call
to int() was omitted, and bool('0') yields True, not
False!
#-- 8
# [ if form has a PDF value ->
# self.pdf := True
# else ->
# self.pdf := False ]
self.pdf = regform.PDF in form
Last in the control group are the and buttons. There are two ways that this script is called:
Each primary entry on the regional index page is a
button whose name has
the form S_. This is a
request for a history report for just that one
center.
ddmm-DDDMM
Because every primary entry on the regional index
page has its own checkbox, when the user clicks the
button, whose name is
ALL, we expect multiple values
for the LAT_LON element, each
with
If we don't get any at all, we raise a ScriptError to tell the user to check at least one
box.
In any case, each value of the LAT_LON
element should have the format ". See Section 10.39, “ddmm-DDDMM"HistArgs._findLatLons(): Check all lat-lon
arguments”.
#-- 9
# [ if (form has a key ALL) and
# (form has at least one key LAT_LON) and
# (the LAT_LON values are valid "ddmm-DDDMM" coordinates) ->
# self.latLonList := those coordinates as a list of
# ("ddmm", "DDDMM") tuples
# else if (form has a key whose name starts with
# regform.S_ and ending with valid "ddmm-DDDMM"
# coordinates) ->
# self.latLonList := a list containing one tuple of
# the form ("ddmm", "DDDMM") with that ending
self.latLonList = self._findLatLons(form)