From 3dc405d3475d99f54c00ec8b3b49137c0aa0c9ca Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 27 Jan 2012 07:51:53 +0100 Subject: [PATCH 1/3] work in progress: new package docgen for document generation --- docgen/README.txt | 10 +++++++ docgen/__init__.py | 1 + docgen/base.py | 55 ++++++++++++++++++++++++++++++++++ docgen/tests.py | 26 ++++++++++++++++ docgen/word_macros.pt | 70 +++++++++++++++++++++++++++++++++++++++++++ docgen/word_page.pt | 23 ++++++++++++++ 6 files changed, 185 insertions(+) create mode 100644 docgen/README.txt create mode 100644 docgen/__init__.py create mode 100644 docgen/base.py create mode 100755 docgen/tests.py create mode 100644 docgen/word_macros.pt create mode 100644 docgen/word_page.pt diff --git a/docgen/README.txt b/docgen/README.txt new file mode 100644 index 0000000..b9d009f --- /dev/null +++ b/docgen/README.txt @@ -0,0 +1,10 @@ +================================================================ +docgen - Document Generation from Result Sets and XML Structures +================================================================ + + >>> from zope import component + >>> from zope.publisher.browser import TestRequest + + >>> from cybertools.docgen.base import WordDocument + >>> doc = WordDocument(None, TestRequest) + diff --git a/docgen/__init__.py b/docgen/__init__.py new file mode 100644 index 0000000..5bb534f --- /dev/null +++ b/docgen/__init__.py @@ -0,0 +1 @@ +# package diff --git a/docgen/base.py b/docgen/base.py new file mode 100644 index 0000000..cc961e4 --- /dev/null +++ b/docgen/base.py @@ -0,0 +1,55 @@ +# +# Copyright (c) 2012 Helmut Merz helmutm@cy55.de +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +""" +View definitions for generation of documents. +""" + +from zope.app.pagetemplate import ViewPageTemplateFile +from zope.cachedescriptors.property import Lazy +from zope.publisher.browser import BrowserPage + +word_template = ViewPageTemplateFile('word_page.pt') + + +class Base(BrowserPage): + + def __call__(self): + return self.index() + + +class WordDocument(Base): + + index = word_template + + def setHeader(self, data, filename='document'): + fn = '%s.doc' % filename + response = self.request.response + response.setHeader('Cache-Control', '') + response.setHeader('Pragma', '') + response.setHeader('Content-Type', 'application/msword;charset=utf-8') + response.setHeader('Content-Length', len(data)) + response.setHeader('Content-Disposition', 'filename="%s"' % fn) + + mswordXml = """ + + Print + 90 + + + """ diff --git a/docgen/tests.py b/docgen/tests.py new file mode 100755 index 0000000..48cd742 --- /dev/null +++ b/docgen/tests.py @@ -0,0 +1,26 @@ +""" +unit tests, doc tests +""" + +import unittest, doctest +from zope.testing.doctestunit import DocFileSuite +from zope.interface.verify import verifyClass +from zope.interface import implements + + +class Test(unittest.TestCase): + "Basic tests for the docgen package." + + def testInterfaces(self): + pass + + +def test_suite(): + flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS + return unittest.TestSuite(( + unittest.makeSuite(Test), + DocFileSuite('README.txt', optionflags=flags), + )) + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite') diff --git a/docgen/word_macros.pt b/docgen/word_macros.pt new file mode 100644 index 0000000..99c8fc0 --- /dev/null +++ b/docgen/word_macros.pt @@ -0,0 +1,70 @@ + + + + +
+ +
+

Title

+
+

+
+ + + + +
+ Start date: +

startDate

+
+ +

Index

+
+

1. Introduction

+
+ +

For ... + .

+ +
+
+ +
+

Annex 1: ...

+
+
+ +
+
+

+ Footnote Text...

+ +
+
+
+
+

$refNumber

+
+
+
Page + PAGE +
+
+
+
+ + + + diff --git a/docgen/word_page.pt b/docgen/word_page.pt new file mode 100644 index 0000000..649c9dc --- /dev/null +++ b/docgen/word_page.pt @@ -0,0 +1,23 @@ + + + + Document + + + + + + + + +
Body Text
+ + + From f9e89cff933ef535c4e31f81282856f995181a6d Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 27 Jan 2012 07:52:50 +0100 Subject: [PATCH 2/3] add info in README of reporter package --- reporter/README.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/reporter/README.txt b/reporter/README.txt index f63074e..68772f5 100644 --- a/reporter/README.txt +++ b/reporter/README.txt @@ -2,7 +2,10 @@ A Basic API for Reports and Listings ==================================== - ($Id$) +Note: The basic reporting stuff (with Report, ReportInstance, Field, and ResultSet +classes) is now in cybertools.composer.report. The stuff defined here is, +however, still used in some (TUM) projects and may also be useful in other +cases. TO DO... From 46e8939ee18bf8847ffe37393430143ea2b28019 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sat, 28 Jan 2012 19:49:19 +0100 Subject: [PATCH 3/3] work in progress: document generation --- docgen/base.py | 8 ++++++-- docgen/word_page.pt | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docgen/base.py b/docgen/base.py index cc961e4..71ef7fd 100644 --- a/docgen/base.py +++ b/docgen/base.py @@ -29,8 +29,12 @@ word_template = ViewPageTemplateFile('word_page.pt') class Base(BrowserPage): - def __call__(self): - return self.index() + encoding = 'UTF-8' + + def __call__(self, *args, **kw): + data = self.index(*args, **kw).encode(self.encoding) + self.setHeader(data) + return data class WordDocument(Base): diff --git a/docgen/word_page.pt b/docgen/word_page.pt index 649c9dc..0856a07 100644 --- a/docgen/word_page.pt +++ b/docgen/word_page.pt @@ -17,7 +17,7 @@ -
Body Text
+