[Mpuls-commits] r1506 - in wasko/branches/2.0: mpulsweb/lib waskaweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Feb 11 10:19:39 CET 2010


Author: torsten
Date: 2010-02-11 10:19:39 +0100 (Thu, 11 Feb 2010)
New Revision: 1506

Added:
   wasko/branches/2.0/mpulsweb/lib/renderer.py
Removed:
   wasko/branches/2.0/waskaweb/lib/renderer.py
Log:
Moved renderer to mpulsbase


Copied: wasko/branches/2.0/mpulsweb/lib/renderer.py (from rev 1480, wasko/branches/2.0/waskaweb/lib/renderer.py)

Deleted: wasko/branches/2.0/waskaweb/lib/renderer.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/renderer.py	2010-02-11 09:17:35 UTC (rev 1505)
+++ wasko/branches/2.0/waskaweb/lib/renderer.py	2010-02-11 09:19:39 UTC (rev 1506)
@@ -1,924 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright 2007, 2008 Intevation GmbH, Germany, <info at intevation.de>
-# 
-# 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 
-# 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 
-# European Social Fund resources.
-#
-# Authors:
-# Sascha L. Teichmann <teichmann at intevation.de>
-#
-
-import logging
-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 
-from formed.instance.backends.postgres import DBFactory as InstanceFactory
-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 cgi import escape
-from xml.sax.saxutils import quoteattr
-import re
-from datetime import date 
-
-log = logging.getLogger(__name__)
-
-TARGET = re.compile(r"(\w+)(?:|:(.+))$")
-WEIGHTS = frozenset([15, 25, 30, 40, 45, 50, 55, 60, 75])
-#SET_MODIFICATION = 'onchange="setModification();"'
-SET_MODIFICATION = ''
-
-def is_required(flags):
-    return flags.find("required:") >= 0
-
-def digits(n):
-    d, c = 10, 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()):
-            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)
-
-    def render(self, target, width="100"):
-        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   = []
-
-    def append(self, item, weight=1.0):
-        self.items.append((item, weight))
-
-    def render(self, doBreak=True):
-        out = []
-        if self.items:
-            out.append('<table>')
-            out.append('<tr>')
-            for col, w in self.items:
-                data = col.render(self.target, w or "")
-                if not data:
-                    data = "<td></td>"
-                out.append(data)
-            out.append('</tr>')
-            out.append('</table>')
-        return "".join(out)
-
-class ChoiceContainer(Container):
-    def render(self, doBreak=True):
-        out = []
-        if self.items:
-            for col, w in self.items:
-                data = col.render(self.target, w or "")
-                out.append(data)
-        return "".join(out)
-
-class ViewRenderer:
-
-    def __init__(self, it=None, page=None, ro_mode=True):
-        log.debug(page)
-        log.debug(page.getIdentifier())
-        self.it              = it # instancetree
-        self.page            = page
-        self.stateStack      = None
-        self.containersStack = None
-        self.ro_mode         = ro_mode
-        self.tabindex        = 3
-
-    def next_tabindex(self):
-        tabindex = self.tabindex
-        self.tabindex += 1
-        return 'tabindex="%d"' % tabindex
-
-    def render(self, showNext=False):
-
-        out = []
-        if not self.ro_mode:
-            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()))
-            if showNext:
-                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()))
-
-        self.stateStack = []
-        self.containersStack = [[Container(None) ]]
-        #for item in self.page.getChildren():
-        #    self._renderChild(item)
-        #self._renderChild(self.page)
-        self._renderPage(self.page)
-
-        out.append(self.containersStack[-1][0].render())
-
-        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()))
-            if showNext:
-                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 
-        if target:
-            m = TARGET.match(target)
-            if m:
-                target = m.group(1)
-                try:
-                   weight = m.group(2)
-                except (TypeError, ValueError):
-                   pass
-
-        containersStack = self.containersStack
-        for container in containersStack[-1]:
-            if not container.target or container.target == target:
-                container.append(item, weight)
-                return
-
-    def _getMeta(self, node):
-        if isinstance(node, MetaNodeComponent):
-            return node
-        else:
-            return node.getMeta()
-
-    def _renderLabel(self, node, labeltag=True):
-        meta = self._getMeta(node)
-        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()))
-        else:
-            out.append('%s' %  meta.getDescription())
-        out.append(' ')
-        return "\n".join(out)
-
-    def _renderAttributes(self, node):
-        meta = self._getMeta(node)
-
-        out = []
-        log.debug('Search help')
-        log.debug('Annotations: %s' % meta.getAnnotations(['help', 'requiered', 'evaluation']))
-        if meta.hasHelp():
-            log.debug('Found help')
-            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())
-        if meta.hasEvaluation():
-            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):
-        meta = self._getMeta(node)
-        out = []
-        error = '<form:error name="%s" format="">' % node.getIdentifier()
-        if node.hasErrors() or True:
-            #out.append('<span class="error">%s</span>' % node.getErrors())
-            out.append('<span class="error">%s</span>' % error)
-        return "\n".join(out)
-
-    def _renderDummyGroup(self, node):
-        meta = self._getMeta(node)
-        description = meta.getDescription()
-
-        out = []
-        if meta.isInvisible():
-            if description:
-                out.append("<!-- %s -->\n" % escape(description))
-
-            out.append(self._renderRecursive(node))
-        else:
-            out.append('<div class="widget">')
-            out.append(self._renderRecursive(node))
-            out.append("</div>")
-
-        self.toTarget(Item("".join(out)), meta.getTarget())
-
-    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']
-        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('<br>')
-        out.append(self._renderErrors(node))
-        self.toTarget(Item("".join(out)), meta.getTarget())
-
-    def _renderGroup(self, node):
-        meta = self._getMeta(node)
-        description = meta.getDescription()
-
-        out = []
-
-        if meta.isInvisible():
-            if description:
-                out.append("<!-- %s -->\n" % escape(description))
-        else:
-            out.append("<fieldset>\n")
-            if description:
-                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())
-
-    def _renderRepeatContainer(self, node):
-        meta = self._getMeta(node)
-        description = meta.getDescription()
-        out = []
-        out.append('<fieldset>')
-        out.append('<legend>%s</legend>' % escape(description))
-        out.append('<table class="repeatgroup">')
-        if True:
-            out.extend(self._renderRepeatList(node))
-        else:
-            out.extend(self._renderRepeatNav(node))
-        out.append('</table>')
-        out.append('</fieldset>')
-        self.toTarget(Item("".join(out)), meta.getTarget())
-
-    def _renderRepeatList(self, node):
-        out = []
-        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('</td>')
-            out.append('</tr>')
-        if self.ro_mode:
-            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')))
-        return out
-
-    def _renderRepeatNav(self, node):
-        out = []
-        for child in node.getChildren(): 
-            out.append('<tr>')
-            out.append('<td class="container">')
-            out.append(self._renderRecursive(child))
-            out.append('</td>')
-            out.append('</tr>')
-            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(' | ?/? | ')
-        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('</td>')
-        out.append('</tr>')
-        return out
-
-    def _renderConditional(self, conditional):
-        meta = self._getMeta(conditional)
-        out = u""
-        if True: #meta.evaluate():
-            ro = not meta.isInvisible()
-            if ro:
-                old_ro = self.ro_mode
-                self.ro_mode = True
-                for child in conditional.getChildren():
-                    self._renderChild(child)
-                self.ro_mode = old_ro
-            else:
-                self.toTarget(Text(""), meta.getTarget())
-        else:
-            for child in conditional.getChildren():
-                self._renderChild(child)
-
-    def _renderInfo(self, node):
-        meta = self._getMeta(node)
-        out = []
-        if meta.isInvisible(): return
-        text, depth = meta.getValue(), 1#visibleDepth(node)
-        if text:
-            out.append('<p class="text">')
-            out.append('<img src="/images/icons/formular/info.png"> ')
-            out.append(text)
-            out.append('</p>')
-            #text = "<h%s>%s</h%s>\n" % (depth, escape(text), depth)
-            self.toTarget(Div("".join(out)), meta.getTarget())
-
-    def _renderText(self, node):
-        meta = self._getMeta(node) 
-        out  = []
-        id   = node.getIdentifier()
-        data = node.getValue() or ""
-        size = meta.getSize()
-        disabled = self.ro_mode and "disabled" or ""
-        maxlength = meta.getMaxLength()
-        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('<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()
-        data = node.getValue() or ""
-        size = "10" 
-        disabled = self.ro_mode and "disabled" or ""
-        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('<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()
-        data = 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('<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()
-        value = node.getValue() or ""
-        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))
-        else:
-            value = value.replace('\r\n', '<br>')
-            value = value.replace('\n', '<br>')
-            value = value.replace('\r', '<br>')
-            out.append('<p class="readonly">%s</p>' % (NA(value)))
-        out.append(self._renderErrors(node))
-        self.toTarget(Item("".join(out)), meta.getTarget())
-
-    def _renderRadio(self, 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()
-            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(self._renderLabel(child))
-            out.append(self._renderAttributes(child))
-            out.append('<br>')
-        self.stateStack.pop()
-        out.append(self._renderErrors(node))
-        self.toTarget(Item("".join(out)), meta.getTarget())
-
-    def _renderPlainBool(self, node):
-        meta  = self._getMeta(node)
-        id = node.getIdentifier()
-        mvalue = meta.getValue()
-        value = node.getValue()
-        disabled = self.ro_mode and "disabled" or ""
-        #checked = self.stateStack[-1] == value and "checked" or ""
-        #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(self._renderLabel(node))
-        out.append(self._renderAttributes(node))
-        errors = self._renderErrors(node)
-        if errors:
-            out.append('<br>')
-            out.append(errors)
-        out.append('<br>')
-        self.toTarget(Item("".join(out)), meta.getTarget())
-
-    def _renderChoice(self, node):
-        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 ""
-
-        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))
-        self.stateStack.append(str(value))
-        out.append(self._renderRecursive(meta, False, ChoiceContainer))
-        #for child in meta.children:
-        #    if isinstance(child, data.ExternalChoiceListLeaf):
-        #        out.extend(self._renderExternalChoiceList(child))
-        #    value = child.getValue()
-        #    label = child.getDescription()
-        #    selected = (value == self.stateStack[-1]) and 'selected="selected"' or ''
-        #    if label:
-        #        out.append('<option value="%s" %s>%s</option>' % (value, selected, label))
-
-        self.stateStack.pop()
-        out.append('</select>')
-        out.append('<br>')
-        out.append(self._renderErrors(node))
-        self.toTarget(Item("".join(out)), meta.getTarget());
-
-    def _renderChoiceGroup(self, choice):
-        meta        = self._getMeta(choice)
-        description = meta.getDescription()
-        name        = meta.getName()
-        out = []
-        if not self.ro_mode:
-            out.append('<optgroup label="%s">\n' % (description))
-        out.append(self._renderRecursive(meta, False, ChoiceContainer))
-        if not self.ro_mode:
-            out.append("</optgroup>\n")
-        self.toTarget(Text("".join(out)), meta.getTarget());
-
-    def _renderChoiceBool(self, bool):
-        meta        = self._getMeta(bool)
-
-        description = meta.getDescription()
-        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 ""
-
-        if (value or value==0): value = 'value="%s"' % escape(value, True)
-        else:     value = ""
-
-        if description: description = escape(description)
-        else:           description = ""
-
-        if self.ro_mode:
-            if selected:
-                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)
-        description = meta.getDescription()
-        disabled    = self.ro_mode and "disabled" or ""
-        out = []
-        legend = []
-        out.append('<table class="radiomatrix">')
-
-        # write table header 
-        out.append('<tr>')
-        out.append('<th class="label">')
-        out.append(self._renderLabel(node, False))
-        out.append(self._renderAttributes(node))
-        out.append('</th>')
-        for hcol in self._getMeta(node.getChildren()[0]).children:
-            hcolmeta = hcol
-            alternative = hcolmeta.getAlternative()
-            description = hcolmeta.getDescription()
-            if alternative == '':
-                header = description
-            else:
-                header = alternative
-                legend.append("<strong>%s</strong>:%s" % (alternative, description))
-            out.append("<th>%s</th>" % header)
-        out.append("</tr>")
-
-        # write table body
-        for num, row in enumerate(node.getChildren()):
-            out.append('<tr>')
-            out.append('<td class="label %s">' % (num%2 and "hl" or ""))
-            out.append(self._renderLabel(row, False))
-            out.extend(self._renderAttributes(row))
-            out.append('</td>')
-            self.stateStack.append(str(row.getValue()))
-            for col in self._getMeta(row).children:
-                name = row.getIdentifier()
-                name = name
-                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('</td>')
-            self.stateStack.pop()
-            out.append("</tr>")
-
-        # write legend
-        length = len(self._getMeta(node.getChildren()[0]).children)+1
-        out.append('<tr><td colspan="%s"></td></tr>' % str(length))
-        if legend:
-            out.append('<tr>')
-            out.append('<td class="legend" colspan="%s">' % str(length))
-            out.append(" ".join(legend))
-            out.append('</td>')
-            out.append('</tr>')
-        out.append('<tr>')
-        out.append('<td class="label" colspan="%s">' % str(length))
-        out.append(self._renderErrors(node))
-        out.append('</td>')
-        out.append('</tr>')
-        out.append('</table>')
-        out.append('<br>')
-        self.toTarget(Item("".join(out)), meta.getTarget());
-
-    def _renderPage(self, page):
-        out = []
-        out.append(self._renderRecursive(page))
-        self.toTarget(Item("\n".join(out)), self._getMeta(page).getTarget())
-
-    def _renderBool(self, bool):
-        meta = self._getMeta(bool)
-        parent = meta.parent
-        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):
-            self._renderChoiceBool(bool)
-
-        elif isinstance(self._getMeta(parent), data.RadioNode):
-            self._renderRadioBool(bool)
-
-        else:
-            self._renderPlainBool(bool)
-
-    def _renderExternalChoiceList(self, choiceList):
-        out = []
-        children = choiceList.getChildren()
-        if children:
-            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))
-        return out
-
-    def _renderChild(self, child):
-        meta = self._getMeta(child)
-        if isinstance(child, RepeatInstanceContainerNode):
-            self._renderRepeatContainer(child)
-        elif isinstance(meta, Node):
-            if isinstance(meta, data.MatrixNode):
-                self._renderMatrix(child)
-            elif isinstance(meta, data.GroupNode) and isinstance(meta.parent, data.ChoiceNode):
-                self._renderChoiceGroup(child)
-            elif isinstance(meta, data.GroupNode):
-                self._renderGroup(child)
-            elif isinstance(meta, data.ChoiceNode):
-                self._renderChoice(child)
-            elif isinstance(meta, data.RadioNode):
-                self._renderRadio(child)
-            elif isinstance(meta, data.PageNode):
-                self._renderPage(child)
-            elif isinstance(meta, data.ConditionalNode):
-                self._renderConditional(child)
-            else:
-                self.toTarget(Item(self._renderRecursive(child)), meta.getTarget())
-
-        elif isinstance(meta, data.InfoLeaf):
-            self._renderInfo(child)
-        elif isinstance(meta, data.BoolLeaf):
-            self._renderBool(child)
-        elif isinstance(meta, data.TextLeaf):
-            self._renderText(child)
-        elif isinstance(meta, data.TextAreaLeaf):
-            self._renderTextArea(child)
-        elif isinstance(meta, data.IntLeaf):
-            self._renderInt(child)
-        elif isinstance(meta, data.DateLeaf):
-            self._renderDate(child)
-        elif isinstance(meta, data.ExternalChoiceListLeaf):
-            self._renderExternalChoiceList(child)
-
-    def _renderRecursive(self, node, doBreak=True, Cont=Container):
-        meta = self._getMeta(node)
-
-        containers = meta.getContainers()
-
-        containers = containers and [Cont(c.strip()) for c in containers.split(",")] or []
-        containers.append(Cont(None))
-
-        self.containersStack.append(containers)
-
-        children = node.getChildren()
-        for child in children:
-            self._renderChild(child)
-
-        out = []
-        for c in self.containersStack.pop():
-            txt = c.render(doBreak)
-            if txt:
-                out.append(txt)
-                #if doBreak: out.append('<br class="newline">\n')
-        return "".join(out)
-
-class RepeatGroupRenderer(ViewRenderer):
-
-    def render_digest(self, rg):
-        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']}
-
-        if digests:
-            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))
-                out.append('<tr>')
-                out.append('<td class="label">')
-                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())
-                value = item.getValue()
-                if isinstance(self._getMeta(item), data.DateLeaf):
-                    if value: value = format_date(value) 
-                out.append('%s' % NA(value))
-                out.append('</a>')
-                out.append('</td>')
-                out.append('</tr>')
-        out.append('</table>')
-        return "".join(out)
-
-    def render(self, showNext=False):
-        out = []
-        out.append('<div class="widget">')
-        out.append('<table class="list">')
-        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('</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) 
-
-class ErrorRenderer(object):
-    
-    def __init__(self, error_items, warnings):
-        self.error_items = error_items
-        self.warnings    = warnings
-
-    def render(self, page):
-        meta = page.getMeta()
-        page_name = meta.getName()
-        tree = page.getInstanceTree()
-
-        #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 self.error_items:
-            out.append('<div class="widget dialog">')
-            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('</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('<ol>')
-
-            for k, v in self.warnings.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('</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 = []
-        #        if counter:
-        #            for item in v:
-        #                links.append(u'<a href="#f_%s" title=%s>%d</a>' % (
-        #                    item[0], quoteattr(item[1]), counter))
-        #                counter += 1
-        #        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 "".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 = []
-#                 if counter:
-#                     for item in v:
-#                         links.append(u'<a href="#f_%s" title=%s>%d</a>' % (
-#                             item[0], quoteattr(item[1]), counter))
-#                         counter += 1
-#                 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)
-
-# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8:



More information about the Mpuls-commits mailing list