[Mpuls-commits] r4559 - in base/trunk: . mpulsweb/controllers mpulsweb/lib mpulsweb/templates/casemanagement

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 2 17:02:15 CET 2011


Author: torsten
Date: 2011-02-02 17:02:12 +0100 (Wed, 02 Feb 2011)
New Revision: 4559

Modified:
   base/trunk/ChangeLog
   base/trunk/development.ini
   base/trunk/mpulsweb/controllers/case_overview.py
   base/trunk/mpulsweb/lib/validators.py
   base/trunk/mpulsweb/templates/casemanagement/caselist.mako
Log:
Improved caseoverview. Handling search params and errors should now be better.
Diveded large functions in smaller subfunctions.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2011-02-02 15:57:36 UTC (rev 4558)
+++ base/trunk/ChangeLog	2011-02-02 16:02:12 UTC (rev 4559)
@@ -2,7 +2,20 @@
 
 	* mpulsweb/templates/main.mako: Only show "Account-Settings" if
 	administration is enabled.
+	* mpulsweb/lib/app_globals.py: Load configfile and buidl
+	ConfigParser-object. Save parser as g.mpuls_ini
+	* mpulsweb/lib/helpers.py: New functions
+	"get_urls_for_other_datasets", "get_num_of_other_datasets". Needed for
+	switching between datasets
+	* mpulsweb/templates/switch_to_other_datasets.mako: Only show links to
+	switch between datasets if there is more than one dataset avaliable
 
+	* mpulsweb/controllers/case_overview.py,
+	mpulsweb/lib/validators.py,
+	mpulsweb/templates/casemanagement/caselist.mako: Improved
+	caseoverview. Handling search params and errors should now be better.
+	Diveded large functions in smaller subfunctions.
+
 2011-02-01  Torsten Irlaender <torsten at intevation.de>
 
 	* mpulsweb/templates/evaluation/evaluate.mako: Issue1744: Changed

Modified: base/trunk/development.ini
===================================================================
--- base/trunk/development.ini	2011-02-02 15:57:36 UTC (rev 4558)
+++ base/trunk/development.ini	2011-02-02 16:02:12 UTC (rev 4559)
@@ -44,11 +44,12 @@
 
 # for connections to PostgeSQL database
 # db_database: %s will be replaced by certificate value
-mpuls.db.host     = 127.0.0.1 
+#mpuls.db.host     = 127.0.0.1 
+mpuls.db.host     = justus.pult 
 mpuls.db.port     = 5432 
 # Define fallback name of the database if fetching name from
 # SSL_CLIENT_S_DN_CN in ssl certificte fails. 
-mpuls.db.name     = mydb 
+mpuls.db.name     = testdb 
 mpuls.db.database = ka_%s_db
 # db_user:     first %s -> database name, second %s -> user
 mpuls.db.user     = ka_%s_%s

Modified: base/trunk/mpulsweb/controllers/case_overview.py
===================================================================
--- base/trunk/mpulsweb/controllers/case_overview.py	2011-02-02 15:57:36 UTC (rev 4558)
+++ base/trunk/mpulsweb/controllers/case_overview.py	2011-02-02 16:02:12 UTC (rev 4559)
@@ -8,6 +8,7 @@
 
 from mpulsweb.lib.base import c, render, request, session, BaseController
 from mpulsweb.lib.security import checkRole
+from mpulsweb.lib.validators import CaseOverviewForm 
 from mpulsweb.model.user import UserListObject
 from mpulsweb.model.case import MpulsCaseOverview
 from mpulsweb.model.phase import PhaseFactory 
@@ -16,25 +17,27 @@
 log = logging.getLogger(__name__)
 
 
