[Mpuls-commits] r1684 - in wasko/branches/2.0: . mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Feb 23 12:37:49 CET 2010


Author: bh
Date: 2010-02-23 12:37:43 +0100 (Tue, 23 Feb 2010)
New Revision: 1684

Modified:
   wasko/branches/2.0/ChangeLog
   wasko/branches/2.0/mpulsweb/lib/renderer.py
Log:
* mpulsweb/lib/renderer.py: Fix formatting.


Modified: wasko/branches/2.0/ChangeLog
===================================================================
--- wasko/branches/2.0/ChangeLog	2010-02-23 11:21:01 UTC (rev 1683)
+++ wasko/branches/2.0/ChangeLog	2010-02-23 11:37:43 UTC (rev 1684)
@@ -1,3 +1,7 @@
+2010-02-23  Bernhard Herzog  <bh at intevation.de>
+
+	* mpulsweb/lib/renderer.py: Fix formatting.
+
 2010-02-23  Torsten Irländer <torsten.irlaender at intevation.de>
 
 	* jmdweb: New. copied from waskaweb. Adapted imports to jmdweb. 

Modified: wasko/branches/2.0/mpulsweb/lib/renderer.py
===================================================================
--- wasko/branches/2.0/mpulsweb/lib/renderer.py	2010-02-23 11:21:01 UTC (rev 1683)
+++ wasko/branches/2.0/mpulsweb/lib/renderer.py	2010-02-23 11:37:43 UTC (rev 1684)
@@ -1,50 +1,53 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
-# 
-# This file is part of mpuls WASKA (CoMPUter-based case fiLeS - 
+#
+# This file is part of mpuls WASKA (CoMPUter-based case fiLeS -
 # Web-Anwendungs-Server fuer Kompetenzagenturen).
-# 
+#
 # mpuls WASKA is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Affero General Public License as published by the
 # Free Software Foundation, either version 3 of the License, or (at your
 # option) any later version.
-# 
+#
 # mpuls WASKA 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 Affero General Public
 # License for more details.
-# 
+#
 # You should have received a copy of the GNU Affero General Public
 # License along with mpuls WASKA. If not, see <http://www.gnu.org/licenses/>.
-# 
-# mpuls WASKA has been developed on behalf of the 
+#
+# mpuls WASKA has been developed on behalf of the
 # Projekttraeger im Deutschen Zentrum fuer Luft- und Raumfahrt e.V. (PT-DLR)
 # within the programme Kompetenzagenturen (Durchfuehrungsphase) funded by
-# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and 
+# the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and
 # European Social Fund resources.
 #
 # Authors:
 # Sascha L. Teichmann <teichmann at intevation.de>
 #
 
+import re
+from cgi import escape
+from xml.sax.saxutils import quoteattr
+from datetime import date
 import logging
+
+from pylons.i18n import _
+from pylons import g
+
 from formed.meta import UNKNOWN_STR, UNKNOWN_INT, UNKNOWN_DATE
-from formed.meta.nodecomponents import Node
-from formed.meta.nodecomponents import NodeComponent as MetaNodeComponent
-from formed.instance.tree import RepeatInstanceContainerNode, RepeatInstanceNode 
+import formed.meta.data as data
+from formed.meta.nodecomponents import Node, NodeComponent as MetaNodeComponent
+from formed.instance.tree import RepeatInstanceContainerNode, \
+     RepeatInstanceNode
 from formed.instance.backends.postgres import DBFactory as InstanceFactory
-from mpulsweb.lib.db import PostgresDBInterface 
+
+from mpulsweb.lib.db import PostgresDBInterface
 from mpulsweb.lib.helper.filters import NA
-from mpulsweb.lib.helpers import dd_mm_YYYY as format_date 
-import formed.meta.data as data
-from pylons.i18n import _
-from pylons import g
+from mpulsweb.lib.helpers import dd_mm_YYYY as format_date
 
-from cgi import escape
-from xml.sax.saxutils import quoteattr
-import re
-from datetime import date 
 
 log = logging.getLogger(__name__)
 
@@ -58,33 +61,40 @@
 
 def digits(n):
     d, c = 10, 1
-    while n >= d: d *= 10; c += 1
+    while n >= d:
+        d *= 10
+        c += 1
     return c
 
 def visibleDepth(c):
     depth = -1
     while c:
-        if not(isinstance(c, data.GroupNode) and not c.isInvisible()):
+        if not (isinstance(c, data.GroupNode) and not c.isInvisible()):
             depth += 1
         c = c.parent
     return depth
 
 
 class Text:
+
     def __init__(self, txt):
         self.txt = txt
 
     def render(self, target, weight=None):
         return self.txt
 
+
 class Div(Text):
+
     def __init__(self, txt):
         Text.__init__(self, txt)
 
     def render(self, target, width=""):
         return '<td width="%s">%s</td>\n' % ("%s%%" % width, self.txt)
 
+
 class Item(Text):
+
     def __init__(self, txt):
         Text.__init__(self, txt)
 
