[Mpuls-commits] r881 - wasko/branches/2.0/waskaweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Jan 26 14:13:49 CET 2010


Author: torsten
Date: 2010-01-26 14:13:48 +0100 (Tue, 26 Jan 2010)
New Revision: 881

Removed:
   wasko/branches/2.0/waskaweb/lib/renderer.py
Log:
* waskaweb/lib/renderer.py: Deleted. Not imported from anywhere.


Deleted: wasko/branches/2.0/waskaweb/lib/renderer.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/renderer.py	2010-01-26 12:02:22 UTC (rev 880)
+++ wasko/branches/2.0/waskaweb/lib/renderer.py	2010-01-26 13:13:48 UTC (rev 881)
@@ -1,1047 +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>
-#
-
-from waskaweb.model.nodecomponents import Node
-
-import waskaweb.model.data as data
-
-from waskaweb.model import UNKNOWN_DATE, UNKNOWN_INT
-
-from filters import NA
-
-from cgi import escape
-
-from xml.sax.saxutils import quoteattr
-
-import re
-
-from datetime import date 
-
-#import traceback
-
-TARGET = re.compile(r"(\w+)(?:|:(.+))$")
-
-WEIGHTS = frozenset([15, 25, 30, 40, 45, 50, 55, 60, 75])
-
-SET_MODIFICATION = 'onchange="setModification();"'
-
-def is_required(flags):
-    return flags.find("required:") >= 0
-
-def open_in_blank(url, image):
-    return u'<span class="help"> <a href="%s" target="_blank">%s</a></span>' % (url, image)
-
-def required_url(dataID, get_image):
-    return open_in_blank(
-        "/case/required/%s" % escape(dataID),
-        get_image("/images/icons/required_12x12.png", 'border="0" alt="Pflichtfeld"'))
-
-def eval_url(dataID, get_image):
-    return open_in_blank(
-        "/case/showHelpEvaluation/%s" % escape(dataID),
-        get_image("/images/icons/needed_12x12.png", 'border="0" alt="Auswertungsrelevant"'))
-
-def help_url(dataID, get_image):
-    return open_in_blank(
-        "/case/showhelp/%s" % escape(dataID),
-        get_image("/images/icons/form_help.png", 'border="0" alt="Hilfesymbol"'))
-
-class FormData:
-   
-    def __init__(self, get_image, help=None):
-        self.get_image = get_image
-        self.help      = help 
-
-    def getData(self, dataID):
-        return ""
-
-    def getPrintableData(self, dataID):
-        return self.getData(dataID) 
-
-    def getHelp(self, dataID):
-        if not self.help: return ''
-
-        out = []
-        if self.help.hasAnnotations(dataID):
-            out.append(required_url(dataID, self.get_image))
-
-        if self.help.hasAnnotations(dataID, ('evaluation',)):
-            out.append(eval_url(dataID, self.get_image))
-
-        if self.help.hasHelp(dataID):
-            out.append(help_url(dataID, self.get_image))
-
-        return ''.join(out)
-
-    def hasError(self, dataID):
-        return False
-
-    def getError(self, dataID):
-        return ""
-
-    def hasWarning(self, dataID):
-        return False
-
-    def getWarning(self, dataID):
-        return ""
-
-    def evaluate(self, expr):
-        return True
-
-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
-
-def pretty(x):
-    if isinstance(x, date):
-        if x == UNKNOWN_DATE:
-            return "unbekannt"
-        return "%02d.%02d.%04d" % (x.day, x.month, x.year)
-
-    if isinstance(x, (type(""), type(u""))):
-        return u"%s" % x
-        #return unicode(str(x), 'utf-8')
-
-    if isinstance(x, type(0)):
-        return x == UNKNOWN_INT and "unbekannt" or str(x)
-
-    if isinstance(x, type(False)):
-        return x and "on" or ""
-
-    return str(x)
-
-class FormDataImpl(FormData):
-
-    def __init__(
-        self,
-        file_cache, 
-        help     = None, 
-        page     = None, 
-        errors   = None, 
-        warnings = None,
-        nc       = None,
-        formed   = None
-    ):
-        FormData.__init__(self, file_cache.get_image, help)
-        self.page     = page
-        self.errors   = errors
-        self.warnings = warnings
-        self.formed   = formed
-        if nc:
-            self.nc      = nc #NodeComponent List []
-            self.widgets = self.nc[0].allWidgets()
-        else: 
-            self.nc      = []
-            self.widgets = {} 
-
-    def evaluate(self, expr):
-        return self.formed.evaluate(expr)
-
-    def getData(self, dataID):
-        if not self.errors is None:
-            try:
-                ei = self.errors[dataID]
-                if not ei.bad is None:
-                    return u"%s" % pretty(ei.bad)
-            except KeyError:
-                pass
-        if not self.page is None:
-            value = self.page.getData(dataID)
-            if value is not None: value = pretty(value)
-            else:     value = ""
-            return value
-        return ""
-
-    def getPrintableData(self, dataID):
-        value = self.getData(dataID)
-        try:
-            widget = self.widgets[dataID]
-        except KeyError:
-            return value 
-
-        if not isinstance(widget, data.ChoiceNode):
-            return value
-
-        for c in widget.children:
-            if isinstance(c, data.BoolLeaf):
-                v = c.getValue()
-                if v == value:
-                    return c.getDescription()
-            elif isinstance(c, data.ExternalChoiceListLeaf):
-                cc = c.getChildren()
-                if cc:
-                    for i in cc:
-                        if isinstance(i, data.BoolLeaf):
-                            v = c.getValue()
-                            if v == value:
-                                return c.getDescription()
-
-        return value 
-
-    def hasError(self, dataID):
-        return self.errors and bool(self.errors.get(dataID))
-
-    def getError(self, dataID):
-        if self.errors:
-            try:
-                ei = self.errors[dataID]
-                return u"<br>\n".join([u"%s" % s for s in ei.messages])
-            except KeyError:
-                pass
-        return ""
-
-    def hasWarning(self, dataID):
-        return self.warnings and bool(self.warnings.get(dataID))
-
-    def getWarning(self, dataID):
-        if self.warnings:
-            try:
-                t = self.warnings[dataID]
-                return u"<br>".join(t[1].join())
-            except KeyError:
-                pass
-        return u""
-
-
-class Text:
-    def __init__(self, txt):
-        self.txt = txt
-
-    def render(self, target, weight):
-        return self.txt
-
-class Div(Text):
-    def __init__(self, txt):
-        Text.__init__(self, txt)
-
-    def render(self, target, weight):
-        return '<div class="waska_form_element w100">%s</div>\n' % self.txt
-
-class Item(Text):
-    def __init__(self, txt):
-        Text.__init__(self, txt)
-
-    def render(self, target, weight):
-        weight = int(100.0*weight+0.5)
-        weight = weight in WEIGHTS and " w%d" % weight or " w100"
-        return '<div class="waska_form_element %s">\n%s</div>\n' % (
-            weight, 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):
-        if self.items:
-            out = []
-            f = 1.0/reduce(lambda x, y: x + y[1], self.items, 0)
-            ws = [f*w[1] for w in self.items]
-            target = self.target
-            out = [item[0].render(target, w) for item, w in zip(self.items, ws)]
-            if doBreak: out.append('<br>')
-            return "".join(out)
-        return ""
-
-class ViewRenderer:
-
-    def __init__(self, formdata=None, ro_mode=True):
-        self.formdata        = formdata
-        self.stateStack      = None
-        self.containersStack = None
-        self.ro_mode         = ro_mode
-        self.items           = formdata.nc
-        self.tabindex        = 3
-
-    def next_tabindex(self):
-        tabindex = self.tabindex
-        self.tabindex += 1
-        return 'tabindex="%d"' % tabindex
-
-    def renderView(self, name="", ds_id=None, showNext=True):
-
-        if not self.items:
-            return "No items given!"
-
-        self.tabindex = 3
-       
-        out = []
-        if not self.ro_mode:
-            out.append('<form id="waska_form" action="/case/save" accept-charset="UTF-8" method="POST">\n')
-            # Add submitbutton at the top of the page too
-            out.append('<div class="waska_form_element w100">')
-            out.append('<input type="hidden" name="ds" value="%s">' % ds_id)
-            out.append('<input type="submit" value="&Uuml;bernehmen" %s>\n' % self.next_tabindex())
-            if showNext:
-                out.append('<input type="submit" value="&Uuml;bernehmen und weiter" name="__formular_next" %s>\n' % \
-                    self.next_tabindex())
-            out.append('</div>')
-
-        self.stateStack = []
-        self.containersStack = [[Container(None) ]]
-        for item in self.items:
-            self._renderChild(item)
-
-        out.append(self.containersStack[-1][0].render())
-
-        if not self.ro_mode:
-            if name:
-                out.append('<input type="hidden" name="page" value=%s>\n' \
-                    % quoteattr(name))
-            out.append('<div class="waska_form_element w100">')
-            out.append('<input type="submit" value="&Uuml;bernehmen" %s>\n' % self.next_tabindex())
-            if showNext:
-                out.append('<input type="submit" value="&Uuml;bernehmen und weiter" name="__formular_next" %s>\n' % \
-                    self.next_tabindex())
-            out.append('</div>')
-            out.append('</form>\n')
-
-        return "".join(out)
-
-    def toTarget(self, item, target):
-        weight = 1.0
-        if target:
-            m = TARGET.match(target)
-            if m:
-                target = m.group(1)
-                try:
-                   weight = float(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 _renderGroup(self, node):
-        description = node.getDescription()
-        name        = node.getName()
-
-        help        = self.formdata.getHelp(name)
-        data        = self.formdata.getData(name)
-
-        out = []
-        
-        if node.isInvisible():
-            if description:
-                out.append("<!-- %s -->\n" % escape(description))
-
-            out.append(self._renderRecursive(node))
-        else:
-            out.append("<fieldset>\n")
-            if description:
-                out.append(
-                    "<legend>%s %s</legend>\n" % (escape(description), help))
-            out.append(self._renderRecursive(node))
-            out.append("</fieldset>\n")
-
-        self.toTarget(Item("".join(out)), node.getTarget())
-
-    def _renderConditional(self, conditional):
-
-        expr = conditional.getExpr()
-        out = u""
-        if expr and not self.formdata.evaluate(expr):
-            ro = not conditional.isInvisible()
-            if ro:
-                old_ro = self.ro_mode
-                self.ro_mode = True
-                for child in conditional.children:
-                    self._renderChild(child)
-                self.ro_mode = old_ro
-            else:
-                self.toTarget(Text(""), conditional.getTarget())
-        else:
-            for child in conditional.children:
-                self._renderChild(child)
-
-    def _renderMatrix(self, node):
-        description = node.getDescription()
-        name        = node.getName()
-
-        help        = self.formdata.getHelp(name)
-        legend      = []
-
-        out = []
-        
-        error = self.formdata.getData(name)
-        if node.isInvisible():
-            if description:
-                out.append("<!-- %s -->\n" % escape(description))
-
-            out.append(self._renderRecursive(node))
-        else:
-            try:
-                out.append('<table class="formed-radiomatrix">')
-                # write table header take
-                out.append("<tr>")
-                out.append('<th class="formed-radiomatrix-label">%s</th>' % description)
-                for hcol in node.children[0].children:
-                    alternative = hcol.getAlternative()
-                    description = hcol.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
-                fdata = self.formdata
-                for num, row in enumerate(filter(lambda x: isinstance(x, data.RadioNode), node.children)):
-                    css_row_class = num % 2 and 'odd' or 'even'
-
-                    rname = row.getName()
-
-                    if fdata.hasError(rname):
-                        label = u'<span class="error_font">%s</span>' % escape(row.getDescription())
-                    elif fdata.hasWarning(rname):
-                        label = u'<span class="warning_font">%s</span>' % escape(row.getDescription())
-                    else:
-                        label = escape(row.getDescription())
-
-                    out.append(
-                        u'<tr>'
-                        u'<td class="formed-radiomatrix-label %s">'
-                        u'<a name="f_%s">%s</a>%s</td>' % (
-                            css_row_class, 
-                            rname, 
-                            label,
-                            fdata.getHelp(rname)))
-
-                    self.stateStack.append((
-                        self.formdata.getData(row.getName()),
-                        is_required(row.getFlags())))
-
-                    for col in row.children:
-                        out.append('<td class="formed-radiomatrix-data %s">%s</td>' % (
-                            css_row_class, self._renderRadioMatrixBool(col)))
-
-                    self.stateStack.pop()
-                    out.append("</tr>")
-                # write legend
-                if legend:
-                    out.append(
-                        u'<tr><td class="formed-radiomatrix-legend" colspan="%s">'
-                        u'<span class="formed-radiomatrix-legend">%s</span></td></tr>' % (
-                            len(node.children[0].children)+1, ", ".join(legend)))
-                out.append("</table>")
-            except:
-                pass
-                #traceback.print_exc()
-        self.toTarget(Item("".join(out)), node.getTarget())
-
-
-    def _renderInfo(self, info):
-        if info.isInvisible(): return
-        text, depth = info.getValue(), visibleDepth(info)
-        if text:
-            text = "<h%s>%s</h%s>\n" % (depth, escape(text), depth)
-            self.toTarget(Div(text), info.getTarget())
-
-    def _renderRadio(self, radio):
-        description = radio.getDescription()
-        name        = radio.getName()
-
-        help        = self.formdata.getHelp(name)
-        data        = self.formdata.getData(name)
-        #error       = self.formdata.hasError(name)
-
-        label = self._renderLabel(description, name, help=help,)
-
-        out = [ label ]
-
-        self.stateStack.append(data)
-        out.append(self._renderRecursive(radio))
-        self.stateStack.pop()
-
-        self.toTarget(Text("".join(out)), radio.getTarget());
-
-    def _renderChoice(self, choice):
-        description = choice.getDescription()
-        name        = choice.getName()
-        size        = choice.getSize()
-        multiple    = choice.getMultiple()
-        flags       = choice.getFlags()
-
-        help        = self.formdata.getHelp(name)
-        data        = self.formdata.getData(name)
-        error       = self.formdata.hasError(name)
-        warn        = self.formdata.hasWarning(name)
-
-        css_class   = []
-
-        label = self._renderLabel(description, name, help=help)
-
-        if name:
-            name = quoteattr(name)
-            name = 'name=%s id=%s' % (name, name)
-        else:
-            name = ""
-
-        # Do not render choicelists in disabled mode as IE can not cope with
-        # css on disabled list elements. Instead just render the selected
-        # option within the list (ChoiceBool)
-        disabled = ""
-        #if self.ro_mode: 
-        #    disabled = 'disabled="disabled"'
-        #    css_class.append('readonly')
-        #else: disabled = ""
-
-        multiple = multiple and "multiple" or ""
-
-        if not size: size = "1"
-
-        out = [ label ]
-
-        if is_required(flags):
-            css_class.append('required')
-
-        if  error: css_class.append('error_box')    
-        elif warn: css_class.append('warning_box')    
-
-        out.append(
-            '<select size="%s" class="%s" %s %s %s %s %s>\n' % (
-                size, " ".join(css_class), disabled, 
-                multiple, name, SET_MODIFICATION, self.next_tabindex()))
-
-        self.stateStack.append(data)
-        out.append(self._renderRecursive(choice, False))
-        self.stateStack.pop()
-
-        out.append("</select>\n")
-
-        self.toTarget(Item("".join(out)), choice.getTarget());
-
-    def _renderChoiceBool(self, bool):
-
-        description = bool.getDescription()
-        name        = bool.getName()
-        value       = bool.getValue()
-        selected    = ""
-        out         = ""
-        
-        toSelect = self.stateStack[-1]
-        selected = toSelect ==  (value or value==0) and "selected" or ""
-
-        if (value or value==0): value = 'value=%s' % quoteattr(value)
-        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), bool.getTarget());
-
-    def _renderRadioMatrixBool(self, bool):
-        '''Radio bool without any label'''
-
-        name        = bool.getName()
-        pname       = bool.parent.getName()
-        description = bool.getDescription()
-        value       = bool.getValue()
-
-        toCheck, required = self.stateStack[-1]
-
-        checked = toCheck == value and "checked" or ""
-
-        required = required and 'class="required"' or ''
-        
-        if value:
-            value = u'value=%s' % quoteattr(value)
-        else:
-            value = ""
-
-        if   pname: oname = u'name=%s' % quoteattr(pname)
-        elif  name: oname = u'name=%s' % quoteattr(name)
-        else:       oname = u''
-
-        disabled = self.ro_mode and 'disabled' or ''
-
-        out = u'<input type="radio" %s %s %s %s %s %s %s>\n' % (
-            oname, value, required, checked, SET_MODIFICATION, 
-            disabled, self.next_tabindex())
-
-        return out
-
-    def _renderRadioBool(self, bool):
-
-        name        = bool.getName()
-        pname       = bool.parent.getName()
-        description = bool.getDescription()
-        value       = bool.getValue()
-        css_class   = []
-
-        toCheck = self.stateStack[-1]
-
-        checked = toCheck == value and "checked" or ""
-        
-        label = self._renderLabel(description, name, newline=False)
-
-        if value:
-            value = 'value=%s' % quoteattr(value)
-        else:
-            value = ""
-
-        if   pname: oname = u'name=%s' % quoteattr(pname)
-        elif  name: oname = u'name=%s' % quoteattr(name)
-        else:       oname = u''
-
-        if name: id = u'id=%s' % quoteattr(name)
-        else:    id = ""
-        
-        if self.ro_mode: 
-            disabled = "disabled"
-            css_class.append(disabled)
-        else: disabled = ""
-
-        out = u'<input type="radio" class="%s" %s %s %s %s %s %s %s>%s\n' % (
-            u" ".join(css_class), disabled, oname, id, value, checked, 
-            SET_MODIFICATION, self.next_tabindex(), label)
-
-        self.toTarget(Item(out), bool.getTarget())
-
-    def _renderPlainBool(self, bool):
-
-        name        = bool.getName()
-        description = bool.getDescription()
-        css_class   = []
-
-        data = self.formdata.getData(name)
-        if data == "1": 
-            value = 'value=%s' % quoteattr(data)
-            checked = "checked"
-        else:
-            value, checked = "", ""
-
-        label = self._renderLabel(description, name)
-
-        if name: 
-            name = quoteattr(name)
-            name = 'name=%s id=%s' % (name, name)
-        else:
-            name = ''
-
-        if self.ro_mode: 
-            disabled = "disabled"
-            css_class.append('readonly')
-        else: disabled = ""
-
-        out = '<input type="checkbox" class="%s" %s %s %s %s %s %s>%s' % (
-            " ".join(css_class), disabled, name, value, checked, 
-            SET_MODIFICATION, self.next_tabindex(), label)
-
-        self.toTarget(Item(out), bool.getTarget())
-
-    def _renderLabel(self, description, name, help=None, newline=True):
-
-        error = self.formdata.hasError(name)
-        warn  = self.formdata.hasWarning(name)
-
-        if help: helpmsg = help
-        else:    helpmsg = ""
-
-        if newline: newline = "<br>"
-        else:       newline = ""
-
-        if description:
-            description = escape(description)
-            if name:
-                if error:
-                    return u'<label for=%s class="error_font"><a name="f_%s">%s</a> %s</label>%s\n' % ( 
-                    quoteattr(name), escape(name), description, helpmsg, newline)
-
-                if warn:
-                    return u'<label for=%s class="warning_font"><a name="f_%s">%s</a> %s</label>%s\n' % ( 
-                    quoteattr(name), escape(name), description, helpmsg, newline)
-
-                return u'<label for=%s><a name="f_%s">%s</a> %s</label>%s\n' % ( 
-                    quoteattr(name), escape(name), description, helpmsg, newline)
-                    
-            return u"%s " % description
-        return ""
-
-    def _renderTextArea(self, text):
-
-        description = text.getDescription()
-        name        = text.getName()
-        rows        = text.getRows()
-        cols        = text.getCols()
-        flags       = text.getFlags()
-        
-        help        = self.formdata.getHelp(name)
-        data        = self.formdata.getData(name)
-        error       = self.formdata.hasError(name)
-        warn        = self.formdata.hasWarning(name)
-
-        css_class   = []
-
-        if data: value = escape(data)
-        else:    value = ""
-
-        if rows: rows = 'rows=%s' % quoteattr(rows)
-        else:    rows = ""
-
-        if cols: cols = 'cols=%s' % quoteattr(cols)
-        else:    cols = ""
-
-        out = [ self._renderLabel(description, name, help=help) ]
-
-        if name: 
-            name = quoteattr(name)
-            name = 'name=%s id=%s' % (name, name)
-        else:
-            name = ""
-
-        if is_required(flags):
-            css_class.append('required')
-
-        if  error: css_class.append('error_box')    
-        elif warn: css_class.append('warning_box')    
-
-        if not self.ro_mode: 
-            out.append('<textarea class="%s" %s %s %s %s %s>%s</textarea><br>\n' % (
-            " ".join(css_class), name, rows, cols, 
-            SET_MODIFICATION, self.next_tabindex(), value))
-        else:
-            #disabled = "disabled"
-            #css_class.append('readonly')
-            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))
-
-        self.toTarget(Item("".join(out)), text.getTarget())
-
-    def _renderDate(self, date):
-
-        description = date.getDescription()
-        name        = date.getName()
-        flags       = date.getFlags()
-        help        = self.formdata.getHelp(name)
-
-        data        = self.formdata.getData(name)
-        error       = self.formdata.hasError(name)
-        warn        = self.formdata.hasWarning(name)
-        css_class   = []
-
-        if data: value = 'value=%s' % quoteattr(data)
-        else:    value = ""
-        
-        out = [ self._renderLabel(description, name, help=help) ]
-
-        if name:
-            name = quoteattr(name)
-            name = 'name=%s id=%s' % (name, name)
-        else:
-            name = ""
-
-        if self.ro_mode: 
-            disabled = "readonly"
-            css_class.append('readonly')
-        else: disabled = ""
-
-        if is_required(flags):
-            css_class.append('required')
-
-        if  error: css_class.append('error_box')    
-        elif warn: css_class.append('warning_box')    
-
-        out.append( '<input type="text" size="10" maxlength="10" class="%s" %s %s %s %s %s><br>\n' % (
-            " ".join(css_class), disabled, name, 
-            value, SET_MODIFICATION, self.next_tabindex()))
-
-        self.toTarget(Item("".join(out)), date.getTarget());
-
-    def _renderText(self, text):
-
-        description = text.getDescription()
-        size        = text.getSize()
-        flags       = text.getFlags()
-        length      = text.getMaxLength()
-        name        = text.getName()
-        help        = self.formdata.getHelp(name)
-        data        = self.formdata.getData(name)
-        error       = self.formdata.hasError(name)
-        warn        = self.formdata.hasWarning(name)
-        css_class   = ['field']
-
-        if data: value = 'value=%s' % quoteattr(data)
-        else:    value = ""
-
-        if size:   size = 'size=%s' % quoteattr(size)
-        else:      size = ""
-
-        if length: length = 'maxlength=%s' % quoteattr(length)
-        else:      length = ""
-
-        if self.ro_mode: 
-            css_class.append('readonly')
-            disabled = "readonly"
-        else: disabled = ""
-
-        out = [ self._renderLabel(description, name, help=help) ]
-
-        if name:
-            name = quoteattr(name)
-            name = 'name=%s id=%s' % (name, name)
-        else:
-            name = ""
-
-        if is_required(flags):
-            css_class.append('required')
-
-        if  error: css_class.append('error_box')    
-        elif warn: css_class.append('warning_box')    
-
-        out.append(u'<input type="text" class="%s" %s %s %s %s %s %s %s><br>\n' % (
-            " ".join(css_class), disabled, size, length, name, 
-            value, SET_MODIFICATION, self.next_tabindex()))
-
-        self.toTarget(Item("".join(out)), text.getTarget())
-
-    def _renderIntLeaf(self, integer):
-
-        description = integer.getDescription()
-        name        = integer.getName()
-        flags       = integer.getFlags()
-        minV        = integer.getMinValue()
-        maxV        = integer.getMaxValue()
-        help        = self.formdata.getHelp(name)
-        data        = self.formdata.getData(name)
-        error       = self.formdata.hasError(name)
-        warn        = self.formdata.hasWarning(name)
-        css_class   = ['intfield']
-        
-        if data: value = 'value=%s' % quoteattr(data)
-        else:    value = ""
-
-        try:
-            minV, maxV = int(minV), int(maxV)
-            highest = max(abs(maxV), abs(minV))
-            size = digits(highest)
-            if minV < 0 or maxV < 0: size += 1
-            size = 'size="%d" maxlength="%d"' % (size, size)
-        except ValueError:
-            size = ""
-
-        out = [ self._renderLabel(description, name, help=help) ]
-
-        if name:
-            name = quoteattr(name)
-            id   = 'id=%s'   % name
-            name = 'name=%s' % name
-        else:
-            id, name = "", ""
-
-        if self.ro_mode: 
-            disabled = "readonly"
-            css_class.append('readonly')
-        else: disabled = ""
-
-        if is_required(flags):
-            css_class.append('required')
-
-        if  error: css_class.append('error_box')    
-        elif warn: css_class.append('warning_box')    
-
-        out.append(u'<input type="text" class="%s" %s %s %s %s %s %s %s><br>\n' % (
-            " ".join(css_class), disabled, size, name, value, 
-            id, SET_MODIFICATION, self.next_tabindex()))
-
-        self.toTarget(Item("".join(out)), integer.getTarget())
-
-    def _renderPage(self, page):
-        out = self._renderRecursive(page)
-        self.toTarget(Text(out), page.getTarget())
-
-    def _renderBool(self, bool):
-
-        parent = bool.parent
-
-        if isinstance(parent,  data.ChoiceNode):
-            self._renderChoiceBool(bool)
-
-        elif isinstance(parent, data.RadioNode):
-            self._renderRadioBool(bool)
-
-        else:
-            self._renderPlainBool(bool)
-
-    def _renderExternalChoiceList(self, choiceList):
-        children = choiceList.getChildren()
-        if children:
-            for child in children:
-                if isinstance(child, data.BoolLeaf):
-                    self._renderBool(child)
-
-    def _renderChild(self, child):
-
-        if isinstance(child, Node):
-            if isinstance(child, data.MatrixNode):
-                self._renderMatrix(child)
-            elif isinstance(child, data.GroupNode):
-                self._renderGroup(child)
-            elif isinstance(child, data.ChoiceNode):
-                self._renderChoice(child)
-            elif isinstance(child, data.RadioNode):
-                self._renderRadio(child)
-            elif isinstance(child, data.PageNode):
-                self._renderPage(child)
-            elif isinstance(child, data.ConditionalNode):
-                self._renderConditional(child)
-            else:
-                self.toTarget(Text(self._renderRecursive(child)), child.getTarget())
-
-        elif isinstance(child, data.InfoLeaf):
-            self._renderInfo(child)
-        elif isinstance(child, data.BoolLeaf):
-            self._renderBool(child)
-        elif isinstance(child, data.TextLeaf):
-            self._renderText(child)
-        elif isinstance(child, data.TextAreaLeaf):
-            self._renderTextArea(child)
-        elif isinstance(child, data.IntLeaf):
-            self._renderIntLeaf(child)
-        elif isinstance(child, data.DateLeaf):
-            self._renderDate(child)
-        elif isinstance(child, data.ExternalChoiceListLeaf):
-            self._renderExternalChoiceList(child)
-        
-    def _renderRecursive(self, node, doBreak=True):
-        containers = node.getContainers()
-
-        containers = containers and [Container(c.strip()) for c in containers.split(",")] or []
-        containers.append(Container(None))
-
-        self.containersStack.append(containers)
-
-        for child in node.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 ErrorRenderer(object):
-    
-    def __init__(self, error_items, warnings, file_cache):
-        self.error_items = error_items
-        self.warnings    = warnings
-        self.get_image   = file_cache.get_image
-
-    def render(self, page):
-
-        page_name = page.getName()
-
-        errors_list = [kv for kv in self.error_items.iteritems() if kv[1].page == page_name]
-        order = dict([(w.getName(), idx) for idx, w in enumerate(page.allWidgets())])
-
-        out = []
-
-        get_image = self.get_image
-        if errors_list:
-            out.append(
-                u'<div class="form_errors">'
-                u'<h1><a name="error_list">Fehlerhafte Formulareingabe</a></h1>'
-                u'<ul>')
-
-            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="/case/undo_error/%s">' % k)
-                out.append(get_image("/images/icons/undo.png",
-                    u'border="0" alt="undo" title="Letzten gültigen Wert wieder herstellen."'))
-                out.append(
-                    u'</a> '
-                    u'<a href="#f_%s">%s: %s</a></li>'% (k, v.name, u", ".join(v.messages)))
-
-            out.append(u'</ul></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(
-                u'<div class="form_warnings">'
-                u'<h1><a name="warning_list">%s</a></h1>'
-                u'<ul>' % (len(warns) > 1 and u"Hinweise" or u"Hinweis"))
-
-            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