[Mpuls-commits] r257 - in wasko/trunk: . waskaweb/controllers waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 11 19:18:23 CET 2009


Author: teichmann
Date: 2009-02-11 19:18:22 +0100 (Wed, 11 Feb 2009)
New Revision: 257

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/controllers/CaseBase.py
   wasko/trunk/waskaweb/controllers/case.py
   wasko/trunk/waskaweb/model/navigation.py
Log:
Initial rebuild of the navigation.


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-02-11 14:48:41 UTC (rev 256)
+++ wasko/trunk/ChangeLog.txt	2009-02-11 18:18:22 UTC (rev 257)
@@ -1,5 +1,16 @@
 2009-02-11	Sascha L. Teichmann	<teichmann at intevation.de>
 
+	Initial rebuild of the navigation.
+
+	* waskaweb/model/navigation.py: Build navigation tree from
+	 formed tree.
+
+	* waskaweb/controllers/CaseBase.py,
+	  waskaweb/controllers/case.py: Removed some special WASKA 
+	  code.
+
+2009-02-11	Sascha L. Teichmann	<teichmann at intevation.de>
+
 	Make creation of cases work
 
 	* formed/privacy_statement.html,

Modified: wasko/trunk/waskaweb/controllers/CaseBase.py
===================================================================
--- wasko/trunk/waskaweb/controllers/CaseBase.py	2009-02-11 14:48:41 UTC (rev 256)
+++ wasko/trunk/waskaweb/controllers/CaseBase.py	2009-02-11 18:18:22 UTC (rev 257)
@@ -73,7 +73,7 @@
             formdata          = self._getFormdata(ti, real_id, no_data)
             vr                = ViewRenderer(formdata, ro_mode)
             content           = vr.renderView(
-                ti.key, 
+                str(ti.key), 
                 ds_id,  
                 "/case/save", 
                 showNext = not ti.nextKey() is None)

Modified: wasko/trunk/waskaweb/controllers/case.py
===================================================================
--- wasko/trunk/waskaweb/controllers/case.py	2009-02-11 14:48:41 UTC (rev 256)
+++ wasko/trunk/waskaweb/controllers/case.py	2009-02-11 18:18:22 UTC (rev 257)
@@ -172,7 +172,7 @@
         session_case = case.getSessionCase()
         session['case'] = session_case
 
-        navigation = NavigationTree(case)
+        navigation = NavigationTree(g.formedTree, case)
         session['navigation.tree'] = navigation
         session.save()
         return case
@@ -376,7 +376,8 @@
 
         c.page_id = page_id
         c.print_form = "show" # Which page to open in popup on printing?
-        content, navigation = self._getRenderdFormElements(ti, ds_id, page_id, ro_mode=False)
+        content, navigation = self._getRenderdFormElements(
+            ti, ds_id, page_id, ro_mode=False)
         c.formular = content
         c.form_navigation = navigation 
         return render('/casemanagement/formular.mako')

Modified: wasko/trunk/waskaweb/model/navigation.py
===================================================================
--- wasko/trunk/waskaweb/model/navigation.py	2009-02-11 14:48:41 UTC (rev 256)
+++ wasko/trunk/waskaweb/model/navigation.py	2009-02-11 18:18:22 UTC (rev 257)
@@ -33,41 +33,8 @@
 from paste.httpexceptions  import HTTPNotFound
 from waskaweb.lib.helpers  import getHelp
 
