[Formed-commits] r300 - in trunk: . formed/formed/plugins/export
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Dec 17 11:33:38 CET 2008
Author: frank
Date: 2008-12-17 11:33:37 +0100 (Wed, 17 Dec 2008)
New Revision: 300
Modified:
trunk/ChangeLog
trunk/formed/formed/plugins/export/latex.py
Log:
LaTeX export reworked: Section marks and help text placeholder.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-12-04 10:39:22 UTC (rev 299)
+++ trunk/ChangeLog 2008-12-17 10:33:37 UTC (rev 300)
@@ -1,3 +1,10 @@
+2008-12-17 Frank Koormann <frank.koormann at intevation.de>
+
+ * formed/formed/plugins/export/latex.py: Export form as set of
+ latex tables to be included into a master document. The export
+ generates section marks to structure the form and placeholders for
+ help texts to be merged in by a post processing step.
+
2008-12-04 Sascha L. Teichmann <teichmann at intevation.de>
* formed/formed/model/expr.py: Added 'today' which pushes the current date
Modified: trunk/formed/formed/plugins/export/latex.py
===================================================================
--- trunk/formed/formed/plugins/export/latex.py 2008-12-04 10:39:22 UTC (rev 299)
+++ trunk/formed/formed/plugins/export/latex.py 2008-12-17 10:33:37 UTC (rev 300)
@@ -9,6 +9,7 @@
# Authors:
# Sascha L. Teichmann <teichmann at intevation.de>
# Torsten Irlaender <torsten.irlaender at intevation.de>
+# Frank Koormann <frank.koormann at intevation.de>
#
from formed.plugins.ui.controls import FileDialogFilter
@@ -21,44 +22,50 @@
from cgi import escape
FUNCTION2ANONTYPE = {u'suppress_value': u'Wert wird gelöscht',
- u'shorten_value': u'Wert wird auf %(wert)s gekürzt',
- u'hash_value': u'Hashwert wird mit %(wert)s berechnet',
- u'suppress_value2': u'Wert wird gelöscht 2',
- u'check_bool': u'Prüfen des Werts %(wert)s',
- u'get_age': u'Zurücksetzen auf den 01.01 des Geburtsjahres'}
+ u'shorten_value': u'Wert wird auf %(wert)s Stellen gekürzt',
+ u'hash_value': u'Hashwert wird mit %(wert)s berechnet',
+ u'suppress_value2': u'Wert wird gelöscht 2',
+ u'check_bool': u'Prüfen des Werts %(wert)s',
+ u'get_age': u'Zurücksetzen auf den 01.01. des Geburtsjahres'}
-LATEX_HEADER = u'''
-\\documentclass{article}
+TABLE_HEADER = u'''
+{\\small
+\\begin{longtable}[t]{p{6cm}p{3.5cm}p{3cm}p{7.5cm}}
+{\\bfseries Feld} & {\\bfseries Typ}
+ & {\\bfseries Anonymisierung} & {\\bfseries DB-Feld}
+\\\\
+\\hline
+\\endfirsthead
-\\title{Anonymisierung der Formularfelder}
-\\usepackage{supertabular, german, longtable}
-\\usepackage[latin1]{inputenc}
+\\multicolumn{4}{l}{\sl ... Fortsetzung}
+\\\\
+\\hline
+{\\bfseries Feld} & {\\bfseries Typ}
+ & {\\bfseries Anonymisierung} & {\\bfseries DB-Feld}
+\\\\
+\\hline
+\\endhead
-\\begin{document}
-\\maketitle
-\\begin{longtable}[ht]{|p{6cm}|p{3cm}|p{3cm}|}
- \\hline
- Formular Bezeichung & Typ & Art Anonymisierung \\\\
- \\hline\\hline
+\\multicolumn{4}{r}{\\sl Fortsetzung ...}
+\\endfoot
+
+\\endlastfoot
'''
-LATEX_FOOTER = u'''
-\\hline
-\\end{longtable}
-\\end{document}
+TABLE_FOOTER = u'''
+\\end{longtable}}
'''
+def texize(s): return s.replace('$','\\$').replace('_','\\_').replace('%','\\%').replace('~','\\url{~}').replace('"','\\url{"}').replace('^','\\url{^}').replace('#','\\#')
def esc(s):
- if s:
- s = s.replace('_', '-')
- return s
+ if s: return escape(s)
return ""
-def fillRow(k):
+def fillRow(k, field = ""):
c = [esc(i) for i in k]
- return "& ".join(c) + "\\\\"
+ return texize("" + " & ".join(c)) + ("\\\\ %s\n \\hline" % field )
def getAnonymizeType(name):
if name:
@@ -79,69 +86,98 @@
data.ChoiceNode: "Auswahlliste"
}
+SECTION_LEVEL = ["\\section", "\\subsection", "\\subsubsection", "\\paragraph"]
+
class RecursiveExporter(ModeChecker):
@checkMode
- def _matchGroup(self, nc, out):
+ def _matchGroup(self, nc, out, d):
if not nc.isInvisible():
- d = min(5, max(1, nc.depth()))
- print >> out, '\\multicolumn{3}{|l|}{\\textbf{%s}} \\\\' % esc(nc.getDescription())
- print >> out, '\\hline'
+ d = min(4, d+1)
+ print >> out, TABLE_FOOTER
+ print >> out, texize('%s{%s}\n%s' % (
+ SECTION_LEVEL[d-1], esc(nc.getDescription()),
+ esc(nc.getAnnotation())))
+ print >> out, TABLE_HEADER
+ return d
@checkMode
- def _matchPage(self, nc, out):
- d = min(5, max(1, nc.depth()))
- print >> out, '\\multicolumn{3}{|l|}{\\textbf{%s}} \\\\' % esc(nc.getDescription())
- print >> out, '\\hline'
+ def _matchPage(self, nc, out, d):
+ d = min(4, d+1)
+ print >> out, TABLE_FOOTER
+ print >> out, texize('%s{%s}\n%s' % (
+ SECTION_LEVEL[d-1], esc(nc.getDescription()),
+ esc(nc.getAnnotation())))
+ print >> out, TABLE_HEADER
+ return d
@checkMode
+ def _matchInfo(self, nc, out):
+ print >> out, "%%db_%s" % nc.getName()
+
+ @checkMode
def _matchText(self, nc, out):
print >> out, fillRow([
nc.getDescription(),
LOCAL_NAME.get(nc.__class__, "Unbekannt"),
- getAnonymizeType(nc.getFunction())
- ])
- print >> out, '\\hline'
+ getAnonymizeType(nc.getFunction()),
+ nc.getName(),
+# nc.getAttribute("size"),
+# nc.getAttribute("maxlength"),
+# nc.getAttribute("minvalue"),
+# nc.getAttribute("maxvalue"),
+# nc.getAttribute("rows"),
+# nc.getAttribute("cols"),
+# nc.getAnnotation()]
+ ], "%%db_%s" % nc.getName())
+ #print >> out, "\\multicolumn{4}{p{20cm}}{%%db_%s\n}\\\\ \\hline" % nc.getName()
+ #print >> out, "%%db_%s" % nc.getName()
@checkMode
def _matchBoolean(self, nc, out):
- print >> out, '%s & & \\\\' % esc(nc.getDescription())
- print >> out, '\\hline'
+# print >> out, '%s & & \\\\' % esc(nc.getDescription())
+# print >> out, '\\hline'
+ pass
@checkMode
def _matchChoice(self, nc, out):
desc = esc(nc.getDescription())
ln = esc(LOCAL_NAME.get(nc.__class__, "unbekannt"))
+ name = esc(nc.getName())
anon = getAnonymizeType(nc.getFunction())
- print >> out, '%s & %s & %s \\\\' % (esc(desc), esc(ln), esc(anon))
- print >> out, '\\hline'
- self._exportRecursiveAsLaTeX(nc, out)
+ print >> out, fillRow([desc, ln, anon, name],
+ "%%db_%s" % nc.getName())
+ #print >> out, "\\multicolumn{4}{p{20cm}}{%%db_%s\n}\\\\ \\hline" % nc.getName()
+ #print >> out, "%%db_%s" % nc.getName()
@checkMode
def _matchExternal(self, nc, out):
c = nc.getChildren()
if c: c = len(c)
else: c = 0
- print >> out, u'& Externe Liste mit %d Einträgen & \\\\' % c
- print >> out, '\\hline'
+ print >> out, '<tr><td></td><td>Externe Liste mit %d Einträgen</td><td colspan="8"></td><td></td></tr>' % c
@checkMode
- def _exportRecursiveAsLaTeX(self, node, out):
+ def _exportRecursiveAsLaTeX(self, node, out, d):
+ d_ = d
for nc in node.children:
+ d = d_
if isinstance(nc, data.GroupNode):
- self._matchGroup(nc,out)
+ d = self._matchGroup(nc,out, d)
elif isinstance(nc, data.RadioNode):
self._matchChoice(nc, out)
elif isinstance(nc, data.ChoiceNode):
self._matchChoice(nc, out)
elif isinstance(nc, data.PageNode):
- self._matchPage(nc, out)
+ d = self._matchPage(nc, out, d)
elif isinstance(nc, data.ExternalChoiceListLeaf):
self._matchExternal(nc,out)
elif isinstance(nc, data.BoolLeaf) and \
isinstance(nc.getParent(), data.ChoiceNode):
self._matchBoolean(nc, out)
continue
+ elif isinstance(nc, data.InfoLeaf):
+ self._matchInfo(nc, out)
if isinstance(nc, (
data.TextLeaf,
@@ -153,11 +189,11 @@
if isinstance(nc, (data.GroupNode, data.PageNode)):
- self._exportRecursiveAsLaTeX(nc, out)
+ self._exportRecursiveAsLaTeX(nc, out, d)
def exportRecursiveAsLaTeX(self, node, out):
self.prepareDescent()
- self._exportRecursiveAsLaTeX(node, out)
+ self._exportRecursiveAsLaTeX(node, out, 0)
class ExportAsLaTeXFilter(FileDialogFilter):
@@ -186,15 +222,13 @@
allModes = main.getAllModes()
out = None
try:
- out = codecs.open(path, "wb", "Latin1")
- print >> out, LATEX_HEADER
+ out = codecs.open(path, "wb", "UTF-8")
exporter = RecursiveExporter(mode, allModes)
exporter.exportRecursiveAsLaTeX(root, out)
-
- print >> out, LATEX_FOOTER
finally:
if out:
+ print >> out, TABLE_FOOTER
try: out.close()
except: pass
More information about the Formed-commits
mailing list