@@ -92,10 +102,12 @@
         width = width or "100"
         return '<td width="%s">%s</td>\n' % ("%s%%" % width, self.txt)
 
+
 class Container:
+
     def __init__(self, target):
-        self.target  = target
-        self.items   = []
+        self.target = target
+        self.items = []
 
     def append(self, item, weight=1.0):
         self.items.append((item, weight))
@@ -114,7 +126,9 @@
             out.append('</table>')
         return "".join(out)
 
+
 class ChoiceContainer(Container):
+
     def render(self, doBreak=True):
         out = []
         if self.items:
@@ -123,15 +137,16 @@
                 out.append(data)
         return "".join(out)
 
+
 class ViewRenderer:
 
     def __init__(self, it=None, page=None, ro_mode=True):
-        self.it              = it # instancetree
-        self.page            = page
-        self.stateStack      = None
+        self.it = it # instancetree
+        self.page = page
+        self.stateStack = None
         self.containersStack = None
-        self.ro_mode         = ro_mode
-        self.tabindex        = 3
+        self.ro_mode = ro_mode
+        self.tabindex = 3
 
     def next_tabindex(self):
         tabindex = self.tabindex
@@ -142,18 +157,24 @@
 
         out = []
         if not self.ro_mode:
-            out.append('<form id="formularpage" action="/formularpage/save" accept-charset="UTF-8" method="POST">\n')
+            out.append('<form id="formularpage"'
+                       ' action="/formularpage/save"'
+                       ' accept-charset="UTF-8" method="POST">\n')
             # Add submitbutton at the top of the page too
             out.append('<div class="widget formbuttons">')
-            out.append('<input type="submit" name="save" value="%s" %s>' % (_('Save'), self.next_tabindex()))
+            out.append('<input type="submit" name="save" value="%s" %s>'
+                       % (_('Save'), self.next_tabindex()))
             if showNext:
-                out.append('&nbsp;<input type="submit" name="savenext" value="%s" %s>' % (_('Save and proceed'), self.next_tabindex()))
+                out.append('&nbsp;<input type="submit" name="savenext"'
+                           ' value="%s" %s>'
+                           % (_('Save and proceed'), self.next_tabindex()))
             out.append('</div>')
         out.append('<div class="widget formfields">')
-        out.append('<input type="hidden" name="page" value="%s">' % (self.page.getIdentifier()))
+        out.append('<input type="hidden" name="page" value="%s">'
+                   % (self.page.getIdentifier()))
 
         self.stateStack = []
-        self.containersStack = [[Container(None) ]]
+        self.containersStack = [[Container(None)]]
         #for item in self.page.getChildren():
         #    self._renderChild(item)
         #self._renderChild(self.page)
@@ -164,16 +185,19 @@
         out.append('</div>')
         if not self.ro_mode:
             out.append('<div class="widget formbuttons">')
-            out.append('<input type="submit" name="save" value="%s" %s>' % (_('Save'), self.next_tabindex()))
+            out.append('<input type="submit" name="save" value="%s" %s>'
+                       % (_('Save'), self.next_tabindex()))
             if showNext:
-                out.append('&nbsp;<input type="submit" name="savenext" value="%s" %s>' % (_('Save and proceed'), self.next_tabindex()))
+                out.append('&nbsp;<input type="submit" name="savenext"'
+                           ' value="%s" %s>'
+                           % (_('Save and proceed'), self.next_tabindex()))
             out.append('</div>')
             out.append('</form>\n')
 
         return "".join(out)
 
     def toTarget(self, item, target):
-        weight = None 
+        weight = None
         if target:
             m = TARGET.match(target)
             if m:
@@ -200,8 +224,10 @@
         out = []
         error = node.hasErrors() and "error" or ""
         if labeltag:
-            out.append('<label for="%s"><a class="%s" name="f_%s">%s</a></label>' % 
-            (node.getIdentifier(), error, node.getIdentifier(),meta.getDescription()))
+            out.append('<label for="%s"><a class="%s" name="f_%s">'
+                       '%s</a></label>'
+                       % (node.getIdentifier(), error, node.getIdentifier(),
+                          meta.getDescription()))
         else:
             out.append('%s' %  meta.getDescription())
         out.append(' ')
@@ -212,11 +238,18 @@
 
         out = []
         if meta.hasHelp():
-            out.append('<a href="/annotations/help/%s" target="_blank"><img src="/images/icons/formular/help.png" alt="help"></a>' % meta.getName())
+            out.append('<a href="/annotations/help/%s" target="_blank">'
+                       '<img src="/images/icons/formular/help.png" alt="help">'
+                       '</a>'
+                       % meta.getName())
         if meta.hasRequired():
-            out.append('<a href="/annotations/required/%s" target="_blank"><img src="/images/icons/formular/required.png" alt="required"></a>' % meta.getName())
+            out.append('<a href="/annotations/required/%s" target="_blank">'
+                       '<img src="/images/icons/formular/required.png"'
+                       ' alt="required"></a>' % meta.getName())
         if meta.hasEvaluation():
