[Mpuls-commits] r1981 - wasko/branches/2.0/mpulsweb/controllers
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Mar 17 10:22:05 CET 2010
Author: torsten
Date: 2010-03-17 10:22:05 +0100 (Wed, 17 Mar 2010)
New Revision: 1981
Modified:
wasko/branches/2.0/mpulsweb/controllers/case_overview.py
Log:
* mpulsweb/controllers/case_overview.py: Did some codecleanup
Modified: wasko/branches/2.0/mpulsweb/controllers/case_overview.py
===================================================================
--- wasko/branches/2.0/mpulsweb/controllers/case_overview.py 2010-03-17 09:20:47 UTC (rev 1980)
+++ wasko/branches/2.0/mpulsweb/controllers/case_overview.py 2010-03-17 09:22:05 UTC (rev 1981)
@@ -4,6 +4,8 @@
import formencode
+from pylons import app_globals as g
+
from mpulsweb.lib.base import c, h, render, request, session, BaseController
from mpulsweb.lib.security import checkRole
from mpulsweb.lib.validators import SearchCaseForm
@@ -12,18 +14,21 @@
log = logging.getLogger(__name__)
+all_phases = [p for p in g.mpuls_config.get('phases', 'phases')]
+all_phases.append("-1")
+
FORM_DEFAULTS_ADMIN = {
- 'show_own': '1',
+ 'own': '1',
'search_str': '',
- 'show_open': '0',
- 'show_markdelete': '1',
- 'show_markanonymize': '1',
+ 'state': ['3', '4'],
+ 'phase': all_phases
}
FORM_DEFAULTS_CM = {
- 'show_own': '1',
+ 'own': '1',
'search_str': '',
- 'show_open': '1',
+ 'state': ['1'],
+ 'phase': all_phases
}
def get_sort(params):
@@ -50,6 +55,16 @@
@checkRole(('admin', 'cm', 'pt_dlr'))
def overview(self):
+
+ # Set default paramaters for casesearch depending on userrole
+ user = session['USER_AUTHORIZED']
+ if user.isAdmin():
+ FORM_DEFAULTS = FORM_DEFAULTS_ADMIN
+ else:
+ FORM_DEFAULTS = FORM_DEFAULTS_CM
+
+ # If reset parameter is set ti != 0 the delete all saved params and
+ # cases on overview page
reset = self._checkBool(request.params.get('reset', '0'))
if reset:
session['CASE_OVERVIEW_SEARCHOPTIONS'] = {}
@@ -57,31 +72,27 @@
session['EXTENDED_SEARCH'] = False
session.save()
- c.extended_search = session.get('EXTENDED_SEARCH', False)
- user = session['USER_AUTHORIZED']
-
- ulo = UserListObject()
- filter = [u.id for u in ulo.getAdminList()]
- c.userlist = ulo.getUserList(filter)
-
- # If the user is admin then he should see only cases which are
- # marked for deletion or anonymisation
- if user.isAdmin():
- FORM_DEFAULTS = FORM_DEFAULTS_ADMIN
- else:
- FORM_DEFAULTS = FORM_DEFAULTS_CM
-
form_defaults = (session.get('CASE_OVERVIEW_SEARCHOPTIONS')
or FORM_DEFAULTS)
+ session['CASE_OVERVIEW_SEARCHOPTIONS'] = form_defaults
+ session.save()
search_options = self.parseSearchOptions(form_defaults)
-
# Sorting of the cases
search_options.extend(self.parseSortOptions(request.params))
search_str = ";".join(search_options)
+
+ # Do search
c.cases = MpulsCaseOverview()
c.cases.search(search_str)
+ # Values used in the template
+ #
+ c.extended_search = session.get('EXTENDED_SEARCH', False)
+ ulo = UserListObject()
+ filter = [u.id for u in ulo.getAdminList()]
+ c.userlist = ulo.getUserList(filter)
+
#count num of cases
c.count_all = len([x for x in c.cases.getDatasets()])
c.count_own = len([x for x in c.cases.getDatasets()
@@ -112,15 +123,19 @@
overview = render('/casemanagement/overview.mako')
return formencode.htmlfill.render(unicode(overview, 'utf-8'),
defaults=form_defaults_copy)
+
@checkRole(('admin', 'cm', 'pt_dlr'))
def search(self):
+ log.debug(request.params)
validator = SearchCaseForm()
c.form_result = {}
c.form_errors = {}
try:
form_result = validator.to_python(request.params)
+ log.debug(form_result)
except formencode.Invalid, error:
+ log.exception(error)
form_result = error.value
form_errors = error.error_dict or {}
session['CASE_OVERVIEW_SEARCHOPTIONS'] = form_result
@@ -135,13 +150,34 @@
search_options.append('sort_order:%s' % sort_order)
return search_options
- #def parseSearchOptions(self, options=None):
- # search_options = []
- # log.debug(options)
- # # Status
- # if options.has_key('status'):
- # pass
- #
- # return search_options
+ def parseSearchOptions(self, options=None):
+ search_options = []
+ user = 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)
+
+ # Phase
+ if options.has_key('phase'):
+ for pp in options['phase']:
+ log.debug(pp)
+ # Get phasepart ids for the selected phasepairs.
+ for p in g.mpuls_config.get('phases', 'pairs')[0].get(str(pp), [-1]):
+ search_options.append('phase:%s' % p)
+
+ return search_options
+
# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
More information about the Mpuls-commits
mailing list