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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 31 20:37:14 CEST 2010


Author: bh
Date: 2010-08-31 20:37:13 +0200 (Tue, 31 Aug 2010)
New Revision: 3497

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/search.py
Log:
* mpulsweb/lib/search.py (CaseSearch.generic_int_choice_clause):
New.  More generic way to handle a common case of search SQL
subclause
(CaseSearch.get_status_clause): Use generic_int_choice_clause
instead of having the equivalent code inline.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-08-31 18:05:21 UTC (rev 3496)
+++ base/trunk/ChangeLog	2010-08-31 18:37:13 UTC (rev 3497)
@@ -1,5 +1,13 @@
 2010-08-31  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/lib/search.py (CaseSearch.generic_int_choice_clause):
+	New.  More generic way to handle a common case of search SQL
+	subclause
+	(CaseSearch.get_status_clause): Use generic_int_choice_clause
+	instead of having the equivalent code inline.
+
+2010-08-31  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/lib/search.py (CaseSearch.convert_form_parameters):
 	Always include -1 in the state values.  This behavior was
 	accidentally removed in an earlier commit.

Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py	2010-08-31 18:05:21 UTC (rev 3496)
+++ base/trunk/mpulsweb/lib/search.py	2010-08-31 18:37:13 UTC (rev 3497)
@@ -243,6 +243,31 @@
 
         return search_options
 
+    def generic_int_choice_clause(self, options, key, column):
+        """Return a search condition for an option with multiple int values.
+
+        The allowed values are the values in the list of ints stored in
+        the options dictionary under key.  There are three cases to
+        consider:
+
+          1. options does not contain key at all.  This means the value
+             doesn't matter and thus the method returns 'TRUE'.
+
+          2. the values list is empty.  This means no value matches and
+             no case will match.  The method returns 'FALSE'
+
+          3. The value is a list.  In this case the method returns a
+             condition that selects cases where the column given by the
+             string column has one of the values in the list.
+        """
+        if key in options:
+            values = options[key]
+            if values:
+                return ('%s IN (%s)'
+                        % (column, ','.join([str(v) for v in values])))
+            return "FALSE"
+        return "TRUE"
+
     def get_allowed_viewer_clause(self, options):
         """Return the search condition that selects based on owner or standin.
         This means the search condition a case manager user can use to
@@ -346,8 +371,7 @@
         """Return the search condition to select cases based on status.
         Derived classes may override this method if necessary.
         """
-        return ("st.status IN (%s)"
-                % ",".join([str(x) for x in options["state"]]))
+        return self.generic_int_choice_clause(options, "state", "st.status")
 
     def get_gender_clause(self, options):
         """Return the search condition to select cases based on gender.



More information about the Mpuls-commits mailing list