-            out.append('<a href="/annotations/evaluation/%s" target="_blank"><img src="/images/icons/formular/evaluation.png" alt="evaluation"></a>' % meta.getName())
+            out.append('<a href="/annotations/evaluation/%s" target="_blank">'
+                       '<img src="/images/icons/formular/evaluation.png"'
+                       ' alt="evaluation"></a>' % meta.getName())
         return "\n".join(out)
 
     def _renderErrors(self, node):
@@ -248,19 +281,20 @@
     def _renderDummyLeaf(self, node):
         meta = self._getMeta(node)
         description = meta.getDescription()
-        flags       = meta.getFlags()
-        name        = node.getIdentifier()
-        help        = node.getAnnotation([])
-        data        = node.getValue()
-        error       = node.hasErrors()
-        warn        = node.hasWarning()
-        css_class   = ['field']
+        flags = meta.getFlags()
+        name = node.getIdentifier()
+        help = node.getAnnotation([])
+        data = node.getValue()
+        error = node.hasErrors()
+        warn = node.hasWarning()
+        css_class = ['field']
         out = []
 
         out.append(self._renderLabel(node))
         out.append(self._renderAttributes(node))
         out.append('<br>')
-        out.append('<input name="%s" id="%s" value="%s" type="text">' % (name, name, data))
+        out.append('<input name="%s" id="%s" value="%s" type="text">'
+                   % (name, name, data))
         out.append('<br>')
         out.append(self._renderErrors(node))
         self.toTarget(Item("".join(out)), meta.getTarget())
@@ -277,8 +311,9 @@
         else:
             out.append("<fieldset>\n")
             if description:
-                out.append(
-                    "<legend>%s %s</legend>\n" % (self._renderLabel(node, False), self._renderAttributes(node)))
+                out.append("<legend>%s %s</legend>\n"
+                           % (self._renderLabel(node, False),
+                              self._renderAttributes(node)))
             out.append(self._renderRecursive(node))
             out.append("</fieldset>\n")
         self.toTarget(Item("".join(out)), meta.getTarget())
@@ -300,25 +335,35 @@
 
     def _renderRepeatList(self, node):
         out = []
-        for child in node.getChildren(): 
+        for child in node.getChildren():
             out.append('<tr>')
             out.append('<td class="container">')
             out.append(self._renderRecursive(child))
             out.append('</td>')
             out.append('<td class="vcontrol" width="15">')
             if not self.ro_mode:
-                out.append('<a href="/repeatgroup/delete/%s"><img src="/images/icons/formular/rg_delete.png" alt="%s"/></a>' % (child.getIdentifier(), _('Delete')))
+                out.append('<a href="/repeatgroup/delete/%s">'
+                           '<img src="/images/icons/formular/rg_delete.png"'
+                           ' alt="%s"/></a>'
+                           % (child.getIdentifier(), _('Delete')))
             out.append('</td>')
             out.append('</tr>')
         if self.ro_mode:
-            out.append('<tr><td class="hcontrol" style="text-align: right;" colspan="2">&nbsp;</td></tr>')
+            out.append('<tr><td class="hcontrol" style="text-align: right;"'
+                       ' colspan="2">&nbsp;</td></tr>')
         else:
-            out.append('<tr><td class="hcontrol" style="text-align: right;" colspan="2"><a href="/repeatgroup/new/%s">%s <img src="/images/icons/formular/rg_new.png" alt="%s"/></a></td></tr>' % (node.getIdentifier(), _('Create new'), _('Create new')))
+            out.append('<tr><td class="hcontrol" style="text-align: right;"'
+                       ' colspan="2">'
+                       '<a href="/repeatgroup/new/%s">%s'
+                       ' <img src="/images/icons/formular/rg_new.png"'
+                       ' alt="%s"/></a></td></tr>'
+                       % (node.getIdentifier(), _('Create new'),
+                          _('Create new')))
         return out
 
     def _renderRepeatNav(self, node):
         out = []
-        for child in node.getChildren(): 
+        for child in node.getChildren():
             out.append('<tr>')
             out.append('<td class="container">')
             out.append(self._renderRecursive(child))
@@ -327,14 +372,26 @@
             break;
         out.append('<tr>')
         out.append('<td class="hcontrol">')
