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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 25 15:39:05 CET 2009


Author: teichmann
Date: 2009-02-25 15:39:02 +0100 (Wed, 25 Feb 2009)
New Revision: 299

Modified:
   wasko/trunk/ChangeLog.txt
   wasko/trunk/waskaweb/model/casedocument.py
   wasko/trunk/waskaweb/model/phases_factory.py
Log:
Various fixes for the phase overview.


Modified: wasko/trunk/ChangeLog.txt
===================================================================
--- wasko/trunk/ChangeLog.txt	2009-02-25 14:11:32 UTC (rev 298)
+++ wasko/trunk/ChangeLog.txt	2009-02-25 14:39:02 UTC (rev 299)
@@ -1,3 +1,14 @@
+2009-02-25	Sascha L. Teichmann <teichmann at intevation.de>
+
+	* waskaweb/model/casedocument.py: Suppress traceback output if
+	  rule evalution fails. Fixed problem with missing dates in
+	  phase overview.
+
+	* waskaweb/model/phases_factory.py: Repair several small issue
+	  with rule evaluation. Do some more caching to prevent
+	  redundant rule evaluations. Repaired links to missing fields.
+	  Generate links to already filled pages.
+
 2009-02-25	Torsten Irlaender  <torsten.irlaender at intevation.de> 
 
 	Modified logbook

Modified: wasko/trunk/waskaweb/model/casedocument.py
===================================================================
--- wasko/trunk/waskaweb/model/casedocument.py	2009-02-25 14:11:32 UTC (rev 298)
+++ wasko/trunk/waskaweb/model/casedocument.py	2009-02-25 14:39:02 UTC (rev 299)
@@ -207,7 +207,7 @@
                 okay = expr.evaluate(dict([
                     (n, self.getData(n, ds_id)) for n in expr.getDependencies()]))
             except:
-                print_exc(file=sys.stderr)
+                #print_exc(file=sys.stderr)
                 okay = False
 
             if not okay:

Modified: wasko/trunk/waskaweb/model/phases_factory.py
===================================================================
--- wasko/trunk/waskaweb/model/phases_factory.py	2009-02-25 14:11:32 UTC (rev 298)
+++ wasko/trunk/waskaweb/model/phases_factory.py	2009-02-25 14:39:02 UTC (rev 299)
@@ -33,7 +33,11 @@
 
 from waskaweb.model.data             import PageNode, WidgetCollector, DateLeaf, RuleLeaf
 
+from waskaweb.model.casedocument     import WARNING
+
 import re
+import sys
+import traceback
 
 from cgi import escape
 
@@ -67,6 +71,7 @@
         self.phase_times     = {}
         self.missing_cache   = {}
         self.rule_eval_cache = {}
+        self.var_eval_cache  = {}
 
     def getPhaseTime(self, phase):
         try:
@@ -75,7 +80,7 @@
             try:
                 time_vars = self.formed.getTimeVars(phase)
                 if not time_vars: return None
-                pt = [self.formed.getData(x) for x in time_vars]
+                pt = [self.formed.getData(x.getName()) for x in time_vars]
                 if pt: pt = pt[0]
                 else:  pt = None
                 self.phase_times[phase] = pt
@@ -84,7 +89,7 @@
             return pt
 
     def isPhaseComplete(self, phase):
-        return bool(self.missingFields(phase))
+        return not bool(self.missingFields(phase))
 
     def missingFields(self, phase):
 
@@ -102,52 +107,78 @@
         self.missing_cache[phase] = missing
         for var in vars:
             var_name = var.getName()
+
             try:
-                result = self.rule_eval_cache[var_name]
+                result = self.var_eval_cache[var_name]
+                if result: missing.add(var)
+                continue
             except KeyError:
-                rules = self.formed.getRulesForVariable(
-                    var_name)
-                if not rules: continue
-                result = True
-                for rule in rules:
+                pass
+
+            rules = self.formed.getRulesForVariable(var_name)
+            if not rules: continue
+
+            result = True
+            for rule in rules:
+                # only eval warning rules
+                mark = WARNING.search(rule.getMark())
+                if not mark: continue
+                rule_name = rule.getName()
+                try:
+                    result = self.rule_eval_cache[rule_name]
+                except KeyError:
                     expr   = rule.getExpr()
                     deps   = expr.getDependencies()
                     params = dict((v, getData(v)) for v in deps)
                     try:
-                        result = expr.eval(params)
+                        result = expr.evaluate(params)
                     except:
-                        result = False
-                    if not result: break
+                        result = True
+                    self.rule_eval_cache[rule_name] = result
 
-                self.rule_eval_cache[var_name] = result
-                if not result:
-                    missing.append(var)
+                if not result: break
+
+            self.var_eval_cache[var_name] = result
+            if not result: missing.append(var)
+
         return missing
 
     def getLinkListForPhase(self, phase, navigation=None, link=None):
 
         if not navigation and not link: return u""
 
-        missing = self.missingFields(phase)
+        all_vars = self.formed.getPhaseVars(phase)
+        if not all_vars: return u""
 
-        out = []
+        missing_set = set([x.getName() for x in self.missingFields(phase)])
 
-        used_pages = set()
+        pages, used_pages = [], {}
 
-        for var in missing:
+        for var in all_vars:
             p = page(var)
             p_name = p.getName()
-            if p_name in used_pages: continue
-            tree_item = navigation.findTreeItemByPageName(p_name)
-            if not tree_item: continue
-            tree_item = tree_item.deepest_item()
-            l = link(tree_item)
-            out.append('<a href=%s>%s</a>' % (
-                l, escape(description(p)).replace(' ', '&nbsp;')))
-            used_pages.add(p_name)
+            try:
+                t = used_pages[p_name]
+            except KeyError:
+                tree_item = navigation.findTreeItemByPageName(p_name)
+                if not tree_item: continue
+                tree_item = tree_item.deepest_item()
+                t = [tree_item, False]
+                pages.append(t)
+                used_pages[p_name] = t
 
-        return u", ".join(out)
+            if var.getName() in missing_set:
+                t[1] = True
 
+        out = []
+        for tree_item, miss in pages:
+            #print >> sys.stderr, "page: %s %s" % (tree_item.name, miss)
+            warn = miss and 'class="required_missing"' or ''
+            out.append('<a href=%s %s>%s' % (
+                link(tree_item), warn, escape(tree_item.description).replace(' ', '&nbsp;')))
+
+        return u",</a> ".join(out) + (out and "</a>" or "")
+
     def phases_pairs(self, current_phase, navigation=None, link=None):
 
         pairs = []



More information about the Mpuls-commits mailing list