[Mpuls-commits] r3811 - in base/trunk: . mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Sep 28 19:02:02 CEST 2010
Author: bh
Date: 2010-09-28 19:01:59 +0200 (Tue, 28 Sep 2010)
New Revision: 3811
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/lib/search.py
Log:
Change the search semantics for choices represented as check
boxes: If None are checked, do not consider the corresponding
search parameter at all, making it equivalent to checking all of
them. Formerly it meant that none of the cases would match
because the value of the corresponding field in the database had
to be in the then emtpy set of checked values.
Implements the mpuls base part of mpuls/issue1047
* mpulsweb/lib/search.py (CaseSearch.convert_form_parameters): Do
not add 'state' and 'phase' to search_options if the corresponding
list in the form parameters was empty.
(CaseSearch.get_phases_dates_clause): Handle a missing 'phase'
option as if all options were specified. Update the doc-string.
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2010-09-28 15:38:22 UTC (rev 3810)
+++ base/trunk/ChangeLog 2010-09-28 17:01:59 UTC (rev 3811)
@@ -1,5 +1,22 @@
2010-09-28 Bernhard Herzog <bh at intevation.de>
+ Change the search semantics for choices represented as check
+ boxes: If None are checked, do not consider the corresponding
+ search parameter at all, making it equivalent to checking all of
+ them. Formerly it meant that none of the cases would match
+ because the value of the corresponding field in the database had
+ to be in the then emtpy set of checked values.
+
+ Implements the mpuls base part of mpuls/issue1047
+
+ * mpulsweb/lib/search.py (CaseSearch.convert_form_parameters): Do
+ not add 'state' and 'phase' to search_options if the corresponding
+ list in the form parameters was empty.
+ (CaseSearch.get_phases_dates_clause): Handle a missing 'phase'
+ option as if all options were specified. Update the doc-string.
+
+2010-09-28 Bernhard Herzog <bh at intevation.de>
+
Show errors and warnings in the same order as the widgets on the
page. Fixes mpuls/issue1106
Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py 2010-09-28 15:38:22 UTC (rev 3810)
+++ base/trunk/mpulsweb/lib/search.py 2010-09-28 17:01:59 UTC (rev 3811)
@@ -202,10 +202,12 @@
search_options["search_string"] = [options.get('search_str')]
# Status
- # we alwas match the state -1 for backwards compatibility
- search_options["state"] = [-1]
- if "state" in options:
- search_options["state"].extend(options["state"])
+ state = options.get("state")
+ if state:
+ # for backwards compatibility we always include -1, but only
+ # if the user actually wants to search based on the state,
+ # i.e. when at least one state value was given.
+ search_options["state"] = [-1] + list(state)
# Responsibilty
# shown cases where the user is editor, or standin or both
@@ -230,7 +232,8 @@
for pp in options["phase"]:
phases.extend((int(p) for p in pairs[0].get(str(pp),
[-1])))
- search_options["phase"] = phases
+ if phases:
+ search_options["phase"] = phases
# Dates
if (options.get("sdate") is not None
@@ -340,15 +343,20 @@
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.
+ The phases used for the return value are given as the value of
+ the 'phase' key of the options dictionary as a list of phase
+ ids. If the options dictionary does not contain the 'phase'
+ key, the value is considered to equivalent to a list containing
+ all possible phase ids.
+ The start and end dates are given as the values of the 'sdate'
+ and 'edate' keys of the options dictionary.
+
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.
+ 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.
Otherwise, the clause matches all cases that are currently in
one of the given phases.
@@ -358,14 +366,8 @@
maps to is empty, the claus will be equivalent to 'FALSE' and no
case will match.
- Derived classes may override this method if
- necessary.
+ Derived classes may override this method if necessary.
"""
- phases = options.get('phase')
- if phases is None:
- # no phase option -> all cases match
- return "TRUE"
-
sd = options.get('sdate')
ed = options.get('edate')
@@ -373,18 +375,22 @@
# no date range given -> match according to current phase
return self.generic_int_choice_clause(options, "phase", "m.phase")
+ phases = options.get('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.
+
+ # if phases is None, it means the phases parameter was
+ # omitted altogether and all phases should match.
+ if phases is None or int(sp.id) in phases or int(ep.id) in phases:
+ # a phase can 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 "
More information about the Mpuls-commits
mailing list