for id in ids: world = cherrypy.request.db.query(World).get(id) world.randomNumber = rp() worlds.append(world.serialize()) cherrypy.request.db.commit() return worlds @cherrypy.expose def fortune(self): fortunes = cherrypy.request.db.query(Fortune).all() fortunes.append(Fortune(id=0, message="Additional fortune added at request time.")) fortunes.sort(key=attrgetter("message")) html = "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>" for f in fortunes: html += "<tr><td>" + str(f.id) + "</td><td>" + cgi.escape(f.message) + "</td></tr>" html += "</table></body></html>" return html if __name__ == "__main__": # Register the SQLAlchemy plugin from saplugin import SAEnginePlugin DBDRIVER = 'mysql' DATABASE_URI = '%s://benchmarkdbuser:benchmarkdbpass@TFB-database:3306/hello_world?charset=utf8' % (DBDRIVER) SAEnginePlugin(cherrypy.engine, DATABASE_URI).subscribe() # Register the SQLAlchemy tool from satool import SATool cherrypy.tools.db = SATool() cherrypy.server.socket_host = '0.0.0.0' cherrypy.quickstart(CherryPyBenchmark(), '', {'/': {'tools.db.on': True, 'log.screen': False, 'log.access_file': ''}})
'global': { # 'environment' : 'production' 'engine.autoreload.on': False, } }) conf = { '/': { 'tools.db.on': True }, '/admin': { 'tools.auth_digest.on': True, 'tools.auth_digest.realm': 'lunch', 'tools.auth_digest.get_ha1': cherrypy.lib.auth_digest.get_ha1_dict_plain(userpassdict), 'tools.auth_digest.key': 'd8f0238a5c3bae97', }, '/static': { 'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.join(os.getcwd(), "static") } } if DEBUG: Manager(cherrypy.engine, 1).subscribe() else: Manager(cherrypy.engine, 60).subscribe() SAEnginePlugin(cherrypy.engine, 'sqlite:///'+cfg.dbfile).subscribe() cherrypy.tools.db = SATool() cherrypy.quickstart(Lunch(), '/', conf)