[Mpuls-commits] r698 - in wasko/branches/2.0: . formed waskaweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 18 15:56:48 CET 2009


Author: torsten
Date: 2009-11-18 15:56:44 +0100 (Wed, 18 Nov 2009)
New Revision: 698

Modified:
   wasko/branches/2.0/ChangeLog.txt
   wasko/branches/2.0/formed/formedtree_web.xml
   wasko/branches/2.0/waskaweb/lib/renderer_new.py
Log:
Added grouping of choicelists


Modified: wasko/branches/2.0/ChangeLog.txt
===================================================================
--- wasko/branches/2.0/ChangeLog.txt	2009-11-18 08:03:51 UTC (rev 697)
+++ wasko/branches/2.0/ChangeLog.txt	2009-11-18 14:56:44 UTC (rev 698)
@@ -1,3 +1,11 @@
+2009-11-18 	Torsten Irlaender	<torsten.irlaender at intevation.de> 
+
+	Implement grouping of choicelists
+
+	* waskaweb/lib/renderer_new.py,
+	  formed/formedtree_web.xml: New formedtree with groups. Adopted
+	  grouping
+
 2009-11-17 	Torsten Irlaender	<torsten.irlaender at intevation.de> 
 
 	Issue606

Modified: wasko/branches/2.0/formed/formedtree_web.xml
===================================================================
--- wasko/branches/2.0/formed/formedtree_web.xml	2009-11-18 08:03:51 UTC (rev 697)
+++ wasko/branches/2.0/formed/formedtree_web.xml	2009-11-18 14:56:44 UTC (rev 698)
@@ -70,23 +70,27 @@
         <rule expr="$erstgespraech isset" flags="required:phase_a_start" mark="warning:erstgespraech" name="rule-84" value="Fehlende Pflichtfeldangabe"/>
         <group containers="a" description="Angaben zum Zugang des/der Jugendlichen" name="group-2" target="h">
           <choice description="Zugang des/der Jugendlichen zur Koordinierungsstelle" flags="required:phase_a_end" name="zugang" size="1" target="a">
-            <bool description="Eigenständiger Zugang des Jugendlichen" name="bool-1" value="1"/>
-            <bool description="Familie/Eltern" name="bool-2" value="2"/>
-            <bool description="Schule" name="bool-3" value="3"/>
-            <bool description="Lehrer/in" name="bool-4" value="4"/>
-            <bool description="Schulsozialarbeit" name="bool-5" value="5"/>
-            <bool description="Streetwork" name="bool-6" value="6"/>
-            <bool description="Jugendamt" name="bool-7" value="7"/>
-            <bool description="Jugendhilfeeinrichtung" name="bool-8" value="8"/>
-            <bool description="Beratungsstelle" name="bool-9" value="9"/>
-            <bool description="SGB II - Träger" name="bool-10" value="10"/>
-            <bool description="Verwandte" name="bool-11" value="11"/>
-            <bool description="Soziales Umfeld (Freunde, Bekannte)" name="bool-12" value="12"/>
-            <bool description="Kompetenzagentur" name="bool-13" value="13"/>
-            <bool description="Koordinierungsstelle" name="bool-413" value="15"/>
-            <bool description="Jugendmigrationsdienst" name="bool-14" value="14"/>
+            <group description="Institutionelle Zugangswege" name="group-instzugang">
+              <bool description="Schule" name="bool-3" value="3"/>
+              <bool description="Lehrer/in" name="bool-4" value="4"/>
+              <bool description="Schulsozialarbeit" name="bool-5" value="5"/>
+              <bool description="Jugendamt" name="bool-7" value="7"/>
+              <bool description="Jugendhilfeeinrichtung" name="bool-8" value="8"/>
+              <bool description="Beratungsstelle" name="bool-9" value="9"/>
+              <bool description="SGB II - Träger" name="bool-10" value="10"/>
+              <bool description="Kompetenzagentur" name="bool-13" value="13"/>
+              <bool description="Koordinierungsstelle" name="bool-413" value="15"/>
+              <bool description="Jugendmigrationsdienst" name="bool-14" value="14"/>
+            </group>
+            <group description="Offene Zugangswege" name="group-offenugang">
+              <bool description="Familie/Eltern" name="bool-2" value="2"/>
+              <bool description="Eigenständiger Zugang des Jugendlichen" name="bool-1" value="1"/>
+              <bool description="Streetwork" name="bool-6" value="6"/>
+              <bool description="Verwandte" name="bool-11" value="11"/>
+              <bool description="Soziales Umfeld (Freunde, Bekannte)" name="bool-12" value="12"/>
+              <bool description="Sonstiges" name="bool-15" value="-2"/>
+            </group>
             <bool description="unbekannt" name="unbekannt-0" value="-3"/>