-        out.append('<a name="%s" href="/repeatgroup/select_first/%s"><img src="/images/icons/formular/rg_first.png"/></a>' % (_('Select first'), child.getIdentifier()))
-        out.append('<a name="%s" href="/repeatgroup/select_prev/%s"><img src="/images/icons/formular/rg_prev.png"/></a>' % (_('Select previous'), child.getIdentifier()))
-        out.append('<a name="%s" href="/repeatgroup/select_next/%s"><img src="/images/icons/formular/rg_next.png"/></a>' % (_('Select next'), child.getIdentifier()))
-        out.append('<a name="%s" href="/repeatgroup/select_last/%s"><img src="/images/icons/formular/rg_last.png"/></a>' % (_('Select last'), child.getIdentifier()))
+        out.append('<a name="%s" href="/repeatgroup/select_first/%s">'
+                   '<img src="/images/icons/formular/rg_first.png"/></a>'
+                   % (_('Select first'), child.getIdentifier()))
+        out.append('<a name="%s" href="/repeatgroup/select_prev/%s">'
+                   '<img src="/images/icons/formular/rg_prev.png"/></a>'
+                   % (_('Select previous'), child.getIdentifier()))
+        out.append('<a name="%s" href="/repeatgroup/select_next/%s">'
+                   '<img src="/images/icons/formular/rg_next.png"/></a>'
+                   % (_('Select next'), child.getIdentifier()))
+        out.append('<a name="%s" href="/repeatgroup/select_last/%s">'
+                   '<img src="/images/icons/formular/rg_last.png"/></a>'
+                   % (_('Select last'), child.getIdentifier()))
         out.append(' | ?/? | ')
         if not self.ro_mode:
-            out.append('<a name="%s" href="/repeatgroup/new/%s"><img src="/images/icons/formular/rg_new.png"/></a>' % (_('Create new'), child.getIdentifier()))
-            out.append('<a name="%s" href="/repeatgroup/delete/%s"><img src="/images/icons/formular/rg_delete.png"/></a>' % (_('Delete'), child.getIdentifier()))
+            out.append('<a name="%s" href="/repeatgroup/new/%s">'
+                       '<img src="/images/icons/formular/rg_new.png"/></a>'
+                       % (_('Create new'), child.getIdentifier()))
+            out.append('<a name="%s" href="/repeatgroup/delete/%s">'
+                       '<img src="/images/icons/formular/rg_delete.png"/></a>'
+                       % (_('Delete'), child.getIdentifier()))
         out.append('</td>')
         out.append('</tr>')
         return out
@@ -359,7 +416,8 @@
     def _renderInfo(self, node):
         meta = self._getMeta(node)
         out = []
-        if meta.isInvisible(): return
+        if meta.isInvisible():
+            return
         text, depth = meta.getValue(), 1#visibleDepth(node)
         if text:
             out.append('<p class="text">')
@@ -370,9 +428,9 @@
             self.toTarget(Div("".join(out)), meta.getTarget())
 
     def _renderText(self, node):
-        meta = self._getMeta(node) 
-        out  = []
-        id   = node.getIdentifier()
+        meta = self._getMeta(node)
+        out = []
+        id = node.getIdentifier()
         data = escape(node.getValue() or "")
         size = meta.getSize()
         disabled = self.ro_mode and "disabled" or ""
@@ -380,54 +438,60 @@
         out.append(self._renderLabel(node))
         out.append(self._renderAttributes(node))
         out.append('<br>')
-        out.append('<input name="%s" id="%s" value="%s" type="text" size="%s" maxlength="%s" %s>' % (id, id, data, size, maxlength, disabled))
+        out.append('<input name="%s" id="%s" value="%s" type="text" size="%s"'
+                   ' maxlength="%s" %s>'
+                   % (id, id, data, size, maxlength, disabled))
         out.append('<br>')
         out.append(self._renderErrors(node))
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderDate(self, node):
-        meta = self._getMeta(node) 
-        out  = []
-        id   = node.getIdentifier()
+        meta = self._getMeta(node)
+        out = []
+        id = node.getIdentifier()
         data = node.getValue() or ""
-        size = "10" 
+        size = "10"
         disabled = self.ro_mode and "disabled" or ""
-        maxlength = "10" 
+        maxlength = "10"
         out.append(self._renderLabel(node))
         out.append(self._renderAttributes(node))
         out.append('<br>')
-        out.append('<input name="%s" id="%s" value="%s" type="text" size="%s" maxlength="%s" %s class="datefield">' % (id, id, format_date(data), size, maxlength, disabled))
+        out.append('<input name="%s" id="%s" value="%s" type="text" size="%s"'
+                   ' maxlength="%s" %s class="datefield">'
+                   % (id, id, format_date(data), size, maxlength, disabled))
         out.append('<br>')
         out.append(self._renderErrors(node))
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderInt(self, node):
-        meta = self._getMeta(node) 
-        out  = []
-        id   = node.getIdentifier()
+        meta = self._getMeta(node)
+        out = []
+        id = node.getIdentifier()
         data = escape(node.getValue() or "")
         disabled = self.ro_mode and "disabled" or ""
         out.append(self._renderLabel(node))
         out.append(self._renderAttributes(node))
         out.append('<br>')
-        out.append('<input name="%s" id="%s" value="%s" type="text" %s>' % (id, id, data, disabled))
+        out.append('<input name="%s" id="%s" value="%s" type="text" %s>'
+                   % (id, id, data, disabled))
         out.append('<br>')
         out.append(self._renderErrors(node))
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderTextArea(self, node):
-        meta  = self._getMeta(node) 
-        out   = []
-        id    = node.getIdentifier()
+        meta = self._getMeta(node)
+        out = []
+        id = node.getIdentifier()
         value = escape(node.getValue() or "")
