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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 17 19:53:15 CEST 2010


Author: bh
Date: 2010-08-17 19:53:12 +0200 (Tue, 17 Aug 2010)
New Revision: 3427

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/search.py
Log:
* mpulsweb/lib/search.py (Search._parse_search_str): Remove
bad_types and fields from return value.  They are always emtpy.
Put allowed_states and phases into the options dict and do not
return them separately either.  The return value has now been
reduced to the search strings and the options dict.
(CaseSearch.get_allowed_viewer_clause)
(CaseSearch.get_editor_clause, CaseSearch.get_phases_clause)
(CaseSearch.get_needle_clause, CaseSearch.get_dates_clause)
(CaseSearch.get_status_clause): Always take search and options as
parameters.  Now all of these methods have the same interface.
(Search._build_sql, CaseSearch.get_where, CaseSearch._build_sql):
Adapt to the interface changes of the other methods


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-08-17 17:15:40 UTC (rev 3426)
+++ base/trunk/ChangeLog	2010-08-17 17:53:12 UTC (rev 3427)
@@ -1,5 +1,20 @@
 2010-08-17  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/lib/search.py (Search._parse_search_str): Remove
+	bad_types and fields from return value.  They are always emtpy.
+	Put allowed_states and phases into the options dict and do not
+	return them separately either.  The return value has now been
+	reduced to the search strings and the options dict.
+	(CaseSearch.get_allowed_viewer_clause)
+	(CaseSearch.get_editor_clause, CaseSearch.get_phases_clause)
+	(CaseSearch.get_needle_clause, CaseSearch.get_dates_clause)
+	(CaseSearch.get_status_clause): Always take search and options as
+	parameters.  Now all of these methods have the same interface.
+	(Search._build_sql, CaseSearch.get_where, CaseSearch._build_sql):
+	Adapt to the interface changes of the other methods
+
+2010-08-17  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/model/phase.py (PhasePart.__init__): Log a warning if a
 	phase does not have an associated date field.  The missing date
 	field name will likely interfere with date-range searches.

Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py	2010-08-17 17:15:40 UTC (rev 3426)
+++ base/trunk/mpulsweb/lib/search.py	2010-08-17 17:53:12 UTC (rev 3427)
@@ -45,9 +45,7 @@
         # implement some searchengine here
         search = []
         allowed_states = [-1]
-        bad_types = []
         phases = []
-        fields = {}
         options = {}
 
         if s:
@@ -69,10 +67,11 @@
                               "Found invalid search syntax in options: %s" % err
                 else:
                     search.append(option)
-        return search, options, allowed_states, bad_types, phases, fields
+        options["phases"] = phases
+        options["states"] = allowed_states
+        return search, options
 
-    def _build_sql(self, search, options, allowed_states, bad_types, phases,
-                   fieldsdic):
+    def _build_sql(self, search, options):
         pass
 
     def queryDB(self, sql):
@@ -91,12 +90,8 @@
 
     def perform(self, search_str):
         '''Returns the result set of a search based on the search string'''
-        search, options, states, bad_types, phases, fields = \
-                self._parse_search_str(search_str)
-        sql = self._build_sql(search, options, states, bad_types, phases,
-                              fields)
-        result = self.queryDB(sql)
-        return result
+        search, options = self._parse_search_str(search_str)
+        return self.queryDB(self._build_sql(search, options))
 
 
 class CaseSearch(Search):
@@ -112,7 +107,7 @@
             retrieve = "%s," % retrieve
         return SEARCH_FIELDS % retrieve
 
-    def get_allowed_viewer_clause(self, options):
+    def get_allowed_viewer_clause(self, search, 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
@@ -140,7 +135,7 @@
             allowed_viewer = "TRUE"
         return allowed_viewer
 
-    def get_editor_clause(self, options):
+    def get_editor_clause(self, search, 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.
@@ -151,18 +146,19 @@
             return "m.bearbeiter_id = %s" % options['editor']
         return "TRUE"
 
-    def get_phases_clause(self, options, phaseslist):
+    def get_phases_clause(self, search, 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.
 
         Derived classes may override this method if necessary.
         """
-        if phaseslist:
-            return 'm.phase IN (%s)' % ','.join([str(p) for p in phaseslist])
+        if options["phases"]:
+            return ('m.phase IN (%s)'
+                    % ','.join([str(p) for p in options["phases"]]))
         return "FALSE"
 
-    def get_needle_clause(self, options, search):
+    def get_needle_clause(self, search, options):
         """Return the search condition to select cases based on search terms.
         Derived classes may override this method if necessary.
         """
@@ -177,7 +173,7 @@
             return needle_expr % dict(needle=" ".join(search))
         return "TRUE"
 
-    def get_dates_clause(self, options, phaseslist):
+    def get_dates_clause(self, search, options):
         """Return the search condition to select cases based on start/end dates.
         Derived classes may override this method if necessary.
         """
@@ -195,25 +191,25 @@
                     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 phaseslist:
+            if -1 in options["phases"]:
                 time_interval_str.append("(m.phase = -1)")
             time_interval = "(%s)" % "OR".join(time_interval_str)
         return time_interval
 
-    def get_status_clause(self, options, allowed_states):
+    def get_status_clause(self, search, 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 allowed_states])
+        return ("st.status IN (%s)"
+                % ",".join([str(x) for x in options["states"]]))
 
-    def get_where(self, search, options, allowed_states, bad_types, phaseslist,
-                  fieldsdic):
-        allowed_viewer = self.get_allowed_viewer_clause(options)
-        editor = self.get_editor_clause(options)
-        phases = self.get_phases_clause(options, phaseslist)
-        needle_expr = self.get_needle_clause(options, search)
-        time_interval = self.get_dates_clause(options, phaseslist)
-        status_expr = self.get_status_clause(options, allowed_states)
+    def get_where(self, search, options):
+        allowed_viewer = self.get_allowed_viewer_clause(search, options)
+        editor = self.get_editor_clause(search, options)
+        phases = self.get_phases_clause(search, options)
+        needle_expr = self.get_needle_clause(search, options)
+        time_interval = self.get_dates_clause(search, options)
+        status_expr = self.get_status_clause(search, options)
 
         return " AND ".join((needle_expr, status_expr, allowed_viewer, editor,
                              time_interval, phases))
@@ -223,12 +219,10 @@
         sort_order = options.get('sort_order', "desc")
         return SEARCH_ORDER % (sort_field, sort_order)
 
-    def _build_sql(self, search, options, allowed_states, bad_types, phaseslist,
-                   fieldsdic):
+    def _build_sql(self, search, options):
         sql_fields = {}
         sql_fields['fields'] = self.get_fields(options)
-        sql_fields['where'] = self.get_where(search, options, allowed_states,
-                                             bad_types, phaseslist, fieldsdic)
+        sql_fields['where'] = self.get_where(search, options)
         sql_fields['order'] = self.get_order(options)
 
         SQL = SEARCH_QUERY % sql_fields



More information about the Mpuls-commits mailing list