[Mpuls-commits] r1971 - wasko/branches/2.0/mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 16 12:46:00 CET 2010


Author: torsten
Date: 2010-03-16 12:46:00 +0100 (Tue, 16 Mar 2010)
New Revision: 1971

Modified:
   wasko/branches/2.0/mpulsweb/controllers/case_overview.py
Log:
* mpulsweb/controllers/case_overview.py (CaseOverviewController.overview): 
  Moved function into mpulsbase.


Modified: wasko/branches/2.0/mpulsweb/controllers/case_overview.py
===================================================================
--- wasko/branches/2.0/mpulsweb/controllers/case_overview.py	2010-03-16 11:42:44 UTC (rev 1970)
+++ wasko/branches/2.0/mpulsweb/controllers/case_overview.py	2010-03-16 11:46:00 UTC (rev 1971)
@@ -1,11 +1,110 @@
 # -*- coding: utf-8 -*-
+import re
 import logging
 
+import formencode
+
 from mpulsweb.lib.base import c, h, render, request, session, BaseController
 from mpulsweb.lib.security import checkRole
+from mpulsweb.model.user import UserListObject
+from mpulsweb.model.case import MpulsCaseOverview
 
 log = logging.getLogger(__name__)
 
+FORM_DEFAULTS_ADMIN = {
+    'show_own': '1',
+    'search_str': '',
+    'show_open': '0',
+    'show_markdelete': '1',
+    'show_markanonymize': '1',
+    }
+
+FORM_DEFAULTS_CM = {
+    'show_own': '1',
+    'search_str': '',
+    'show_open': '1',
+    }
+
+def get_sort(params):
+    sort = params.get('sort_field', 'id')
+    order = params.get('sort_order', 'asc')
+    return sort, order
+
+def parseSearchOptions(options=None):
+    search_options = []
+    user = session['USER_AUTHORIZED']
+    if options.get('editor', '-1') != '-1':
+        search_options.append('editor:%s' % options.get('editor'))
+    if options.get('show_own') == '1':
+        search_options.append('own:%s' % user.id)
+    if options.get('show_other') == '1':
+        search_options.append('standin:%s' % user.id)
+    if options.get('show_open') == '1':
+        search_options.append('state:%s' % 1)
+        search_options.append('state:%s' % 2)
+    if options.get('show_closed') == '1':
+        search_options.append('state:%s' % 2)
+    if options.get('show_markdelete') == '1':
+        search_options.append('state:%s' % 3)
+    if options.get('show_markanonymize') == '1':
+        search_options.append('state:%s' % 4)
+    if options.get('show_anonymized') == '1':
+        search_options.append('state:%s' % 5)
+        # For cm users show cases which are marked for anon too
+        if h.hasRole(['cm_ka']):
+            search_options.append('state:%s' % 4)
+    if options.get('gender', '-2') != '-2':
+        search_options.append('gender:%s' % options.get('gender'))
+    if options.get('branch'):
+        search_options.append('branch:%s' % options.get('branch'))
+    if options.get('search_str'):
+        search_options.append(options.get('search_str'))
+
+    #Migration
+    if options.get('migration', '-2') != '-2':
+        search_options.append('migration:%s' % options.get('migration'))
+
+    #cm-states
+    cm_state = options.get('cm_state')
+    phases = [] # default
+    if cm_state:
+        if cm_state == 'none':
+            phases = []
+        if cm_state == 'clearing':
+            phases = [0,1]
+        if cm_state == 'active':
+            phases = [2]
+        if cm_state == 'finished':
+            phases = [3,4,5]
+        if cm_state == 'all':
+            phases = [-1,0,1,2,3,4,5]
+        phases = '%s' % ";".join("phase:%s" % p for p in phases)
+        if phases:
+            search_options.append(phases)
+
+    #check build time_interval
+    year = options.get('year')
+    quarter = options.get('quarter')
+    if year != '-1' and year:
+        q_start = "01-01"
+        q_end = "12-31"
+        if quarter == '1':
+            q_end = "03-31"
+        if quarter == '2':
+            q_start = "04-01"
+            q_end = "06-30"
+        if quarter == '3':
+            q_start = "07-01"
+            q_end = "09-30"
+        if quarter == '4':
+            q_start = "10-01"
+
+        search_options.append("interval_start_date:%s" % "-".join([year,
+                                                                   q_start]))
+        search_options.append("interval_end_date:%s" % "-".join([year, q_end]))
+
+    return search_options
+
 class CaseOverviewController(BaseController):
 
     @checkRole(('admin', 'cm', 'pt_dlr'))
@@ -23,4 +122,85 @@
         session.save()
         return self.overview()
 
+    @checkRole(('admin', 'cm', 'pt_dlr'))
+    def overview(self):
+        reset = self._checkBool(request.params.get('reset', '0'))
+        sort_field, sort_order = get_sort(request.params)
+        if reset:
+            session['CASE_OVERVIEW_SEARCHOPTIONS'] = {}
+            session['CASE_OVERVIEW_SELECTION'] = {}
+            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)
+        search_options = parseSearchOptions(form_defaults)
+
+        # Sorting of the cases
+        if sort_field == "name_1":
+            search_options.append('sort_field:name')
+        if sort_field == "vorname_1":
+            search_options.append('sort_field:m.vorname')
+        if sort_field == "zugriff":
+            search_options.append('sort_field:zugriff')
+        if sort_field == "kundennummer":
+            search_options.append('sort_field:fn')
+        if sort_field == "bearbeiter_id":
+            search_options.append('sort_field:bearbeiter_id')
+
+        if sort_order == "desc":
+            search_options.append('sort_order:desc')
+        else:
+            search_options.append('sort_order:asc')
+
+        search_str = ";".join(search_options)
+
+        c.cases = MpulsCaseOverview()
+        c.cases.search(search_str)
+
+        #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()
+                             if x.getEditor().id == user.id])
+        c.count_standin = c.count_all - c.count_own
+        if h.hasRole(['cm_ka']):
+            c.count_anon = len([x for x in c.cases.getDatasets()
+                                  if x.getState().getState() in (4,5)])
+        else:
+            c.count_anon = len([x for x in c.cases.getDatasets()
+                                  if x.getState().getState() == 5])
+        c.count_markanon = len([x for x in c.cases.getDatasets()
+                                  if x.getState().getState() == 4])
+        c.count_del  = len([x for x in c.cases.getDatasets()
+                              if x.getState().getState() == 3])
+
+        # Load case-selection and merge with default search options
+        # Ok please close your eyes now!!! This is.... well ugly
+        form_defaults_copy = form_defaults.copy()
+        form_defaults_copy.update(session.get('CASE_OVERVIEW_SELECTION', {}))
+
+        # Hide evaluation option if someone did a search for a particular editor
+        c.hide_evaluation = False
+        expr = re.compile('.*editor:[0-9]+.*')
+        if expr.match(search_str):
+            c.hide_evaluation = True
+
+        overview = render('/casemanagement/overview.mako')
+        return formencode.htmlfill.render(unicode(overview, 'utf-8'),
+                                          defaults=form_defaults_copy)
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list