From 92d2310548e8e51b6496385d8808cca8eaf1aa04 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 20 Nov 2009 23:23:05 -0500 Subject: Extended python/server.py, which now uses Cheetah --- python/server.py | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'python') 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 + + + + $title + + + + #for $xact in $journal + #for $post in $xact + + + + + + + #end for + #end for +
$post.date$post.xact.payee$post.account$post.amount
+ + +''' + 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!" -- cgit v1.2.3