""" Open Source Garden An exercise based on: Building Cloud Applications with Google AppEngine Charles Severance et al (a work in progress) CSS buttons courtesy of Alex Griffioen: http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html I Ching consultant: Glenn Stockton (CSO) http://controlroom.blogspot.com/2009/01/more-school-business.html """ import os import logging import wsgiref.handlers from google.appengine.ext import webapp from google.appengine.ext.webapp import template import iching def doRender(self, tname = 'index.htm', values = { }): temp = os.path.join(os.path.dirname(__file__), 'templates/' + tname) if not os.path.isfile(temp): return False # Make a copy of the dictionary and add the path newval = dict(values) newval['path'] = self.request.path outstr = template.render(temp, newval) self.response.out.write(outstr) return True class MainHandler(webapp.RequestHandler): def get(self): thedata = iching.throw() self.response.encoding = "UTF-8" doRender(self, "iching.html", thedata) class MotdHandler(webapp.RequestHandler): def get(self): self.response.encoding = "UTF-8" path = self.request.path if doRender(self,path) : return if doRender(self,'index.htm') : return self.response.out.write('Error - unable to find index.htm') def main(): application = webapp.WSGIApplication( [('/motd.html', MotdHandler), ('/.*', MainHandler)], debug=True) wsgiref.handlers.CGIHandler().run(application) main()