[Mpuls-commits] r3499 - in base/trunk: . mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Aug 31 20:53:41 CEST 2010


Author: bh
Date: 2010-08-31 20:53:40 +0200 (Tue, 31 Aug 2010)
New Revision: 3499

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/controllers/case_overview.py
Log:
* mpulsweb/controllers/case_overview.py
(search_options_from_session, CaseOverviewController.overview):
Move some code shared with case_bundle.py to the new function
search_options_from_session.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-08-31 18:38:25 UTC (rev 3498)
+++ base/trunk/ChangeLog	2010-08-31 18:53:40 UTC (rev 3499)
@@ -1,5 +1,12 @@
 2010-08-31  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/controllers/case_overview.py
+	(search_options_from_session, CaseOverviewController.overview):
+	Move some code shared with case_bundle.py to the new function
+	search_options_from_session.
+
+2010-08-31  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/lib/search.py (CaseSearch.get_phases_clause): Use
 	generic_int_choice_clause instead of having the equivalent code
 	inline.  Actually it's not completely equivalent: if "phase" is

Modified: base/trunk/mpulsweb/controllers/case_overview.py
===================================================================
--- base/trunk/mpulsweb/controllers/case_overview.py	2010-08-31 18:38:25 UTC (rev 3498)
+++ base/trunk/mpulsweb/controllers/case_overview.py	2010-08-31 18:53:40 UTC (rev 3499)
@@ -48,6 +48,18 @@
                                                  session['USER_AUTHORIZED'])
 
 
+def search_options_from_session():
+    options = session.get('CASE_OVERVIEW_SEARCHOPTIONS')
+    if options:
+        return options
+
+    user = session['USER_AUTHORIZED']
+    if user.isAdmin():
+        return g.mpuls_config.get('search', 'admin_defaults')[0]
+    else:
+        return g.mpuls_config.get('search', 'cm_defaults')[0]
+
+
 class CaseOverviewController(BaseController):
 
     @checkRole(('admin', 'cm', 'pt_dlr'))
@@ -67,13 +79,6 @@
 
     @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 = g.mpuls_config.get('search', 'admin_defaults')[0]
-        else:
-            FORM_DEFAULTS = g.mpuls_config.get('search', 'cm_defaults')[0]
-
         # 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'))
@@ -83,22 +88,21 @@
             session['EXTENDED_SEARCH'] = False
             session.save()
 
-        form_defaults = (session.get('CASE_OVERVIEW_SEARCHOPTIONS')
-                         or FORM_DEFAULTS)
-        session['CASE_OVERVIEW_SEARCHOPTIONS'] = form_defaults
+        search_options = search_options_from_session()
+        session['CASE_OVERVIEW_SEARCHOPTIONS'] = search_options
         session.save()
-        search_options = self.parseSearchOptions(form_defaults)
-        
+        search = self.parseSearchOptions(search_options)
+
         # Sorting the cases
-        search_options.update(self.parseSortOptions(request.params))
+        search.update(self.parseSortOptions(request.params))
 
         if not c.form_errors:
             c.form_errors = {}
-        
+
         # Do the search if there are no errors
         c.cases = MpulsCaseOverview()
         if not c.form_errors:
-            c.cases.search(search_options)
+            c.cases.search(search)
 
         # Values used in the template
         #
@@ -107,6 +111,8 @@
         filter = [u.id for u in ulo.getAdminList()]
         c.userlist = ulo.getUserList(filter)
 
+        user = session['USER_AUTHORIZED']
+
         #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()
@@ -121,17 +127,17 @@
 
         # 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', {}))
+        search_options_copy = search_options.copy()
+        search_options_copy.update(session.get('CASE_OVERVIEW_SELECTION', {}))
 
         # Hide evaluation option if someone did a search for a particular editor
         c.hide_evaluation = False
-        if "editor" in search_options:
+        if "editor" in search:
             c.hide_evaluation = True
 
         overview = render('/casemanagement/overview.mako')
 
-        formular_defaults = form_defaults_copy or request.params.mixed()
+        formular_defaults = search_options_copy or request.params.mixed()
         return formencode.htmlfill.render(overview,
                                           defaults=formular_defaults,
                                           errors=c.form_errors)



More information about the Mpuls-commits mailing list