-def get_sort(params):
-    '''Return sort field and sort order. First try to return a userdefined sort
-    and order. If user does not provide one of there params, try to return the
-    safed params in session. If session is also empty return default params.
-    '''
-    session_options = session['CASE_OVERVIEW_SEARCHOPTIONS']
-    sort = params.get('sort_field',
-                      session_options.get('sort_field',
-                                          g.mpuls_config.get('search',
-                                                            'default-sorting')))
-    order = params.get('sort_order',
-                       session_options.get('sort_order',
-                                           g.mpuls_config.get('search',
-                                                              'default-order')))
-    session_options['sort_field'] = sort
-    session_options['sort_order'] = order
-    session.save()
-    return sort, order
+#def get_sort(params):
+#    '''Return sort field and sort order. First try to return a userdefined sort
+#    and order. If user does not provide one of there params, try to return the
+#    safed params in session. If session is also empty return default params.
+#    '''
+#    session_options = session['CASE_OVERVIEW_SEARCHOPTIONS']
+#    sort = params.get('sort_field',
+#                      session_options.get('sort_field',
+#                                          g.mpuls_config.get('search',
+#                                                            'default-sorting')))
+#    order = params.get('sort_order',
+#                       session_options.get('sort_order',
+#                                           g.mpuls_config.get('search',
+#                                                              'default-order')))
+#    session_options['sort_field'] = sort
+#    session_options['sort_order'] = order
+#    session.save()
+#    return sort, order
 
+# TODO: Move function. Is only used in other controllers. May be better placed
+# in Model phase or helpers?
 def default_phases():
     phases = []
     for pp in g.mpuls_config.get('phases', 'phases'):
@@ -89,91 +92,86 @@
             session['EXTENDED_SEARCH'] = False
             session.save()
 
+        # Get saved search params from session.
         search_options = search_options_from_session()
+        # Update searchparams with
+        validator = CaseOverviewForm()
+        search_options.update(validator.to_python(request.params))
+
         session['CASE_OVERVIEW_SEARCHOPTIONS'] = search_options
         session.save()
-        search = self.parseSearchOptions(search_options,
+        print g.case
+        return self.search(search_options)
+
+    def _getCaseList(self, search_options):
+        cases = MpulsCaseOverview()
+        if search_options:
+            options = self.parseSearchOptions(search_options,
                                         extended=session.get("EXTENDED_SEARCH"))
+            cases.search(options)
+        return cases
 
-        # Sorting the cases
-        search.update(self.parseSortOptions(request.params))
+    def _renderOverview(self, cases, form_defaults, form_errors):
 
-        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)
-
+        user = session['USER_AUTHORIZED']
         # 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)
-
-        user = session['USER_AUTHORIZED']
         c.phases = PhaseFactory().build() 
 
         #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()
+        c.count_all = len([x for x in cases.getDatasets()])
+        c.count_own = len([x for x in cases.getDatasets()
                            if x.getEditor().id == user.id])
         c.count_standin = c.count_all - c.count_own
