[Mpuls-commits] r4458 - base/trunk/mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Dec 29 12:51:39 CET 2010


Author: torsten
Date: 2010-12-29 12:51:38 +0100 (Wed, 29 Dec 2010)
New Revision: 4458

Modified:
   base/trunk/mpulsweb/lib/search.py
Log:
* mpulsweb/lib/search.py (EvaluationSearch.get_needle_clause): Added specfic function for agency search.


Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py	2010-12-29 11:48:05 UTC (rev 4457)
+++ base/trunk/mpulsweb/lib/search.py	2010-12-29 11:51:38 UTC (rev 4458)
@@ -464,7 +464,6 @@
         retrieve = ", ".join("m." + field for field in self.retrieve_fields)
         if retrieve:
             retrieve = "%s," % retrieve
-        print retrieve
         return self.SEARCH_FIELDS % retrieve
 
 
@@ -503,6 +502,23 @@
         self.retrieve_fields = retrieve_fields
         self.match_fields = match_fields
 
+    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.
+        """
+        search = options.get("search_string", ())
+        if search and self.match_fields:
+            needle_expr = ("((%s) OR (%s))"
+                           % (" OR ".join("f.%s ~* '%%(needle)s'"
+                                          % field
+                                          for field in self.match_fields),
+                              " AND ".join("f.%s IS NULL"
+                                           % field
+                                           for field in self.match_fields)))
+            return needle_expr % dict(needle=" ".join(search))
+        return "TRUE"
+
+
     def get_fields(self, options):
         return self.SEARCH_FIELDS
 



More information about the Mpuls-commits mailing list