[Mpuls-commits] r1978 - wasko/branches/2.0/jmdweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 16 16:06:33 CET 2010


Author: torsten
Date: 2010-03-16 16:06:32 +0100 (Tue, 16 Mar 2010)
New Revision: 1978

Modified:
   wasko/branches/2.0/jmdweb/controllers/case_overview.py
Log:
Fixed case_overview.py


Modified: wasko/branches/2.0/jmdweb/controllers/case_overview.py
===================================================================
--- wasko/branches/2.0/jmdweb/controllers/case_overview.py	2010-03-16 15:05:09 UTC (rev 1977)
+++ wasko/branches/2.0/jmdweb/controllers/case_overview.py	2010-03-16 15:06:32 UTC (rev 1978)
@@ -44,7 +44,7 @@
 
 from mpulsweb.controllers.case_overview import CaseOverviewController \
     as CaseBaseOverviewController, FORM_DEFAULTS_ADMIN, \
-    FORM_DEFAULTS_CM, parseSearchOptions
+    FORM_DEFAULTS_CM, get_sort
 
 from jmdweb.lib.validators import BundleActionForm, \
      SetBundleEditorForm, SetBundleStandinForm, CasePartSelectionForm
@@ -184,20 +184,101 @@
 
 class CaseOverviewController(CaseBaseOverviewController):
 
-    @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
-    def search(self):
-        validator = SearchCaseForm()
-        c.form_result = {}
-        c.form_errors = {}
-        try:
-            form_result = validator.to_python(request.params)
-        except formencode.Invalid, error:
-            form_result = error.value
-            form_errors = error.error_dict or {}
-        session['CASE_OVERVIEW_SEARCHOPTIONS'] = form_result
-        session.save()
-        return self.overview()
+    def parseSortOptions(self, options=None):
+        search_options = []
+        sort_field, sort_order = get_sort(options)
+        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')
+        return search_options
+
+    def parseSearchOptions(self, 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
+
     @checkRole(('admin_ka', 'cm_ka', 'pt_dlr'))
     def bundleAction(self):
         validator = BundleActionForm()
@@ -223,7 +304,7 @@
                     FORM_DEFAULTS = FORM_DEFAULTS_CM
                 search_options = (session.get('CASE_OVERVIEW_SEARCHOPTIONS')
                                   or FORM_DEFAULTS)
-                search_str = ";".join(parseSearchOptions(search_options))
+                search_str = ";".join(self.parseSearchOptions(search_options))
                 case_bundle = CaseBundle([case.id for case in
                                           MpulsCaseOverview().search(search_str)])
             else:



More information about the Mpuls-commits mailing list