From: W. Trevor King Date: Fri, 29 Aug 2008 00:43:04 +0000 (-0400) Subject: Added simple form handling to Location search door warnings. X-Git-Tag: 0.3~10 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1efe4020945931ce3508a3bdfe516144e2bc070e;p=chemdb.git Added simple form handling to Location search door warnings. Also fixed a minor ?bug? with the door warning output in cases where there are no NFPA "Other" chemicals. --- diff --git a/chem_db.py b/chem_db.py index aabe348..cb9af64 100644 --- a/chem_db.py +++ b/chem_db.py @@ -282,8 +282,13 @@ class docgen (object) : 'Reactivity', 'Other'], [Healths, Fires, Reactivities, Others]) : - string += " \multicolumn{3}{c}{\Tstrut %s : %s} \\\\\n" \ - % (name, NFPA_maxs[field]) + if (not hasattr(NFPA_maxs[field], '__len__')) \ + or len(NFPA_maxs[field]) > 0 : + string += " \multicolumn{3}{c}{\Tstrut %s : %s} \\\\\n" \ + % (name, NFPA_maxs[field]) + else : # Print "Other" instead of "Other : []" + string += " \multicolumn{3}{c}{\Tstrut %s} \\\\\n" \ + % (name) for db_id in array : record = self.db.record(db_id) string += " %s & %s & %s \\\\\n" \ diff --git a/chem_web.py b/chem_web.py index ba24324..c49ffc7 100755 --- a/chem_web.py +++ b/chem_web.py @@ -128,6 +128,7 @@ class edit (object) : update = False for field in db.field_list() : if newvals[field] != record[field] : + # TODO: add validation! update=True record[field] = newvals[field] if 'MSDS source' in newvals : @@ -181,7 +182,18 @@ class docs (object) : if name == 'door_warning.pdf' : path = dgen.door_warning() print file(path, 'rb').read() , - + def POST(self, name): + """ + Read the form input and print the appropriate file. + """ + db._refresh() + formdata = web.input() + user_regexp = formdata['regexp'] + regexp = self.validate_string(user_regexp) + path = dgen.door_warning(lambda r: r['Location'] == regexp ) # no regexp matching yet, work in progress + print file(path, 'rb').read() , + def validate_string(self, string): # work in progress + return string class login (object) : "Print an alphabetized index of all existing pages"