[Mpuls-commits] r3401 - in base/trunk: . mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Aug 13 17:06:30 CEST 2010
Author: bh
Date: 2010-08-13 17:06:28 +0200 (Fri, 13 Aug 2010)
New Revision: 3401
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/lib/search.py
Log:
* mpulsweb/lib/search.py (CaseSearch.get_where): Change default
implementation to be exactly what's used in all derived
applications (with the exception of jmdstrukturweb).
(SEARCH_WHERE): Copied from the derived applications as well for
the get_where method
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2010-08-13 14:23:29 UTC (rev 3400)
+++ base/trunk/ChangeLog 2010-08-13 15:06:28 UTC (rev 3401)
@@ -1,5 +1,13 @@
2010-08-13 Bernhard Herzog <bh at intevation.de>
+ * mpulsweb/lib/search.py (CaseSearch.get_where): Change default
+ implementation to be exactly what's used in all derived
+ applications (with the exception of jmdstrukturweb).
+ (SEARCH_WHERE): Copied from the derived applications as well for
+ the get_where method
+
+2010-08-13 Bernhard Herzog <bh at intevation.de>
+
* mpulsweb/lib/session.py (MPulsSession.__delitem__): Remove
superfluous third parameter.
Fixes mpuls/issue971
Modified: base/trunk/mpulsweb/lib/search.py
===================================================================
--- base/trunk/mpulsweb/lib/search.py 2010-08-13 14:23:29 UTC (rev 3400)
+++ base/trunk/mpulsweb/lib/search.py 2010-08-13 15:06:28 UTC (rev 3401)
@@ -6,7 +6,9 @@
import psycopg2.extras
from mpulsweb.lib.db import db
+from mpulsweb.lib.security import hasRole
+
SAVE_SEARCH = re.compile(r'[^\w:;\-\. ]', re.UNICODE)
VALID_OPTIONS = ['editor', 'migration', 'own', 'standin', 'state',
'sort_field', 'sort_order', 'interval_start_date',
@@ -27,7 +29,16 @@
SEARCH_FIELDS = """m.id, m.phase, %s st.status, st.zugriff, st.id as s_id,
ARRAY(SELECT tag_id FROM nm_tags_cases_view WHERE case_id = m.id) AS tags """
SEARCH_ORDER = """ORDER BY %s %s"""
+SEARCH_WHERE = """
+ %s
+ AND st.status IN (%s)
+ AND %s
+ AND %s
+ AND %s
+ AND %s
+"""
+
log = logging.getLogger(__name__)
@@ -108,10 +119,70 @@
retrieve = "%s," % retrieve
return SEARCH_FIELDS % retrieve
- def get_where(self, search, options, allowed_states, bad_types,
- phaseslist, fieldsdic):
- return "TRUE"
+ def get_where(self, search, options, allowed_states, bad_types, phaseslist,
+ fieldsdic):
+ # Ansicht eigene Fallakten / Vertretung
+ which_user = 0
+ allowed_viewer = "FALSE"
+ if options.has_key('own'):
+ which_user += 2
+ if options.has_key('standin'):
+ which_user += 1
+ if which_user == 1:
+ allowed_viewer = "m.bearbeiter_id <> %s" % options.get('standin')
+ if which_user == 2:
+ allowed_viewer = "m.bearbeiter_id = %s" % options.get('own')
+ if which_user == 3:
+ allowed_viewer = "TRUE"
+ allowed_viewer = (hasRole(['admin_ka', 'pb_ka'])
+ and "TRUE" or allowed_viewer)
+ # Bearbeiter
+ editor = (options.has_key('editor')
+ and "m.bearbeiter_id = %s" % options.get('editor') or "TRUE")
+ #Phases
+ 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]))
+
+ fields = {'needle': ""}
+ fields['needle'] = " ".join(search)
+ needle_expr = ("((%s) OR (%s))"
+ % (" OR ".join("m.%s ~* '%%(needle)s'"
+ % field
+ for field in self.match_fields),
+ " AND ".join("m.%s IS NULL"
+ % field
+ for field in self.match_fields)))
+
+ #Dates
+ time_interval = "TRUE"
+ if (options.get('sdate') and options.get('edate')):
+ sd = options.get('sdate')
+ ed = options.get('edate')
+ time_interval_str = []
+ phasepairs = PhaseFactory().build()
+ for p in phasepairs:
+ sp = p.getStart()
+ ep = p.getEnd()
+ time_interval_str.append('''
+ (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)
+
+ needle_expr = needle_expr % fields
+
+ return SEARCH_WHERE % (needle_expr,
+ ",".join([str(x) for x in allowed_states]),
+ allowed_viewer, editor,
+ time_interval, phases)
+
def get_order(self, options):
sort_field = options.get('sort_field', "m.id")
sort_order = options.get('sort_order', "desc")
More information about the Mpuls-commits
mailing list