[Mpuls-commits] r4183 - in base/trunk: . mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Nov 15 20:46:15 CET 2010


Author: bh
Date: 2010-11-15 20:46:15 +0100 (Mon, 15 Nov 2010)
New Revision: 4183

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/search.py
Log:
* mpulsweb/lib/search.py (CaseSearch.get_phases_dates_clause): For
the combined date/phase search also check that the current phase
is the matching phase or one of its successor phases.
Implements the search part of mpuls/issue1268


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-11-15 19:33:28 UTC (rev 4182)
+++ base/trunk/ChangeLog	2010-11-15 19:46:15 UTC (rev 4183)
@@ -1,5 +1,12 @@
 2010-11-15  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/lib/search.py (CaseSearch.get_phases_dates_clause): For
+	the combined date/phase search also check that the current phase
+	is the matching phase or one of its successor phases.
+	Implements the search part of mpuls/issue1268
+
+2010-11-15  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/model/phase.py (get_phase_successors): Add optional
 	parameter phaselist so that the phaselist does not have to be
 	regenerated on every invocation.

Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py	2010-11-15 19:33:28 UTC (rev 4182)
+++ base/trunk/mpulsweb/lib/search.py	2010-11-15 19:46:15 UTC (rev 4183)
@@ -10,7 +10,7 @@
 
 from mpulsweb.lib.db import db
 from mpulsweb.lib.security import hasRole
-from mpulsweb.model.phase import PhaseFactory
+from mpulsweb.model.phase import PhaseFactory, get_phase_successors
 
 
 SAVE_SEARCH = re.compile(r'[^\w:;\-\. ]', re.UNICODE)
@@ -359,7 +359,8 @@
         clause matches all cases which were in one of the given phases
         during the given time.  More precisely, it matches all cases
         where the date interval of one of the phases in the phases list
-        overlaps the interval specified for the search.
+        overlaps the interval specified for the search and the current
+        phase is that phase or one the successor phases of that phase.
 
         Otherwise, the clause matches all cases that are currently in
         one of the given phases.
@@ -380,7 +381,8 @@
 
         phases = options.get('phase')
         phase_clauses = []
-        for p in PhaseFactory().build():
+        phase_list = PhaseFactory().build()
+        for p in phase_list:
             sp = p.getStart()
             ep = p.getEnd()
 
@@ -399,13 +401,16 @@
                 # start date of the phase has not been set yet should
                 # not match.  However, cases where the end date of the
                 # phase has not been set yet should match.
+                successors = get_phase_successors(sp.phase, phase_list)
                 phase_clauses.append("(%s IS NOT NULL"
                                      " AND (%s::date <= '%s'::date)"
                                      " AND "
                                      "(coalesce(%s, now())::date "
-                                     ">= '%s'::date))"
+                                     ">= '%s'::date)"
+                                     " AND phase IN (%s))"
                                      % (sp.datefield, sp.datefield, ed,
-                                        ep.datefield, sd))
+                                        ep.datefield, sd,
+                                        ",".join(str(s) for s in successors)))
         if phase_clauses:
             return "(%s)" % " OR ".join(phase_clauses)
         return "FALSE"



More information about the Mpuls-commits mailing list