-        cols  = meta.getCols() or "0"
-        rows  = meta.getRows() or "0"
+        cols = meta.getCols() or "0"
+        rows = meta.getRows() or "0"
         out.append(self._renderLabel(node, not self.ro_mode))
         out.append(self._renderAttributes(node))
         out.append('<br>')
 
-        if not self.ro_mode: 
-            out.append('<textarea id="%s" name="%s" rows="%s" cols="%s">%s</textarea><br>\n' % (id, id, rows, cols, value))
+        if not self.ro_mode:
+            out.append('<textarea id="%s" name="%s" rows="%s" cols="%s">'
+                       '%s</textarea><br>\n' % (id, id, rows, cols, value))
         else:
             value = value.replace('\r\n', '<br>')
             value = value.replace('\n', '<br>')
@@ -437,16 +501,18 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderRadio(self, node):
-        meta  = self._getMeta(node)
+        meta = self._getMeta(node)
         disabled = self.ro_mode and "disabled" or ""
         self.stateStack.append(node.getValue())
         out = []
         for child in node.getChildren():
-            id    = child.getIdentifier()
+            id = child.getIdentifier()
             value = self._getMeta(child).getValue()
             checked = self.stateStack[-1] == value and 'checked="checked"' or ''
-            out.append('<input type="radio" id="%s" name="%s" value="%s" %s %s %s %s>' 
-            % (id, id, value, disabled, checked, self.next_tabindex(), SET_MODIFICATION))
+            out.append('<input type="radio" id="%s" name="%s"'
+                       ' value="%s" %s %s %s %s>'
+                       % (id, id, value, disabled, checked,
+                          self.next_tabindex(), SET_MODIFICATION))
             out.append(self._renderLabel(child))
             out.append(self._renderAttributes(child))
             out.append('<br>')
@@ -455,7 +521,7 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderPlainBool(self, node):
-        meta  = self._getMeta(node)
+        meta = self._getMeta(node)
         id = node.getIdentifier()
         mvalue = meta.getValue()
         value = node.getValue()
@@ -464,8 +530,10 @@
         #print "mvalue: %s value: %s" % (mvalue, value)
         checked = mvalue == value and "checked" or ""
         out = []
-        out.append('<input type="checkbox" id="%s" name="%s" value="%s" %s %s %s %s>' 
-            % (id, id, mvalue, disabled, checked, self.next_tabindex(), SET_MODIFICATION))
+        out.append('<input type="checkbox" id="%s" name="%s"'
+                   ' value="%s" %s %s %s %s>'
+                   % (id, id, mvalue, disabled, checked,
+                      self.next_tabindex(), SET_MODIFICATION))
         out.append(self._renderLabel(node))
         out.append(self._renderAttributes(node))
         errors = self._renderErrors(node)
@@ -476,19 +544,20 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderChoice(self, node):
-        meta        = self._getMeta(node)
-        id          = node.getIdentifier()
-        value       = node.getValue()
+        meta = self._getMeta(node)
+        id = node.getIdentifier()
+        value = node.getValue()
         description = meta.getDescription()
-        size        = meta.getSize() or "1"
-        multiple    = meta.getMultiple() and "multiple" or ""
-        disabled    = self.ro_mode and "disabled" or ""
+        size = meta.getSize() or "1"
+        multiple = meta.getMultiple() and "multiple" or ""
+        disabled = self.ro_mode and "disabled" or ""
 
         out = []
         out.append(self._renderLabel(node))
         out.append(self._renderAttributes(node))
         out.append('<br>')
-        out.append('<select id="%s" name="%s" size="%s" %s %s %s>' % (id, id, size, multiple, disabled, SET_MODIFICATION))
+        out.append('<select id="%s" name="%s" size="%s" %s %s %s>'
+                   % (id, id, size, multiple, disabled, SET_MODIFICATION))
         self.stateStack.append(str(value))
         out.append(self._renderRecursive(meta, False, ChoiceContainer))
         #for child in meta.children:
@@ -507,9 +576,9 @@
         self.toTarget(Item("".join(out)), meta.getTarget());
 
     def _renderChoiceGroup(self, choice):
-        meta        = self._getMeta(choice)
+        meta = self._getMeta(choice)
         description = meta.getDescription()
-        name        = meta.getName()
+        name = meta.getName()
         out = []
         if not self.ro_mode:
             out.append('<optgroup label="%s">\n' % (description))
@@ -519,45 +588,50 @@
         self.toTarget(Text("".join(out)), meta.getTarget());
 
     def _renderChoiceBool(self, bool):
-        meta        = self._getMeta(bool)
+        meta = self._getMeta(bool)
 
         description = meta.getDescription()
-        name        = meta.getName()
-        value       = meta.getValue()
-        selected    = ""
-        out         = ""
+        name = meta.getName()
+        value = meta.getValue()
+        selected = ""
+        out = ""
 
         #print "render %s" % name
-        
+
         try:
             toSelect = self.stateStack[-1]
         except:
             toSelect = None
-        selected = toSelect ==  (value or value==0) and "selected" or ""
+        selected = toSelect == (value or value==0) and "selected" or ""
 
