Incremented chem_web version number
[chemdb.git] / chem_web.py
index 4ea9de03dc3a014ceb0672246d9f4a85e681bbe1..85b316f62b12629c271614f4b3b30d0fc5923d8e 100755 (executable)
@@ -46,7 +46,7 @@ if SSL :
       from mk_simple_certs import get_cert_filenames
       server_name = 'chem_web'
 
-__version__ = "0.2"
+__version__ = "0.3"
 
 ## For web.py, when a URL matches '/view', handle with class 'view'
 # when it matches '/edit', handle with class 'edit',
@@ -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,16 @@ 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 = re.compile(user_regexp, re.I) # Case insensitive
+            path = dgen.door_warning(lambda r: regexp.match(r['Location']))
+            print file(path, 'rb').read() ,
 
 class login (object) :
       "Print an alphabetized index of all existing pages"
@@ -438,6 +448,7 @@ class templt (object) :
                        ' <head>\n'
                        ' </head>\n'
                        ' <body>\n'
+                       '  <p>\n'
                        '  <a href="/docs/inventory.pdf">Inventory</a>\n'
                        '   in accordance with the \n'
                        '   <a href="http://www.drexelsafetyandhealth.com/lab-chem.htm#chpe7">\n'
@@ -448,6 +459,19 @@ class templt (object) :
                        '   and \n'
                        '   <a href="http://www.drexelsafetyandhealth.com/lab-chem.htm#chpe10">E-10</a>\n'
                        '   .<br>\n'
+                       '  </p>\n'
+                       '  <p>\n'
+                       '  For door warnings for subsections of the whole room,\n'
+                       '   please give a location regexp in the form below.\n'
+                       '  For example: ".*liquids" or "refrigerator".\n'
+                       '  </p>\n'
+                       '  <form action="" method="post" enctype="multipart/form-data">\n'
+                       '   <table>\n'
+                       '    <tr><td>Location regexp</td><td>:</td>\n'
+                       '     <td><input type="text" size="50" id="regexp" name="regexp"></td></tr>\n'
+                       '   </table>\n'
+                       '   <input type="submit" value="Submit" />\n'
+                       '  </form>\n'
                        ' </body>\n'
                        '</html>\n')
                  file(self.dir+'docs.html', 'w').write(docs)
@@ -475,7 +499,7 @@ class chem_web_daemon (daemon.Daemon) :
             ## How we have to start it now
             webpy_func = web.webpyfunc(urls, globals(), False)
             wsgi_func = web.wsgifunc(webpy_func)
-            web.httpserver.runsecure(wsgi_func,
+            web.httpserver.runsimple(wsgi_func,
                                      web.validip(self.options.ip),
                                      ssl_private_key_filename=self.pkey_file,
                                      ssl_certificate_filename=self.cert_file)