-            <bool description="Sonstiges" name="bool-15" value="-2"/>
             <bool checked="true" description="keine Angabe" name="bool-106" value="-1"/>
           </choice>
           <text description="Nennung Sonstiges" function="suppress_value" maxlength="256" name="zugang_t" size="40"/>

Modified: wasko/branches/2.0/waskaweb/lib/renderer_new.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/renderer_new.py	2009-11-18 08:03:51 UTC (rev 697)
+++ wasko/branches/2.0/waskaweb/lib/renderer_new.py	2009-11-18 14:56:44 UTC (rev 698)
@@ -30,6 +30,7 @@
 
 import logging
 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 waskaweb.lib.db import PostgresDBInterface 
@@ -115,6 +116,15 @@
             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):
@@ -181,8 +191,14 @@
                 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 = node.getMeta()
+        meta = self._getMeta(node)
         out = []
         error = node.hasErrors() and "error" or ""
         if labeltag:
@@ -194,7 +210,7 @@
         return "\n".join(out)
 
     def _renderAttributes(self, node):
-        meta = node.getMeta()
+        meta = self._getMeta(node)
 
         out = []
         log.debug('Search help')
@@ -209,14 +225,14 @@
         return "\n".join(out)
 
     def _renderErrors(self, node):
-        meta = node.getMeta()
+        meta = self._getMeta(node)
         out = []
         if node.hasErrors():
             out.append('<span class="error">%s</span>' % node.getError())
         return "\n".join(out)
 
     def _renderDummyGroup(self, node):
-        meta = node.getMeta()
+        meta = self._getMeta(node)
         description = meta.getDescription()
 
         out = []
@@ -233,7 +249,7 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderDummyLeaf(self, node):
-        meta = node.getMeta()
+        meta = self._getMeta(node)
         description = meta.getDescription()
         flags       = meta.getFlags()
         name        = node.getIdentifier()
@@ -253,7 +269,7 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderGroup(self, node):
-        meta = node.getMeta()
+        meta = self._getMeta(node)
         description = meta.getDescription()
 
         out = []
@@ -271,7 +287,7 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderRepeatContainer(self, node):
-        meta = node.getMeta()
+        meta = self._getMeta(node)
         description = meta.getDescription()
         out = []
         out.append('<fieldset>')
@@ -327,7 +343,7 @@
         return out
 
     def _renderConditional(self, conditional):
-        meta = conditional.getMeta()
+        meta = self._getMeta(conditional)
         out = u""
         if True: #meta.evaluate():
             ro = not meta.isInvisible()
@@ -344,7 +360,7 @@
                 self._renderChild(child)
 
     def _renderInfo(self, node):
-        meta = node.getMeta()
+        meta = self._getMeta(node)
         out = []
         if meta.isInvisible(): return
         text, depth = meta.getValue(), 1#visibleDepth(node)
@@ -357,7 +373,7 @@
             self.toTarget(Div("".join(out)), meta.getTarget())
 
     def _renderText(self, node):
-        meta = node.getMeta() 
+        meta = self._getMeta(node) 
         out  = []
         id   = node.getIdentifier()
         data = node.getValue() or ""
@@ -373,7 +389,7 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderDate(self, node):
-        meta = node.getMeta() 
+        meta = self._getMeta(node) 
         out  = []
         id   = node.getIdentifier()
         data = node.getValue() or ""
@@ -389,7 +405,7 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderInt(self, node):
-        meta = node.getMeta() 
+        meta = self._getMeta(node) 
         out  = []
         id   = node.getIdentifier()
         data = node.getValue() or ""
@@ -403,7 +419,7 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderTextArea(self, node):
-        meta  = node.getMeta() 
+        meta  = self._getMeta(node) 
         out   = []
         id    = node.getIdentifier()
         value = node.getValue() or ""
@@ -424,13 +440,13 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderRadio(self, node):
-        meta  = node.getMeta()
+        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 = child.getMeta().getValue()
+            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))
@@ -442,12 +458,13 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderPlainBool(self, node):
-        meta  = node.getMeta()
+        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>' 
@@ -462,7 +479,7 @@
         self.toTarget(Item("".join(out)), meta.getTarget())
 
     def _renderChoice(self, node):
