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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Aug 27 18:56:01 CEST 2008


Author: teichmann
Date: 2008-08-27 18:56:00 +0200 (Wed, 27 Aug 2008)
New Revision: 92

Added:
   waska/trunk/waskaweb/lib/needed.py
Modified:
   waska/trunk/ChangeLog.txt
   waska/trunk/waskaweb/controllers/case.py
   waska/trunk/waskaweb/model/nodecomponents.py
Log:
Extracted required fields from FormEd tree.


Modified: waska/trunk/ChangeLog.txt
===================================================================
--- waska/trunk/ChangeLog.txt	2008-08-27 16:36:03 UTC (rev 91)
+++ waska/trunk/ChangeLog.txt	2008-08-27 16:56:00 UTC (rev 92)
@@ -1,5 +1,14 @@
 2008-08-27  Sascha L. Teichmann <sascha.teichmann at intevation.de>
 
+	* waskaweb/lib/needed.py: New. extracting required fields
+	  for phases from FormEd tree.
+
+	* waskaweb/model/nodecomponents.py: Added walk() across the tree.
+
+	* waskaweb/controllers/case.py: Call (needed.py)extractRequiredFields
+
+2008-08-27  Sascha L. Teichmann <sascha.teichmann at intevation.de>
+
 	* waskaweb/templates/casemanagement/required.mako: Added missing 
 	  Mako template.
 

Modified: waska/trunk/waskaweb/controllers/case.py
===================================================================
--- waska/trunk/waskaweb/controllers/case.py	2008-08-27 16:36:03 UTC (rev 91)
+++ waska/trunk/waskaweb/controllers/case.py	2008-08-27 16:56:00 UTC (rev 92)
@@ -49,6 +49,8 @@
                                         CreateLogbookForm, \
                                         EditLogbookForm
 
+from waskaweb.lib.needed import extractRequiredFields
+
 from waskaweb.lib.helpers import dd_mm_YYYY, HH_MM
 
 from waskaweb.model.repeatgroup    import AidObject, AidList 
@@ -676,6 +678,7 @@
     def phase(self, id):
         id                 = self._checkInt(id)
         case               = self._loadCase(id)
+        fields = extractRequiredFields(g.formedTree)
         return render('/casemanagement/phase.mako')
 
     @checkRole('cm_ka')

Added: waska/trunk/waskaweb/lib/needed.py
===================================================================
--- waska/trunk/waskaweb/lib/needed.py	2008-08-27 16:36:03 UTC (rev 91)
+++ waska/trunk/waskaweb/lib/needed.py	2008-08-27 16:56:00 UTC (rev 92)
@@ -0,0 +1,64 @@
+# -*- 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>
+#
+
+import sys
+
+def extractRequiredFields(document):
+
+    phases = {}
+
+    all = []
+    
+    for nc in document.walk():
+        flags = nc.getFlags()
+        if flags is None: continue
+        for pair in flags.split(';'):
+            pair = pair.strip()
+            if not pair: continue
+            p = [p.strip() for p in pair.split(':')]
+            if len(p) > 1:
+                kind, phase = p[0], p[1]
+                if kind == "required":
+                    phases.setdefault(phase, []).append(nc)
+            else:
+                # TODO: Fix formed tree
+                if p[0] == "required":
+                    all.append(nc)
+
+    for a in all:
+        for v in phases.itervalues():
+            v.append(a)
+
+    for k in sorted(phases.iterkeys()):
+        print >> sys.stderr, "phase '%s': %s" % (k, ', '.join([nc.getName() for nc in phases[k]]))
+        
+    return phases
+
+# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

Modified: waska/trunk/waskaweb/model/nodecomponents.py
===================================================================
--- waska/trunk/waskaweb/model/nodecomponents.py	2008-08-27 16:36:03 UTC (rev 91)
+++ waska/trunk/waskaweb/model/nodecomponents.py	2008-08-27 16:56:00 UTC (rev 92)
@@ -43,6 +43,7 @@
         self.attributes["annotation"]   = ""
         self.attributes["target"]       = ""
         self.attributes["alternative"]  = ""
+        self.attributes["flags"]        = ""
 
     def setAttribute(self, key, value, broadcast=True):
         self.attributes[key] = value
@@ -92,6 +93,12 @@
     def setModes(self, modes):
         self.setAttribute("modes", modes)
 
+    def getFlags(self):
+        return self.getAttribute("flags")
+
+    def setFlags(self, flags):
+        return self.setAttribute("flags", flags)
+
     def getParent(self):
         return self.parent
 
@@ -288,4 +295,9 @@
                 if isinstance(nc, clazz):
                     yield nc
 
+    def walk(self):
+        if self.root:
+            for nc in self.root.walk():
+                yield nc
+
 # vim:set ts=4 sw=4 si et sta sts=4:



More information about the Mpuls-commits mailing list