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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Aug 27 21:02:52 CEST 2010


Author: bh
Date: 2010-08-27 21:02:50 +0200 (Fri, 27 Aug 2010)
New Revision: 3474

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/search.py
Log:
* mpulsweb/lib/search.py (Search.MULTI_OPTIONS): New.  Lists all
search options that are actually lists and may be given multiple
times.
(Search._parse_search_str): Use MULTI_OPTIONS to handle list
options, instead of hard-wiring the names of those options.  The
values are now stored in the resulting optins dictionary under
different keys, though, namely the same key as the option in the
original search string, just like the other options.
(CaseSearch.get_phases_clause, CaseSearch.get_dates_clause)
(CaseSearch.get_status_clause): Adapt to new keys for the phase
and status search options.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-08-27 18:16:51 UTC (rev 3473)
+++ base/trunk/ChangeLog	2010-08-27 19:02:50 UTC (rev 3474)
@@ -1,5 +1,19 @@
 2010-08-27  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/lib/search.py (Search.MULTI_OPTIONS): New.  Lists all
+	search options that are actually lists and may be given multiple
+	times.
+	(Search._parse_search_str): Use MULTI_OPTIONS to handle list
+	options, instead of hard-wiring the names of those options.  The
+	values are now stored in the resulting optins dictionary under
+	different keys, though, namely the same key as the option in the
+	original search string, just like the other options.
+	(CaseSearch.get_phases_clause, CaseSearch.get_dates_clause)
+	(CaseSearch.get_status_clause): Adapt to new keys for the phase
+	and status search options.
+
+2010-08-27  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/controllers/case_overview.py
 	(CaseOverviewController.search): Call the case_search object's
 	validate_form_params method instead of the using SearchCaseForm

Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py	2010-08-27 18:16:51 UTC (rev 3473)
+++ base/trunk/mpulsweb/lib/search.py	2010-08-27 19:02:50 UTC (rev 3474)
@@ -21,6 +21,7 @@
 class Search(object):
 
     VALID_OPTIONS = ('state', 'phase')
+    MULTI_OPTIONS = ('state', 'phase')
 
     SEARCH_QUERY = """
     SELECT %(fields)s
@@ -49,8 +50,6 @@
         # TODO This is a very very simple approach. We should defentiley
         # implement some searchengine here
         search = []
-        allowed_states = [-1]
-        phases = []
         options = {}
 
         if s:
@@ -61,10 +60,8 @@
                     try:
                         key, value = [x.strip() for x in option.split(":")]
                         if key in self.VALID_OPTIONS:
-                            if key == 'state':
-                                allowed_states.append(int(value))
-                            if key == 'phase':
-                                phases.append(int(value))
+                            if key in self.MULTI_OPTIONS:
+                                options.setdefault(key, []).append(int(value))
                             else:
                                 options[key] = value
                     except ValueError, err:
@@ -72,8 +69,6 @@
                               "Found invalid search syntax in options: %s" % err
                 else:
                     search.append(option)
-        options["phases"] = phases
-        options["states"] = allowed_states
         return search, options
 
     def _build_sql(self, search, options):
@@ -237,9 +232,9 @@
 
         Derived classes may override this method if necessary.
         """
-        if options["phases"]:
+        if options["phase"]:
             return ('m.phase IN (%s)'
-                    % ','.join([str(p) for p in options["phases"]]))
+                    % ','.join([str(p) for p in options["phase"]]))
         return "FALSE"
 
     def get_needle_clause(self, search, options):
@@ -275,7 +270,7 @@
                     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["phases"]:
+            if -1 in options["phase"]:
                 time_interval_str.append("(m.phase = -1)")
             time_interval = "(%s)" % "OR".join(time_interval_str)
         return time_interval
@@ -285,7 +280,7 @@
         Derived classes may override this method if necessary.
         """
         return ("st.status IN (%s)"
-                % ",".join([str(x) for x in options["states"]]))
+                % ",".join([str(x) for x in options["state"]]))
 
     def get_gender_clause(self, search, options):
         """Return the search condition to select cases based on gender.



More information about the Mpuls-commits mailing list