[Mpuls-commits] r3407 - in base/trunk: . mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Aug 13 19:42:50 CEST 2010
Author: bh
Date: 2010-08-13 19:42:49 +0200 (Fri, 13 Aug 2010)
New Revision: 3407
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/lib/search.py
Log:
* mpulsweb/lib/search.py (CaseSearch.get_where): Split into the
following methods:
(CaseSearch.get_allowed_viewer_clause)
(CaseSearch.get_editor_clause, CaseSearch.get_phases_clause)
(CaseSearch.get_needle_clause, CaseSearch.get_dates_clause): New
methods for the various parts of get_where
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2010-08-13 16:03:37 UTC (rev 3406)
+++ base/trunk/ChangeLog 2010-08-13 17:42:49 UTC (rev 3407)
@@ -1,5 +1,14 @@
2010-08-13 Bernhard Herzog <bh at intevation.de>
+ * mpulsweb/lib/search.py (CaseSearch.get_where): Split into the
+ following methods:
+ (CaseSearch.get_allowed_viewer_clause)
+ (CaseSearch.get_editor_clause, CaseSearch.get_phases_clause)
+ (CaseSearch.get_needle_clause, CaseSearch.get_dates_clause): New
+ methods for the various parts of get_where
+
+2010-08-13 Bernhard Herzog <bh at intevation.de>
+
* mpulsweb/lib/search.py: Add missing import
2010-08-13 Bernhard Herzog <bh at intevation.de>
Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py 2010-08-13 16:03:37 UTC (rev 3406)
+++ base/trunk/mpulsweb/lib/search.py 2010-08-13 17:42:49 UTC (rev 3407)
@@ -120,9 +120,17 @@
retrieve = "%s," % retrieve
return SEARCH_FIELDS % retrieve
- def get_where(self, search, options, allowed_states, bad_types, phaseslist,
- fieldsdic):
- # Ansicht eigene Fallakten / Vertretung
+ 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
+ the user being the cases's owner or a standin.
+
+ If the current user is an admin this method should return
+ 'TRUE'.
+
+ Derived classes may override this method if necessary.
+ """
which_user = 0
allowed_viewer = "FALSE"
if options.has_key('own'):
@@ -137,17 +145,37 @@
allowed_viewer = "TRUE"
allowed_viewer = (hasRole(['admin_ka', 'pb_ka'])
and "TRUE" or allowed_viewer)
- # Bearbeiter
+ return allowed_viewer
+
+ 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.
+
+ Derived classes may override this method if necessary.
+ """
editor = (options.has_key('editor')
and "m.bearbeiter_id = %s" % options.get('editor') or "TRUE")
+ return editor
- #Phases
+ def get_phases_clause(self, options, phaseslist):
+ """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.
+ """
phases = 'FALSE' #default
if phaseslist:
phases = ('m.id in'
' (SELECT id from master_tbl_view WHERE phase IN (%s))'
% ','.join([str(p) for p in phaseslist]))
+ return phases
+ def get_needle_clause(self, options, search):
+ """Return the search condition to select cases based on search terms.
+ Derived classes may override this method if necessary.
+ """
fields = {'needle': ""}
fields['needle'] = " ".join(search)
needle_expr = ("((%s) OR (%s))"
@@ -157,8 +185,13 @@
" AND ".join("m.%s IS NULL"
% field
for field in self.match_fields)))
+ needle_expr = needle_expr % fields
+ return needle_expr
- #Dates
+ def get_dates_clause(self, options, phaseslist):
+ """Return the search condition to select cases based on start/end dates.
+ Derived classes may override this method if necessary.
+ """
time_interval = "TRUE"
if (options.get('sdate') and options.get('edate')):
sd = options.get('sdate')
@@ -169,15 +202,22 @@
sp = p.getStart()
ep = p.getEnd()
time_interval_str.append('''
- (m.phase IN (%s, %s)
+ (m.phase IN (%s, %s)
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:
time_interval_str.append("(m.phase = -1)")
time_interval = "(%s)" % "OR".join(time_interval_str)
+ return time_interval
- needle_expr = needle_expr % fields
+ 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)
return SEARCH_WHERE % (needle_expr,
",".join([str(x) for x in allowed_states]),
More information about the Mpuls-commits
mailing list