[Mpuls-commits] r3466 - in base/trunk: . mpulsweb/controllers mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Aug 27 16:42:26 CEST 2010
Author: bh
Date: 2010-08-27 16:42:22 +0200 (Fri, 27 Aug 2010)
New Revision: 3466
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/controllers/case_overview.py
base/trunk/mpulsweb/lib/search.py
Log:
* mpulsweb/controllers/case_overview.py (parseSearchOptions): Now
reduced to calling the convert_form_parameters of the
application's case_search object.
* mpulsweb/lib/search.py (Search.convert_form_parameters): New.
Only very slightly modified copy of parseSearchOptions in
controllers/case_overview.py. Now it can easily be extended by
applications.
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2010-08-27 11:01:05 UTC (rev 3465)
+++ base/trunk/ChangeLog 2010-08-27 14:42:22 UTC (rev 3466)
@@ -1,5 +1,16 @@
2010-08-27 Bernhard Herzog <bh at intevation.de>
+ * mpulsweb/lib/search.py (Search.convert_form_parameters): New.
+ Only very slightly modified copy of parseSearchOptions in
+ controllers/case_overview.py. Now it can easily be extended by
+ applications.
+
+ * mpulsweb/controllers/case_overview.py (parseSearchOptions): Now
+ reduced to calling the convert_form_parameters of the
+ application's case_search object.
+
+2010-08-27 Bernhard Herzog <bh at intevation.de>
+
* mpulsweb/lib/search.py (CaseSearch.get_where_subclauses)
(CaseSearch.get_where): Move the code that gathers all the
sub-clauses into the separate method get_where_subclauses that
Modified: base/trunk/mpulsweb/controllers/case_overview.py
===================================================================
--- base/trunk/mpulsweb/controllers/case_overview.py 2010-08-27 11:01:05 UTC (rev 3465)
+++ base/trunk/mpulsweb/controllers/case_overview.py 2010-08-27 14:42:22 UTC (rev 3466)
@@ -45,59 +45,10 @@
return phases
def parseSearchOptions(options):
- search_options = []
- user = session['USER_AUTHORIZED']
+ return g.case_search.convert_form_parameters(options,
+ session['USER_AUTHORIZED'])
- # Searchstring
- if options.get('search_str'):
- search_options.append(options.get('search_str'))
- # Status
- if options.has_key('state'):
- for s in options['state']:
- search_options.append('state:%s' % s)
-
- # Responsibilty
- # shown cases where the user is editor, or standin or both
- if options.get('own'):
- search_options.append('own:%s' % user.id)
- if options.get('standin'):
- search_options.append('standin:%s' % user.id)
-
- # Editor
- # shown cases where the user is editor or all (-1)
- if options.get('editor') and options.get('editor') != -1:
- search_options.append('editor:%s' % options.get('editor'))
-
- # Phase
- if options.has_key('phase'):
- for pp in options['phase']:
- # Get phasepart ids for the selected phasepairs. Only if pairs are
- # defined.
- pairs = g.mpuls_config.get('phases', 'pairs')
- if len(pairs) <= 0:
- continue
- for p in pairs[0].get(str(pp), [-1]):
- search_options.append('phase:%s' % p)
- # Dates
- if (options.has_key('sdate')
- and options.has_key('edate')
- and options.get('sdate') is not None
- and options.get('edate') is not None):
- search_options.append('sdate:%s' % options.get('sdate'))
- search_options.append('edate:%s' % options.get('edate'))
-
- # gender
- if options.get("gender", -2) != -2:
- search_options.append("gender:%s" % options["gender"])
-
- # branch office
- if options.get("branch"):
- search_options.append("branch:%s" % options["branch"])
-
- return search_options
-
-
class CaseOverviewController(BaseController):
@checkRole(('admin', 'cm', 'pt_dlr'))
Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py 2010-08-27 11:01:05 UTC (rev 3465)
+++ base/trunk/mpulsweb/lib/search.py 2010-08-27 14:42:22 UTC (rev 3466)
@@ -5,6 +5,8 @@
import psycopg2.extras
+from pylons import app_globals as g
+
from mpulsweb.lib.db import db
from mpulsweb.lib.security import hasRole
from mpulsweb.model.phase import PhaseFactory
@@ -43,6 +45,62 @@
def supports_option(self, option):
return option in self.VALID_OPTIONS
+ def convert_form_parameters(self, options, user):
+ """Convert form parameters to search options.
+ The parameter user is the user object for the current user.
+ """
+ search_options = []
+
+ # Searchstring
+ if options.get('search_str'):
+ search_options.append(options.get('search_str'))
+
+ # Status
+ if options.has_key('state'):
+ for s in options['state']:
+ search_options.append('state:%s' % s)
+
+ # Responsibilty
+ # shown cases where the user is editor, or standin or both
+ if options.get('own'):
+ search_options.append('own:%s' % user.id)
+ if options.get('standin'):
+ search_options.append('standin:%s' % user.id)
+
+ # Editor
+ # shown cases where the user is editor or all (-1)
+ if options.get('editor') and options.get('editor') != -1:
+ search_options.append('editor:%s' % options.get('editor'))
+
+ # Phase
+ if options.has_key('phase'):
+ for pp in options['phase']:
+ # Get phasepart ids for the selected phasepairs. Only if
+ # pairs are defined.
+ pairs = g.mpuls_config.get('phases', 'pairs')
+ if len(pairs) <= 0:
+ continue
+ for p in pairs[0].get(str(pp), [-1]):
+ search_options.append('phase:%s' % p)
+ # Dates
+ if (options.has_key('sdate')
+ and options.has_key('edate')
+ and options.get('sdate') is not None
+ and options.get('edate') is not None):
+ search_options.append('sdate:%s' % options.get('sdate'))
+ search_options.append('edate:%s' % options.get('edate'))
+
+ # gender
+ if options.get("gender", -2) != -2:
+ search_options.append("gender:%s" % options["gender"])
+
+ # branch office
+ if options.get("branch"):
+ search_options.append("branch:%s" % options["branch"])
+
+ return search_options
+
+
def _parse_search_str(self, s):
# TODO This is a very very simple approach. We should defentiley
# implement some searchengine here
More information about the Mpuls-commits
mailing list