-NEXT_KEYS = {
-    "0"   : "26",
-    "26"  : "1",
-    "1"   : "3",
-    "2"   : "7",
-    "3"   : "4",
-    "4"   : "5",
-    "5"   : "2",
-    "6"   : "7",
-    "7"   : "8",
-    "8"   : "10",
-    "9"   : "12",
-    "10"  : "12",
-    "11"  : "12",
-    "12"  : "32",
-    "13"  : "14",
-    "14"  : "18",
-    "18"  : "20",
-    "19"  : "21",
-    "20"  : "21",
-    "21"  : "23",
-    "22"  : "23",
-    "23"  : "24",
-    "24"  : "25",
-    "27"  : "14",
-    "28"  : "14",
-    "29"  : "14",
-    "30"  : "14",
-    "31"  : "32",
-    "32"  : "33",
-    "33"  : "34",
-    "34"  : "35",
-    "35"  : "13",
-    "36"  : "1"
-}
+from waskaweb.model.nodecomponents import Node
+from waskaweb.model.data           import PageNode
 
 class TreeItem:
 
@@ -149,7 +116,18 @@
         return id
 
     def nextKey(self):
-        return NEXT_KEYS.get(self.key)
+        n_key = self.key + 1
+        root = self
+        while root.parent:
+            root = root.parent
+        stack = root.children[:]
+        while stack:
+            item = stack.pop()
+            if item.key == n_key:
+                return n_key
+            if item.children:
+                stack.extend(item.children)
+        return None
 
     def showPath(self):
         current = self
@@ -157,97 +135,57 @@
             current.displayChildren = True
             current = current.parent
 
-class KompetenzTreeItem(TreeItem):
+def get_page(nc):
+    while nc:
+        if isinstance(nc, PageNode):
+            return nc.getName()
+        nc = nc.parent
+    return ""
 
-    def __init__(self, key, page, description, children, kid, fname):
-        TreeItem.__init__(self, key, page, description, children, fname=fname)
-        self.kid = kid
+class NavigationTreeBuilder(object):
 
-    def realId(self, id):
-        return self.kid
+    def __init__(self, formed):
+        #self.pages = []
+        self.key   = 0
+        self.root  = self.build(formed, None)
 
+    def build(self, nc, parent):
+        print >> sys.stderr, "class %s" % repr(nc)
+
+        if isinstance(nc, PageNode):
+            #self.pages.append(nc.getName())
+            ti = TreeItem(self.key, get_page(nc), nc.getDescription())
+            ti.parent = parent
+            self.key += 1
+            return ti
+
+        if isinstance(nc, Node):
+            children = []
+            n = TreeItem(self.key, get_page(nc), nc.getDescription(), children)
+            n.parent = parent
+            self.key += 1
+            for child in nc.children:
+                children.append(self.build(child, n))
+            return n
+
+        ti = TreeItem(self.key, "xxx", "Unknown Item")
+        ti.parent = parent
+        self.key += 1
+        return ti
+
 class NavigationTree:
 
     #def __init__(self, factories=None):
-    def __init__(self, case=None):
+    def __init__(self, formed, case=None):
         self.errors = [] #List page name with faulty pages
-        factories = {}
-        k_id = case.getKompetenzId()
-        
-        def xmake(key, page, description, children=None, fname=None):
-            return KompetenzTreeItem(key, page, description, children, k_id, fname)
 
-        if not k_id is None:
-            factories = {
-            "page_8": xmake,
-            "page_9": xmake,
-            "page_26": xmake,
-            "page_27": xmake,
-            "page_28": xmake,
-            "page_29": xmake
-            }
+        builder = NavigationTreeBuilder(formed.root.children[0])
 
-        def make(p):
-            def _make(*args, **v):
-                return factories.get(p, TreeItem)(*args, **v)
-            return _make
+        self.root = builder.root
 
