diff options
-rw-r--r-- | python/server.py | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/python/server.py b/python/server.py index 3c6ddb91..88518abf 100644 --- a/python/server.py +++ b/python/server.py @@ -1,13 +1,56 @@ +# -*- coding: utf-8 -*- + import ledger import cgi import sys +import types from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer +from Cheetah.Template import Template +from Cheetah.Filters import WebSafe + +class UnicodeFilter(WebSafe): + def filter(self, s, **kargs): + return WebSafe.filter(self, s, str=unicode, **kargs) + +templateDef = '''#encoding utf-8 + <html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> + <title>$title</title> + </head> + <body> + <table> + #for $xact in $journal + #for $post in $xact + <tr> + <td>$post.date</td> + <td>$post.xact.payee</td> + <td>$post.account</td> + <td>$post.amount</td> + </tr> + #end for + #end for + </table> + </body> + </html> +''' + class LedgerHandler(BaseHTTPRequestHandler): + def __init__(self, *args): + self.journal = ledger.Journal('/Users/johnw/src/ledger/doc/sample.dat') + BaseHTTPRequestHandler.__init__(self, *args) + def do_GET(self): - print "Saw a GET request!" - sys.exit(0) + tmpl = Template(templateDef, filter=UnicodeFilter) + + tmpl.title = 'Ledger Journal' + tmpl.journal = self.journal + + html = unicode(tmpl) + html = html.encode('utf-8') + self.wfile.write(html) def do_POST(self): print "Saw a POST request!" |