summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-20 23:23:05 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-20 23:23:05 -0500
commit92d2310548e8e51b6496385d8808cca8eaf1aa04 (patch)
treef3372affdeb275bf544801a18b2b9d530fcbf868 /python
parent117dddabd4f883de4f464821f9567d889a6fa449 (diff)
downloadfork-ledger-92d2310548e8e51b6496385d8808cca8eaf1aa04.tar.gz
fork-ledger-92d2310548e8e51b6496385d8808cca8eaf1aa04.tar.bz2
fork-ledger-92d2310548e8e51b6496385d8808cca8eaf1aa04.zip
Extended python/server.py, which now uses Cheetah
Diffstat (limited to 'python')
-rw-r--r--python/server.py47
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!"