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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Aug 30 15:46:35 CEST 2010


Author: bh
Date: 2010-08-30 15:46:32 +0200 (Mon, 30 Aug 2010)
New Revision: 3482

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/search.py
Log:
Unify the way search options and the search string are handled
within the search classes.  This is an incompatible change and
requires updates to the MPuls applications that override or extend
any of the affected methods.

* mpulsweb/lib/search.py (Search._parse_search_str): Return the
strings to search for in the options dictionary.  The return value
is now simply the options dictionary.
(Search._build_sql, Search.perform): Adapt to _parse_search_str
changes.  Only pass the options dictionary to _build_sql.  There's
no separate argument for the search strings anymore.
(CaseSearch.get_allowed_viewer_clause)
(CaseSearch.get_editor_clause, CaseSearch.get_branch_clause)
(CaseSearch.get_phases_clause, CaseSearch.get_dates_clause)
(CaseSearch.get_status_clause, CaseSearch.get_gender_clause):
Remove the search parameter.  It's not needed anymore.
(CaseSearch.get_where_subclauses): Remove the search parameter.
It's not needed anymore.  Adapt the get_*_claus calls.
(CaseSearch.get_needle_clause): Remove the search parameter.  It's
not needed anymore.  Take he search strings from the options
dictionary.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-08-30 13:45:31 UTC (rev 3481)
+++ base/trunk/ChangeLog	2010-08-30 13:46:32 UTC (rev 3482)
@@ -1,3 +1,27 @@
+2010-08-30  Bernhard Herzog  <bh at intevation.de>
+
+	Unify the way search options and the search string are handled
+	within the search classes.  This is an incompatible change and
+	requires updates to the MPuls applications that override or extend
+	any of the affected methods.
+
+	* mpulsweb/lib/search.py (Search._parse_search_str): Return the
+	strings to search for in the options dictionary.  The return value
+	is now simply the options dictionary.
+	(Search._build_sql, Search.perform): Adapt to _parse_search_str
+	changes.  Only pass the options dictionary to _build_sql.  There's
+	no separate argument for the search strings anymore.
+	(CaseSearch.get_allowed_viewer_clause)
+	(CaseSearch.get_editor_clause, CaseSearch.get_branch_clause)
+	(CaseSearch.get_phases_clause, CaseSearch.get_dates_clause)
+	(CaseSearch.get_status_clause, CaseSearch.get_gender_clause):
+	Remove the search parameter.  It's not needed anymore.
+	(CaseSearch.get_where_subclauses): Remove the search parameter.
+	It's not needed anymore.  Adapt the get_*_claus calls.
+	(CaseSearch.get_needle_clause): Remove the search parameter.  It's
+	not needed anymore.  Take he search strings from the options
+	dictionary.
+
 2010-08-30  Roland Geider <roland.geider at intevation.de>
 
 	* mpulsweb/i18n/de/LC_MESSAGES/mpulsweb.po:

Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py	2010-08-30 13:45:31 UTC (rev 3481)
+++ base/trunk/mpulsweb/lib/search.py	2010-08-30 13:46:32 UTC (rev 3482)
@@ -69,9 +69,10 @@
                               "Found invalid search syntax in options: %s" % err
                 else:
                     search.append(option)
-        return search, options
+        options["search_string"] = search
+        return options
 
-    def _build_sql(self, search, options):
+    def _build_sql(self, options):
         pass
 
     def queryDB(self, sql):
@@ -90,8 +91,7 @@
 
     def perform(self, search_str):
         '''Returns the result set of a search based on the search string'''
-        search, options = self._parse_search_str(search_str)
-        return self.queryDB(self._build_sql(search, options))
+        return self.queryDB(self._build_sql(self._parse_search_str(search_str)))
 
 
 class CaseSearch(Search):
@@ -178,7 +178,7 @@
 
         return search_options
 
-    def get_allowed_viewer_clause(self, search, options):
+    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
         limit the search to cases that the user can see or modify due to
@@ -206,7 +206,7 @@
             allowed_viewer = "TRUE"
         return allowed_viewer
 
-    def get_editor_clause(self, search, options):
+    def get_editor_clause(self, options):
         """Return the search condition to select cases with a specific owner.
         This is the condition an admin user can use to limit the search
         to cases of a specific case manager.
@@ -217,7 +217,7 @@
             return "m.bearbeiter_id = %s" % options['editor']
         return "TRUE"
 
-    def get_branch_clause(self, search, options):
+    def get_branch_clause(self, options):
         """Return the search condition to select cases based on branch office.
         Derived classes may override this method if necessary.
         """
@@ -226,7 +226,7 @@
             return "b.filiale = '%s'" % branch
         return "TRUE"
 
-    def get_phases_clause(self, search, options):
+    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.
@@ -238,10 +238,11 @@
                     % ','.join([str(p) for p in options["phase"]]))
         return "FALSE"
 
-    def get_needle_clause(self, search, options):
+    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:
             needle_expr = ("((%s) OR (%s))"
                            % (" OR ".join("m.%s ~* '%%(needle)s'"
@@ -253,7 +254,7 @@
             return needle_expr % dict(needle=" ".join(search))
         return "TRUE"
 
-    def get_dates_clause(self, search, options):
+    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.
         """
@@ -276,14 +277,14 @@
             time_interval = "(%s)" % "OR".join(time_interval_str)
         return time_interval
 
-    def get_status_clause(self, search, options):
+    def get_status_clause(self, options):
         """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"]]))
 
-    def get_gender_clause(self, search, options):
+    def get_gender_clause(self, options):
         """Return the search condition to select cases based on gender.
         The default implementation simply returns 'TRUE'.
 
@@ -292,7 +293,7 @@
         """
         return "TRUE"
 
-    def get_where_subclauses(self, search, options):
+    def get_where_subclauses(self, options):
         """Return a list with the 'where' sub-clauses as strings.
         This base method calls the get_*_clause methods to gather the
         commonly used subclauses.  Derived classes should extend this
@@ -300,32 +301,32 @@
         clauses.
         """
         return [
-            self.get_needle_clause(search, options),
-            self.get_status_clause(search, options),
-            self.get_allowed_viewer_clause(search, options),
-            self.get_editor_clause(search, options),
-            self.get_branch_clause(search, options),
-            self.get_dates_clause(search, options),
-            self.get_phases_clause(search, options),
-            self.get_gender_clause(search, options),
+            self.get_needle_clause(options),
+            self.get_status_clause(options),
+            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_gender_clause(options),
             ]
 
-    def get_where(self, search, options):
+    def get_where(self, options):
         """Return the 'where' clause for the search.
         The clause contains all clauses returned by self.get_where_subclauses
         combined by AND.
         """
-        return " AND ".join(self.get_where_subclauses(search, options))
+        return " AND ".join(self.get_where_subclauses(options))
 
     def get_order(self, options):
         sort_field = options.get('sort_field', "m.id")
         sort_order = options.get('sort_order', "desc")
         return self.SEARCH_ORDER % (sort_field, sort_order)
 
-    def _build_sql(self, search, options):
+    def _build_sql(self, options):
         sql_fields = {}
         sql_fields['fields'] = self.get_fields(options)
-        sql_fields['where'] = self.get_where(search, options)
+        sql_fields['where'] = self.get_where(options)
         sql_fields['order'] = self.get_order(options)
 
         SQL = self.SEARCH_QUERY % sql_fields



More information about the Mpuls-commits mailing list