Added simple form handling to Location search door warnings.
authorW. Trevor King <wking@drexel.edu>
Fri, 29 Aug 2008 00:43:04 +0000 (20:43 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 29 Aug 2008 00:43:04 +0000 (20:43 -0400)
Also fixed a minor ?bug? with the door warning output in cases where
there are no NFPA "Other" chemicals.

chem_db.py
chem_web.py

index aabe3484611102254e6b230ebeaad6d1d13cb818..cb9af640f26e6dfecf109a10b7e0b3aecd4c0cbd 100644 (file)
@@ -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" \
index ba24324044d7038d43cd0ee581e74ea6bf67acdb..c49ffc7d576fd7d3d09d43bd7cc4e5df663051b7 100755 (executable)
@@ -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"