-        c.count_anon = len([x for x in c.cases.getDatasets()
+        c.count_anon = len([x for x in cases.getDatasets()
                                 if x.getState().getState() == 5])
-        c.count_markanon = len([x for x in c.cases.getDatasets()
+        c.count_markanon = len([x for x in cases.getDatasets()
                                 if x.getState().getState() == 4])
-        c.count_del = len([x for x in c.cases.getDatasets()
+        c.count_del = len([x for x in 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
-        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:
+        if "editor" in form_defaults:
             c.hide_evaluation = True
 
-        overview = render('/casemanagement/overview.mako')
-
-        form_defaults = search_options_copy or request.params.mixed()
         form_defaults["id_field"] = "m.id"
         form_defaults["all_ids"] = " ".join(unicode(case.id)
-                                            for case in c.cases.getDatasets())
+                                            for case in cases.getDatasets())
+        c.cases = cases
+        overview = render('/casemanagement/overview.mako')
         return formencode.htmlfill.render(overview, defaults=form_defaults,
-                                          errors=c.form_errors)
+                                          errors=form_errors)
+        
 
-
     @checkRole(('admin', 'cm', 'pt_dlr'))
-    def search(self):
-        c.form_result = {}
-        c.form_errors = {}
-        try:
-            c.form_result = g.case_search.validate_form_params(request.params)
-        except formencode.Invalid, error:
-            log.exception("search: formencode error %s" % error)
-            c.form_result = error.value
-            c.form_errors = error.error_dict or {}
+    def search(self, search_options=None):
 
-        session['CASE_OVERVIEW_SEARCHOPTIONS'] = c.form_result
-        session.save()
-        return self.overview()
+        form_result = {} 
+        form_errors = {}
+        if search_options is None:
+            search_options = {}
+            form_result.update(search_options_from_session())
+        else:
+            form_result.update(search_options) 
 
-    def parseSortOptions(self, options=None):
-        sort_field, sort_order = get_sort(options)
+        if not search_options:
+            try:
+                form_result.update(g.case_search.validate_form_params(request.params))
+                search_options.update(form_result)
+                session['CASE_OVERVIEW_SEARCHOPTIONS'] = search_options 
+                session.save()
+            except formencode.Invalid, error:
+                log.exception("search: formencode error %s" % error)
+                form_result = error.value
+                form_errors = error.error_dict or {}
 
-        # Pass the sort options to the template
-        c.sort_field = sort_field
-        c.sort_order = sort_order
+        cases = self._getCaseList(search_options)
+        return self._renderOverview(cases, form_result, form_errors)
 
-        # default behavior is to take the sortfield for sorting
-        return dict(sort_field=sort_field,
-                    sort_order=sort_order)
-
     def parseSearchOptions(self, options, extended):
         return parseSearchOptions(options, extended)
 

Modified: base/trunk/mpulsweb/lib/validators.py
===================================================================
--- base/trunk/mpulsweb/lib/validators.py	2011-02-02 15:57:36 UTC (rev 4558)
+++ base/trunk/mpulsweb/lib/validators.py	2011-02-02 16:02:12 UTC (rev 4559)
@@ -688,7 +688,12 @@
     edate = DateCheck()
     gender = Int(if_missing=-2)
 
+class CaseOverviewForm(BaseFormValidator):
 
+    reset = Bool(if_missing=False)
+    sort_field = String(if_missing=g.mpuls_config.get('search', 'default-sorting'))
+    sort_order = String(if_missing=g.mpuls_config.get('search', 'default-order'))
+
 class BundleActionForm(BaseFormValidator):
 
     filter_extra_fields = True

Modified: base/trunk/mpulsweb/templates/casemanagement/caselist.mako
===================================================================
--- base/trunk/mpulsweb/templates/casemanagement/caselist.mako	2011-02-02 15:57:36 UTC (rev 4558)
+++ base/trunk/mpulsweb/templates/casemanagement/caselist.mako	2011-02-02 16:02:12 UTC (rev 4559)
@@ -40,6 +40,10 @@
 %>
 
 <%def name="build_list_headers()">
+  <%
+    sort_field = session['CASE_OVERVIEW_SEARCHOPTIONS'].get('sort_field')
+    sort_order = session['CASE_OVERVIEW_SEARCHOPTIONS'].get('sort_order')
+  %>
   % if g.mpuls_config.is_enabled('case-module', 'casebundle'):
     <th class="table_header_h table_checkbox">&nbsp;</th>
   % endif
@@ -48,8 +52,9 @@
       <th class="${style} table_header_h">${title}
         <a href="${h.url_for(controller='case_overview', action='overview',
                              sort_field=urlpart, sort_order='asc')}">
+
             <img class   = "sorticon"
-            %if c.sort_field == urlpart and c.sort_order == 'asc':
+            %if sort_field == urlpart and sort_order == 'asc':
                 src    = "${h.url_for('/images/icons/sort_asc_active.png')}"
                 alt    = "${_("Sorted by %s in ascending order") % title}"
                 title  = "${_("Sorted by %s in ascending order") % title}"
@@ -63,7 +68,7 @@
         <a href="${h.url_for(controller='case_overview', action='overview',
                              sort_field=urlpart, sort_order='desc')}">
             <img class   = "sorticon"
-            %if c.sort_field == urlpart and c.sort_order == 'desc':
+            %if sort_field == urlpart and sort_order == 'desc':
                 src    = "${h.url_for('/images/icons/sort_desc_active.png')}"
                 alt    = "${_("Sorted by %s in descending order") % title}"
                 title  = "${_("Sorted by %s in descending order") % title}"



More information about the Mpuls-commits mailing list