-        if (value or value==0): value = 'value="%s"' % escape(value, True)
-        else:     value = ""
+        if (value or value==0):
+            value = 'value="%s"' % escape(value, True)
+        else:
+            value = ""
 
-        if description: description = escape(description)
-        else:           description = ""
+        if description:
+            description = escape(description)
+        else:
+            description = ""
 
         if self.ro_mode:
             if selected:
-                out = "<option %s %s>%s</option>\n" % (value, selected, description)
+                out = ("<option %s %s>%s</option>\n"
+                       % (value, selected, description))
         else:
             out = "<option %s %s>%s</option>\n" % (value, selected, description)
 
         self.toTarget(Text(out), meta.getTarget());
 
     def _renderMatrix(self, node):
-        meta        = self._getMeta(node)
+        meta = self._getMeta(node)
         description = meta.getDescription()
-        disabled    = self.ro_mode and "disabled" or ""
+        disabled = self.ro_mode and "disabled" or ""
         out = []
         legend = []
         out.append('<table class="radiomatrix">')
 
-        # write table header 
+        # write table header
         out.append('<tr>')
         out.append('<th class="label">')
         out.append(self._renderLabel(node, False))
@@ -571,7 +645,8 @@
                 header = description
             else:
                 header = alternative
-                legend.append("<strong>%s</strong>:%s" % (alternative, description))
+                legend.append("<strong>%s</strong>:%s"
+                              % (alternative, description))
             out.append("<th>%s</th>" % header)
         out.append("</tr>")
 
@@ -586,10 +661,13 @@
             for col in self._getMeta(row).children:
                 name = row.getIdentifier()
                 name = name
-                value = col.getValue() 
+                value = col.getValue()
                 checked = value == self.stateStack[-1] and "checked" or ""
                 out.append('<td class="%s">' % (num%2 and "hl" or ""))
-                out.append('<input type="radio" name="%s" value="%s" %s %s %s %s>' %(name, value, checked, self.next_tabindex(), disabled, SET_MODIFICATION) ) 
+                out.append('<input type="radio" name="%s"'
+                           ' value="%s" %s %s %s %s>'
+                           %(name, value, checked, self.next_tabindex(),
+                             disabled, SET_MODIFICATION) )
                 out.append('</td>')
             self.stateStack.pop()
             out.append("</tr>")
@@ -623,9 +701,9 @@
         parentparent = meta.parent.parent
 
         # Check if the bool is within a choicelist
-        if isinstance(self._getMeta(parent),  data.ChoiceNode) \
-        or isinstance(self._getMeta(parent),  data.GroupNode) \
-        and isinstance(self._getMeta(parentparent),  data.ChoiceNode):
+        if (isinstance(self._getMeta(parent), data.ChoiceNode)
+            or isinstance(self._getMeta(parent), data.GroupNode)
+            and isinstance(self._getMeta(parentparent), data.ChoiceNode)):
             self._renderChoiceBool(bool)
 
         elif isinstance(self._getMeta(parent), data.RadioNode):
@@ -641,8 +719,10 @@
             for child in children:
                 value = child.getValue()
                 label = child.getDescription()
-                selected = (value == self.stateStack[-1]) and 'selected="selected"' or ''
-                out.append('<option value="%s" %s>%s</option>' % (value, selected, label))
+                selected = ((value == self.stateStack[-1])
+                            and 'selected="selected"' or '')
+                out.append('<option value="%s" %s>%s</option>'
+                           % (value, selected, label))
         return out
 
     def _renderChild(self, child):
@@ -652,7 +732,8 @@
         elif isinstance(meta, Node):
             if isinstance(meta, data.MatrixNode):
                 self._renderMatrix(child)
-            elif isinstance(meta, data.GroupNode) and isinstance(meta.parent, data.ChoiceNode):
+            elif (isinstance(meta, data.GroupNode)
+                  and isinstance(meta.parent, data.ChoiceNode)):
                 self._renderChoiceGroup(child)
             elif isinstance(meta, data.GroupNode):
                 self._renderGroup(child)
@@ -665,7 +746,8 @@
             elif isinstance(meta, data.ConditionalNode):
                 self._renderConditional(child)
             else:
-                self.toTarget(Item(self._renderRecursive(child)), meta.getTarget())
+                self.toTarget(Item(self._renderRecursive(child)),
+                              meta.getTarget())
 
         elif isinstance(meta, data.InfoLeaf):
             self._renderInfo(child)
@@ -687,7 +769,9 @@
 
         containers = meta.getContainers()
 
-        containers = containers and [Cont(c.strip()) for c in containers.split(",")] or []
+        containers = (containers and [Cont(c.strip())
+                                      for c in containers.split(",")]
+                      or [])
         containers.append(Cont(None))
 
         self.containersStack.append(containers)
@@ -704,34 +788,43 @@
                 #if doBreak: out.append('<br class="newline">\n')
         return "".join(out)
 
+
 class RepeatGroupRenderer(ViewRenderer):
 
     def render_digest(self, rg):