-        meta        = node.getMeta()
+        meta        = self._getMeta(node)
         id          = node.getIdentifier()
         value       = node.getValue()
         description = meta.getDescription()
@@ -476,22 +493,67 @@
         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))
-        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))
+        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        = node.getMeta()
+        meta        = self._getMeta(node)
         description = meta.getDescription()
         disabled    = self.ro_mode and "disabled" or ""
         out = []
@@ -504,7 +566,7 @@
         out.append(self._renderLabel(node, False))
         out.append(self._renderAttributes(node))
         out.append('</th>')
-        for hcol in node.getChildren()[0].getMeta().children:
+        for hcol in self._getMeta(node.getChildren()[0]).children:
             hcolmeta = hcol
             alternative = hcolmeta.getAlternative()
             description = hcolmeta.getDescription()
@@ -524,7 +586,7 @@
             out.extend(self._renderAttributes(row))
             out.append('</td>')
             self.stateStack.append(str(row.getValue()))
-            for col in row.getMeta().children:
+            for col in self._getMeta(row).children:
                 name = row.getIdentifier()
                 name = name
                 value = col.getValue() 
@@ -536,7 +598,7 @@
             out.append("</tr>")
 
         # write legend
-        length = len(node.getChildren()[0].getMeta().children)+1
+        length = len(self._getMeta(node.getChildren()[0]).children)+1
         out.append('<tr><td colspan="%s"></td></tr>' % str(length))
         if legend:
             out.append('<tr>')
@@ -556,16 +618,20 @@
     def _renderPage(self, page):
         out = []
         out.append(self._renderRecursive(page))
-        self.toTarget(Item("\n".join(out)), page.getMeta().getTarget())
+        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
 
-        parent = bool.parent
-
-        if isinstance(parent,  data.ChoiceNode):
+        # 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(parent, data.RadioNode):
+        elif isinstance(self._getMeta(parent), data.RadioNode):
             self._renderRadioBool(bool)
 
         else:
@@ -583,12 +649,14 @@
         return out
 
     def _renderChild(self, child):
-        meta = child.getMeta()
+        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):
@@ -605,8 +673,7 @@
         elif isinstance(meta, data.InfoLeaf):
             self._renderInfo(child)
         elif isinstance(meta, data.BoolLeaf):
-            #self._renderBool(child)
-            self._renderPlainBool(child)
+            self._renderBool(child)
         elif isinstance(meta, data.TextLeaf):
             self._renderText(child)
         elif isinstance(meta, data.TextAreaLeaf):
@@ -618,16 +685,18 @@
         elif isinstance(meta, data.ExternalChoiceListLeaf):
             self._renderExternalChoiceList(child)
 
-    def _renderRecursive(self, node, doBreak=True):
-        meta = node.getMeta()
+    def _renderRecursive(self, node, doBreak=True, Cont=Container):
+        meta = self._getMeta(node)
+
         containers = meta.getContainers()
 
-        containers = containers and [Container(c.strip()) for c in containers.split(",")] or []
-        containers.append(Container(None))
+        containers = containers and [Cont(c.strip()) for c in containers.split(",")] or []
+        containers.append(Cont(None))
 
         self.containersStack.append(containers)
 
-        for child in node.getChildren():
+        children = node.getChildren()
+        for child in children:
             self._renderChild(child)
 
         out = []
@@ -647,7 +716,7 @@
         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(rg.getMeta().getName(), []) 
+            fields  = digests.get(self._getMeta(rg).getName(), []) 
 
         out.append('<table class="rgdigest">')
         if len(fields) < 1:
@@ -658,13 +727,13 @@
                 out.append('<tr>')
                 out.append('<td class="label">')
                 out.append('<a href="/navigation/select_branch/%s">' % rg.getChildren()[0].getIdentifier())
-                out.append(item.getMeta().getDescription())
+                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(item.getMeta(), data.DateLeaf):
+                if isinstance(self._getMeta(item), data.DateLeaf):
                     if value: value = format_date(value) 
                 out.append('%s' % NA(value))
                 out.append('</a>')
@@ -703,7 +772,7 @@
         self.warnings    = warnings
 
     def render(self, page):
-        meta = page.getMeta()
+        meta = self._getMeta(page)
         page_name = meta.getName()
 
         #errors_list = [kv for kv in self.error_items.iteritems() if kv[1].page == page_name]



More information about the Mpuls-commits mailing list