From 22c4d185e122da6ea1c71d17af009a6c55217c39 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 21 Nov 2010 21:33:01 -0500 Subject: [PATCH] Export HTML for Databooks. --- tablib/formats/_html.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tablib/formats/_html.py b/tablib/formats/_html.py index 786d5a3..13dc055 100644 --- a/tablib/formats/_html.py +++ b/tablib/formats/_html.py @@ -8,9 +8,12 @@ from StringIO import StringIO from tablib.packages import markup import tablib +BOOK_ENDINGS = 'h3' + title = 'html' extentions = ('html', ) + def export_set(dataset): """HTML representation of a Dataset.""" @@ -35,3 +38,16 @@ def export_set(dataset): return stream.getvalue() + +def export_book(databook): + """HTML representation of a Databook.""" + + stream = StringIO() + + for i, dset in enumerate(databook._datasets): + title = (dset.title if dset.title else 'Set %s' % (i)) + stream.write('<%s>%s\n' % (BOOK_ENDINGS, title, BOOK_ENDINGS)) + stream.write(dset.html) + stream.write('\n') + + return stream.getvalue()