-        out     = []
-        fields  = []
+        out = []
+        fields = []
         case_id = rg.getIdentifier().split(':')[-1]
-        digests = rgdigests = {'rg_unterstuetzung': ['hilfm_art', 'hilfm_inst', 'hilfm_einr', 'hilfm_start', 'hilfm_ende'], 'rg_kompetenz': ['datum_kf', 'kf_anbiet']}
+        digests = rgdigests = {'rg_unterstuetzung':
+                               ['hilfm_art', 'hilfm_inst', 'hilfm_einr',
+                                'hilfm_start', 'hilfm_ende'],
+                               'rg_kompetenz': ['datum_kf', 'kf_anbiet']}
 
         if digests:
-            fields  = digests.get(self._getMeta(rg).getName(), []) 
+            fields = digests.get(self._getMeta(rg).getName(), [])
 
         out.append('<table class="rgdigest">')
         if len(fields) < 1:
             out.append('<tr><td>%s</td></tr>' % rg.getIdentifier())
         else:
             for num, field in enumerate(fields):
-                item = self.it.getItem('%s:%s:%s' % (field, rg.getInternalIdentifier(), case_id))
+                item = self.it.getItem('%s:%s:%s'
+                                       % (field, rg.getInternalIdentifier(),
+                                          case_id))
                 out.append('<tr>')
                 out.append('<td class="label">')
-                out.append('<a href="/navigation/select_branch/%s">' % rg.getChildren()[0].getIdentifier())
+                out.append('<a href="/navigation/select_branch/%s">'
+                           % rg.getChildren()[0].getIdentifier())
                 out.append(self._getMeta(item).getDescription())
                 out.append('</a>')
                 out.append('</td>')
                 out.append('<td>')
-                out.append('<a href="/navigation/select_branch/%s">' % rg.getChildren()[0].getIdentifier())
+                out.append('<a href="/navigation/select_branch/%s">'
+                           % rg.getChildren()[0].getIdentifier())
                 value = item.getValue()
                 if isinstance(self._getMeta(item), data.DateLeaf):
-                    if value: value = format_date(value) 
+                    if value:
+                        value = format_date(value)
                 out.append('%s' % NA(value))
                 out.append('</a>')
                 out.append('</td>')
@@ -743,30 +836,42 @@
         out = []
         out.append('<div class="widget">')
         out.append('<table class="list">')
-        out.append('<tr><th>%s</th><th class="actions">%s</th>' % (_('Description'), _('Actions')))
+        out.append('<tr><th>%s</th><th class="actions">%s</th>'
+                   % (_('Description'), _('Actions')))
         for num, rg in enumerate(self.page.getChildren()):
             out.append('<tr>')
             out.append('<td>')
             out.append(self.render_digest(rg))
             out.append('</td>')
             out.append('<td class="actions">')
-            out.append('<a href="/navigation/select_branch/%s"><img src="/images/icons/view_red.gif" border="0" alt="%s" title="%s"></a>' % (rg.getChildren()[0].getIdentifier(), _('view'), _('view')))
-            if not self.ro_mode: 
-                out.append('<a href="/repeatgroup/delete/%s"><img src="/images/icons/delete_red.gif" border="0" alt="%s" title="%s"></a>' % (rg.getIdentifier(), _('delete'), _('delete')))
+            out.append('<a href="/navigation/select_branch/%s">'
+                       '<img src="/images/icons/view_red.gif" border="0"'
+                       ' alt="%s" title="%s"></a>'
+                       % (rg.getChildren()[0].getIdentifier(), _('view'),
+                          _('view')))
+            if not self.ro_mode:
+                out.append('<a href="/repeatgroup/delete/%s">'
+                           '<img src="/images/icons/delete_red.gif" border="0"'
+                           ' alt="%s" title="%s"></a>'
+                           % (rg.getIdentifier(), _('delete'), _('delete')))
             out.append('</td>')
             out.append('</tr>')
         out.append('</table>')
         out.append('</div>')
-        out.append('<div>%s %s</div>' % (len(self.page.getChildren()), _('Items found')))
-        if not self.ro_mode: 
-            out.append('<div><br><a href="/repeatgroup/new/%s" class="button">%s</a></div>' % (self.page.getIdentifier(), _('Create new item')))
-        return "\n".join(out) 
+        out.append('<div>%s %s</div>'
+                   % (len(self.page.getChildren()), _('Items found')))
+        if not self.ro_mode:
+            out.append('<div><br><a href="/repeatgroup/new/%s" class="button">'
+                       '%s</a></div>'
+                       % (self.page.getIdentifier(), _('Create new item')))
+        return "\n".join(out)
 
+
 class ErrorRenderer(object):
-    
+
     def __init__(self, error_items, warnings):
         self.error_items = error_items
-        self.warnings    = warnings
+        self.warnings = warnings
 
     def render(self, page):
         meta = page.getMeta()
@@ -781,26 +886,29 @@
 
         if self.error_items:
             out.append('<div class="widget dialog">')
