[Mpuls-commits] r3592 - in base/trunk: . mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Sep 10 17:38:48 CEST 2010
Author: bh
Date: 2010-09-10 17:38:46 +0200 (Fri, 10 Sep 2010)
New Revision: 3592
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/lib/search.py
Log:
Main part of mpuls/issue1085
* mpulsweb/lib/search.py (CaseSearch.get_phases_clause)
(CaseSearch.get_dates_clause): Combined to form the new
get_phases_dates_clause which has different semantics
(CaseSearch.get_phases_dates_clause): New. The phase and date
range search options are tightly related so they need to be
handled together. If both phases and a date range is given, the
clause returned now matches cases that were in the given phase
during the given date range.
(CaseSearch.get_where_subclauses): Adapt to above method changes.
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2010-09-10 14:56:47 UTC (rev 3591)
+++ base/trunk/ChangeLog 2010-09-10 15:38:46 UTC (rev 3592)
@@ -1,3 +1,17 @@
+2010-09-10 Bernhard Herzog <bh at intevation.de>
+
+ Main part of mpuls/issue1085
+
+ * mpulsweb/lib/search.py (CaseSearch.get_phases_clause)
+ (CaseSearch.get_dates_clause): Combined to form the new
+ get_phases_dates_clause which has different semantics
+ (CaseSearch.get_phases_dates_clause): New. The phase and date
+ range search options are tightly related so they need to be
+ handled together. If both phases and a date range is given, the
+ clause returned now matches cases that were in the given phase
+ during the given date range.
+ (CaseSearch.get_where_subclauses): Adapt to above method changes.
+
2010-09-08 Roland Geider <roland.geider at intevation.de>
* mpulsweb/i18n/de/LC_MESSAGES/mpulsweb.po: issue1064: consequent use
Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py 2010-09-10 14:56:47 UTC (rev 3591)
+++ base/trunk/mpulsweb/lib/search.py 2010-09-10 15:38:46 UTC (rev 3592)
@@ -321,15 +321,6 @@
return "b.filiale = '%s'" % branch
return "TRUE"
- def get_phases_clause(self, options):
- """Return the search condition to select cases based on their phase.
- The returned clause should select all cases that are current in
- a phase contained in phaselist.
-
- Derived classes may override this method if necessary.
- """
- return self.generic_int_choice_clause(options, "phase", "m.phase")
-
def get_needle_clause(self, options):
"""Return the search condition to select cases based on search terms.
Derived classes may override this method if necessary.
@@ -346,29 +337,65 @@
return needle_expr % dict(needle=" ".join(search))
return "TRUE"
- def get_dates_clause(self, options):
- """Return the search condition to select cases based on start/end dates.
- Derived classes may override this method if necessary.
+ def get_phases_dates_clause(self, options):
+ """Return the search condition selecing cases based on phase and dates.
+
+ If options does not contain the key 'phase', the returned clause
+ is 'TRUE'. Otherwise the clause depends on whether any dates
+ were specified.
+
+ If both a start date and an end date are given, the returned
+ clause matches all cases which were in the given phase 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.
+
+ Otherwise, the clause matches all cases that are currently in
+ one of the given phases.
+
+ Note that the phases are specified as a list. If the options
+ dictionary contains the key 'phase' but the list of phases it
+ maps to is empty, the claus will be equivalent to 'FALSE' and no
+ case will match.
+
+ Derived classes may override this method if
+ necessary.
"""
- time_interval = "TRUE"
- if (options.get('sdate') and options.get('edate')):
- sd = options.get('sdate')
- ed = options.get('edate')
- time_interval_str = []
- phasepairs = PhaseFactory().build()
- for p in phasepairs:
- sp = p.getStart()
- ep = p.getEnd()
- time_interval_str.append('''
- (m.phase IN (%s, %s)
- AND (%s::date <= '%s'::date)
- AND (coalesce(%s, now())::date >= '%s'::date))
- ''' % (sp.id, ep.id, sp.datefield, ed, ep.datefield, sd))
- if -1 in options.get("phase", ()):
- time_interval_str.append("(m.phase = -1)")
- time_interval = "(%s)" % "OR".join(time_interval_str)
- return time_interval
+ phases = options.get('phase')
+ if phases is None:
+ # no phase option -> all cases match
+ return "TRUE"
+ sd = options.get('sdate')
+ ed = options.get('edate')
+
+ if sd is None or ed is None:
+ # no date range given -> match according to current phase
+ return self.generic_int_choice_clause(options, "phase", "m.phase")
+
+ phase_clauses = []
+ for p in PhaseFactory().build():
+ sp = p.getStart()
+ ep = p.getEnd()
+ if int(sp.id) in phases or int(ep.id) in phases:
+ # a phase either be finished, in which case we have both
+ # start and end dates for the phase, or it may be still
+ # running, in which case we have a start date but no end
+ # date yet. This means that cases where the 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.
+ phase_clauses.append("(%s IS NOT NULL"
+ " AND (%s::date <= '%s'::date)"
+ " AND "
+ "(coalesce(%s, now())::date "
+ ">= '%s'::date))"
+ % (sp.datefield, sp.datefield, ed,
+ ep.datefield, sd))
+ if phase_clauses:
+ return "(%s)" % " OR ".join(phase_clauses)
+ return "FALSE"
+
def get_status_clause(self, options):
"""Return the search condition to select cases based on status.
Derived classes may override this method if necessary.
@@ -397,8 +424,7 @@
self.get_allowed_viewer_clause(options),
self.get_editor_clause(options),
self.get_branch_clause(options),
- self.get_dates_clause(options),
- self.get_phases_clause(options),
+ self.get_phases_dates_clause(options),
self.get_gender_clause(options),
]
More information about the Mpuls-commits
mailing list