-        self.children = [
-            make("page_0")("0", "page_0", "Zust&auml;ndigkeiten, Eingangsdaten", fname="info-0"),
-            make("page_25")("26", "page_25", "Externe Ansprechpartner", fname="info-28"),
-            make("page_1")("36", "page_1", "Angaben zur Person", [
-                make("page_1")("1", "page_1", "Pers&ouml;nliche Angaben"),
-                make("page_2")("3", "page_2", "Famili&auml;re Situation"),
-                make("page_3")("4", "page_3", "Gesundheitliche Situation"),
-                make("page_4")("5", "page_4", "Soziale Lage")
-            ], fname="info-1"),
-            make("page_2")("2", "page_5", "Biographische Daten", [
-                make("page_5")("6", "page_5", "Schule"),
-                make("page_6")("7", "page_6", "Ausbildung und Arbeit"),
-                make("page_7")("8", "page_7", "Weiterer Verlauf", fname="info-7")
-            ], fname="info-2"),
-            make("page_8")("9", "page_8", "Case-Management", [
-                make("page_8")("10", "page_8", "Kompetenzfeststellung", [
-                    make("page_8")("11", "page_8", "Verfahren"),
-                    make("page_9")("12", "page_9", "Ergebnisse der Kompetenzfeststellung", [
-                        make("page_9")("31", "page_9", "Fachkompetenzen"),
-                        make("page_26")("32", "page_26", "Methodenkompetenzen"),
-                        make("page_27")("33", "page_27", "Sprachen und Kommunikation"),
-                        make("page_28")("34", "page_28", "Sozial und Selbstkompetenzen")
-                    ], fname="info-9"),
-                    make("page_29")("35", "page_29", "Dokumentation")
-                ]),
-                make("page_10")("13", "page_10", "F&ouml;rderplanung", fname="info-14"),
-                make("rg_unterstuetzungsangebote")("14", "rg_unterstuetzungsangebote", "Unterst&uuml;tzungsangebote", [
-                    make("page_21")("27", "page_21", "Angebot im Bereich BB", None, False),
-                    make("page_22")("28", "page_22", "Angebot im Bereich BV", None, False),
-                    make("page_23")("29", "page_23", "Angebot im Bereich BQ", None, False),
-                    make("page_24")("30", "page_24", "Angebot im Bereich LB", None, False)
-                ]),
-                make("page_15")("18", "page_15", "Freie Dokumentation")
-            ], fname="info-8"),
-            make("page_16")("19", "page_16", "Abschlussbewertung", [
-                make("page_16")("20", "page_16", "Angaben zum Verlauf und Beendigung des CM"),
-                make("page_17")("21", "page_17", "Erreichte Oberziele", [
-                    make("page_17")("22", "page_17", "Berufliche Integration"),
-                    make("page_18")("23", "page_18", "Soziale Integration"),
-                    make("page_19")("24", "page_19", "Einsch&auml;tzung des Case-Managers")
-                ]),
-                make("page_20")("25", "page_20", "Freie Dokumentation")
-            ], fname="info-20")
-        ]
-        self.buildParents(self.children)
-
-    def buildParents(self, children, parent=None):
-        for child in children:
-            if parent:
-                child.setParent(parent)
-            if child.children: 
-                self.buildParents(child.children, child)
-
     def getAllItems(self, node=None):
         '''Returns a serialized list of treeitems'''
-        if not node: node = self
+        if not node: node = self.root
         items = []
         for c in node.children:
             items.append(c)
@@ -256,11 +194,12 @@
         return items
 
     def getTreeItem(self, key):
-        stack = [self.children]
+        key = int(key)
+        stack = [self.root.children]
         while stack:
             children = stack.pop()
             for c in children:
-                if c.key == str(key):
+                if c.key == key:
                     return c
                 if c.children:
                     stack.append(c.children)
@@ -281,7 +220,7 @@
         return headers
 
     def findTreeItemByPageName(self, name):
-        stack = [self.children]
+        stack = [self.root.children]
         item = None
         while stack:
             children = stack.pop()
@@ -302,7 +241,8 @@
 
     def render(self, select_action, toggle_action, selected_key=None):
         out = ['<ul>']
-        for child in self.children:
+        print >> sys.stderr, repr(self.root)
+        for child in self.root.children:
             child.render(select_action, toggle_action, out, (child.page in self.errors), selected_key)
         out.append('</ul>')
         return "\n".join(out)



More information about the Mpuls-commits mailing list