-            out.append('<h1><img src="/images/alert.png">%s</h1>' % _('Formular errors'))
+            out.append('<h1><img src="/images/alert.png">%s</h1>'
+                       % _('Formular errors'))
             out.append('<ol>')
 
-
             for k, v in self.error_items.iteritems():
                 element = tree.getFormEd().findByName(k.split(':')[0])
                 #print element
                 description = element.getDescription()
                 out.append('<li><a href="/formularpage/undo/%s">' % k)
-                out.append('<img src="/images/icons/formular/undo.png" border="0" alt="undo" title="%s"/>' % _('Restore last valid value'))
-                out.append(
-                    '</a>'
-                    '<a class="error" href="#f_%s">%s: %s</a></li>'% (k, description, v))
+                out.append('<img src="/images/icons/formular/undo.png"'
+                           ' border="0" alt="undo" title="%s"/>'
+                           % _('Restore last valid value'))
+                out.append('</a>'
+                           '<a class="error" href="#f_%s">%s: %s</a></li>'
+                           % (k, description, v))
 
             out.append('</ol>')
             out.append('</div>')
 
         if self.warnings:
             out.append('<div class="widget dialog">')
-            out.append('<h1><img src="/images/info.png">%s</h1>' % _('Formular warnings'))
+            out.append('<h1><img src="/images/info.png">%s</h1>'
+                       % _('Formular warnings'))
             out.append('<ol>')
 
             for k, v in self.warnings.iteritems():
@@ -808,10 +916,12 @@
                 #print element
                 description = element.getDescription()
                 out.append('<li><a href="/formularpage/undo/%s">' % k)
-                out.append('<img src="/images/icons/formular/undo.png" border="0" alt="undo" title="%s"/>' % _('Restore last valid value'))
-                out.append(
-                    '</a>'
-                    '<a class="error" href="#f_%s">%s: %s</a></li>'% (k, description, v))
+                out.append('<img src="/images/icons/formular/undo.png"'
+                           ' border="0" alt="undo" title="%s"/>'
+                           % _('Restore last valid value'))
+                out.append('</a>'
+                           '<a class="error" href="#f_%s">%s: %s</a></li>'
+                           % (k, description, v))
             out.append('</ol>')
             out.append('</div>')
 
@@ -850,55 +960,55 @@
         return "".join(out)
 
 # class ErrorRenderer(object):
-#     
+#
 #     def __init__(self, error_items, warnings):
 #         self.error_items = error_items
 #         self.warnings    = warnings
-# 
+#
 #     def render(self, page):
 #         meta = self._getMeta(page)
 #         page_name = meta.getName()
-# 
+#
 #         #errors_list = [kv for kv in self.error_items.iteritems() if kv[1].page == page_name]
 #         errors_list = [kv for kv in self.error_items.iteritems()]
 #         #order = dict([(w.getName(), idx) for idx, w in enumerate(page.allWidgets())])
-# 
+#
 #         out = []
-# 
+#
 #         if errors_list:
 #             out.append('<div class="widget dialog">')
 #             out.append('<h1><img src="/images/icons/alert.png">%s</h1>' % _('Formular errors'))
 #             out.append('<ol>')
-# 
+#
 #             #errors_list.sort(lambda a, b: cmp(order[a[0]], order[b[0]]))
-# 
+#
 #             for k, v in errors_list:
 #                 out.append(u'<li><a href="/formularpage/undo/%s">' % k)
 #                 out.append(u'<img src="/images/icons/formular/undo.png" border="0" alt="undo" title="%s"' % _('Restore last valid value'))
 #                 out.append(
 #                     u'</a>'
 #                     u'<a class="error" href="#f_%s">%s: %s</a></li>'% (k, v.name, u", ".join(v.messages)))
-# 
+#
 #             out.append('</ol>')
 #             out.append('</div>')
-# 
+#
 #         if self.warnings:
 #             # hash by warning message
 #             warns = {}
 #             warnings_list = self.warnings.items()
 #             #warnings_list.sort(lambda a, b: cmp(order[a[0]], order[b[0]]))
-# 
+#
 #             for k, v in warnings_list:
 #                 msg = u", ".join(v[1])
 #                 items = warns.setdefault(msg, [])
 #                 items.append((k, v[0].getDescription()))
-# 
+#
 #                 out.append('<div class="widget dialog">')
 #                 out.append('<h1><img src="/images/icons/info.png">%s</h1>' % _('Formular warnings'))
 #                 out.append('<ol>')
-# 
+#
 #             counter = (len(self.warnings) > 5) and 1 or None
-# 
+#
 #             for k, v in warns.iteritems():
 #                 out.append(u'<li>')
 #                 links = []
@@ -910,9 +1020,9 @@
 #                 else:
 #                     for item in v:
 #                         links.append(u'<a href="#f_%s">%s</a>' % item)
-# 
+#
 #                 out.append(u"%s: %s</li>" % (k, u", ".join(links)))
-# 
+#
 #             out.append(u'</ul></div>')
 #         return u"".join(out)
 



More information about the Mpuls-commits mailing list