[Mpuls-commits] r138 - in waska/trunk: . waskaweb/controllers waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Sep 8 14:26:14 CEST 2008


Author: teichmann
Date: 2008-09-08 14:26:14 +0200 (Mon, 08 Sep 2008)
New Revision: 138

Modified:
   waska/trunk/ChangeLog.txt
   waska/trunk/waskaweb/controllers/case.py
   waska/trunk/waskaweb/model/navigation.py
   waska/trunk/waskaweb/model/phases_factory.py
Log:
Links of missing fields go direct to case.


Modified: waska/trunk/ChangeLog.txt
===================================================================
--- waska/trunk/ChangeLog.txt	2008-09-08 08:38:25 UTC (rev 137)
+++ waska/trunk/ChangeLog.txt	2008-09-08 12:26:14 UTC (rev 138)
@@ -1,5 +1,13 @@
 2008-09-08  Sascha L. Teichmann <sascha.teichmann at intevation.de>
 
+	* waskaweb/model/navigation.py: add method findTreeItem().
+
+	* waskaweb/model/phases_factory.py: generate direct links to missing fields
+
+	* waskaweb/controllers/case.py: use navigation tree to find page for missing fields.
+
+2008-09-08  Sascha L. Teichmann <sascha.teichmann at intevation.de>
+
 	* waskaweb/model/phases_factory.py: added a method getSQLWhereClauses() to return
 	  a list of tuples (<symbol of phase>, <sql where clause>) to check phase inconsistencies
 	  at database level.

Modified: waska/trunk/waskaweb/controllers/case.py
===================================================================
--- waska/trunk/waskaweb/controllers/case.py	2008-09-08 08:38:25 UTC (rev 137)
+++ waska/trunk/waskaweb/controllers/case.py	2008-09-08 12:26:14 UTC (rev 138)
@@ -694,7 +694,12 @@
 
         phase = case.getState().getPhase()
 
-        c.phase_pairs   = phases_pairs(fields, phase)
+        session_case = session.get('case')
+
+        mode = session_case and session_case.getMode() or "show" 
+        link = lambda ti: '"/case/%s/%d/%s"' % (mode, ti.realId(id), ti.key)
+
+        c.phase_pairs   = phases_pairs(fields, phase, self.getNavigation(), link)
         c.current_phase = Phase(phase, True)
 
         c.form_navigation  = self._getFormNavigation()

Modified: waska/trunk/waskaweb/model/navigation.py
===================================================================
--- waska/trunk/waskaweb/model/navigation.py	2008-09-08 08:38:25 UTC (rev 137)
+++ waska/trunk/waskaweb/model/navigation.py	2008-09-08 12:26:14 UTC (rev 138)
@@ -280,21 +280,24 @@
         headers.reverse()
         return headers
 
-    def getTreeItemByPageName(self, name):
-        '''Returns the treeitem which will be actually rendered when clicking
-        on the item in navigation tree. This is the last treeitem in the tree
-        with the given name'''
+    def findTreeItemByPageName(self, name):
         stack = [self.children]
         item = None
         while stack:
             children = stack.pop()
             for c in children:
                 if c.page == name:
-                    item = c
+                    return c
                 if c.children:
                     stack.append(c.children)
-        if item == None:
-            raise HTTPNotFound()
+        return None
+
+    def getTreeItemByPageName(self, name):
+        '''Returns the treeitem which will be actually rendered when clicking
+        on the item in navigation tree. This is the last treeitem in the tree
+        with the given name'''
+        item = self.findTreeItemByPageName(name)
+        if not item: raise HTTPNotFound()
         return item
 
     def render(self, select_action, toggle_action, selected_key=None):

Modified: waska/trunk/waskaweb/model/phases_factory.py
===================================================================
--- waska/trunk/waskaweb/model/phases_factory.py	2008-09-08 08:38:25 UTC (rev 137)
+++ waska/trunk/waskaweb/model/phases_factory.py	2008-09-08 12:26:14 UTC (rev 138)
@@ -28,11 +28,13 @@
 # Sascha L. Teichmann <sascha.teichmann at intevation.de>
 #
 
-#import sys
+import sys
 
 from waskaweb.model.phases           import *
 from waskaweb.model.phase_transition import *
 
+from waskaweb.model.data             import PageNode
+
 IS_FILLED = \
 """(%(name)s IS NOT NULL
     AND (get_default_value('master_tbl', '%(name)s') IS NULL
@@ -53,6 +55,23 @@
         p = p.parent
     return nc.getName()
 
+def page(nc):
+    p = nc.parent
+    while p:
+        if isinstance(p, PageNode):
+            return p
+        p = p.parent
+    return p
+
+def lookup_item(item, navigation, link):
+    if navigation and link:
+        p = page(item)
+        if p:
+            ti = navigation.findTreeItemByPageName(p.getName())
+            if ti: return link(ti)
+#                '"/case/show/%d/%s"' % (ti.realId(case_id), ti.key)
+    return '"/case/required/%s" target="_blank"' % item.getName()
+
 class RequiredFields:
 
     def __init__(self):
@@ -208,7 +227,7 @@
 
         return True
 
-    def getLinkListForPhase(self, phase):
+    def getLinkListForPhase(self, phase, navigation = None, link = None):
         try:
             phase = self.phases[phase]
         except KeyError:
@@ -218,9 +237,11 @@
 
         for a in phase:
             warn = (not a[1]) and ' class="required_missing"' or ""
-            link = '<a href="/case/required/%s" target="blank"%s>%s</a>' % (
-                a[0].getName(), warn, description(a[0]))
-            out.append(link)
+            l = '<a href=%s %s>%s</a>' % (
+                lookup_item(a[0], navigation, link),
+                warn, 
+                description(a[0]))
+            out.append(l)
 
         return ',\n'.join(out)
 
@@ -230,7 +251,7 @@
     (BERATUNG_START, BERATUNG_ENDE, u"Beratung"),
     (NB_START,       NB_ENDE,       u"Nachbetreuung"))
 
-def phases_pairs(required_fields, current_phase):
+def phases_pairs(required_fields, current_phase, navigation = None, link = None):
 
     pairs = []
 
@@ -243,7 +264,7 @@
             p1 == current_phase,
             required_fields.isPhaseComplete(symbol),
             required_fields.getPhaseTime(symbol),
-            required_fields.getLinkListForPhase(symbol))
+            required_fields.getLinkListForPhase(symbol, navigation, link))
 
         symbol = phase_symbol(p2)
 
@@ -252,7 +273,7 @@
             p2 == current_phase,
             required_fields.isPhaseComplete(symbol),
             required_fields.getPhaseTime(symbol),
-            required_fields.getLinkListForPhase(symbol))
+            required_fields.getLinkListForPhase(symbol, navigation, link))
 
         pairs.append(PhasePair(start, ende, description))
 



More information about the Mpuls-commits mailing list