[Mpuls-commits] r4463 - base/trunk/mpulsweb/controllers

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Dec 29 14:00:19 CET 2010


Author: torsten
Date: 2010-12-29 14:00:19 +0100 (Wed, 29 Dec 2010)
New Revision: 4463

Modified:
   base/trunk/mpulsweb/controllers/evaluation_overview.py
Log:
* mpulsweb/controllers/evaluation_overview.py: Implemented marking
	agencys for evaluation


Modified: base/trunk/mpulsweb/controllers/evaluation_overview.py
===================================================================
--- base/trunk/mpulsweb/controllers/evaluation_overview.py	2010-12-29 12:58:41 UTC (rev 4462)
+++ base/trunk/mpulsweb/controllers/evaluation_overview.py	2010-12-29 13:00:19 UTC (rev 4463)
@@ -6,8 +6,11 @@
 
 from pylons import app_globals as g
 
+from mpulsweb.lib.validators import BundleActionForm
 from mpulsweb.lib.base import c, render, request, session, BaseController
 from mpulsweb.lib.security import checkRole
+from mpulsweb.lib.helpers import url_for
+from mpulsweb.lib.translation import _, ungettext
 from mpulsweb.model.user import UserListObject
 from mpulsweb.model.agency import MpulsAgencyOverview
 from mpulsweb.model.phase import PhaseFactory 
@@ -15,7 +18,17 @@
 
 log = logging.getLogger(__name__)
 
+BUNDLE_NOTIFICATION_NOACTION_HEADER = _("No action specified for the selection")
+BUNDLE_NOTIFICATION_NOACTION = _("""You have not selected any action for the
+selection. Please click OK to go to the case overview and select there
+an action from the drop down menu.""")
 
+BUNDLE_NOTIFICATION_EMPTYLIST_HEADER = _("No valid agencys in the selection!")
+BUNDLE_NOTIFICATION_EMPTYLIST = _(u"""The selected action can not be executed
+on any of the agencys in your selection. Please make sure that the agencys are
+in a state from which you can execute the selected action.""")
+
+
 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
@@ -133,6 +146,7 @@
         overview = render('/evaluation/overview.mako')
 
         form_defaults = search_options_copy or request.params.mixed()
+        form_defaults["id_field"] = "m.fkz::integer"
         form_defaults["all_ids"] = " ".join(unicode(case.id)
                                             for case in c.cases.getDatasets())
         return formencode.htmlfill.render(overview, defaults=form_defaults,
@@ -168,7 +182,62 @@
     def parseSearchOptions(self, options, extended):
         return parseSearchOptions(options, extended)
 
+    def _empty_caselist(self):
+        c.url_ok = url_for(controller='/evaluation_overview')
+        c.dialog_title = BUNDLE_NOTIFICATION_EMPTYLIST_HEADER
+        c.dialog_text = BUNDLE_NOTIFICATION_EMPTYLIST
+        return render('/casebundle/dialogs/error.mako')
+
+    def no_action(self):
+        c.dialog_title= BUNDLE_NOTIFICATION_NOACTION_HEADER
+        c.dialog_text = BUNDLE_NOTIFICATION_NOACTION
+        c.url_ok = url_for(controller='/evaluation_overview')
+        return render('/casebundle/dialogs/error.mako')
+
     def bundleAction(self):
-        return "not implemented"
+        validator = BundleActionForm()
+        log.debug(request.params)
+        try:
+            # Check submitted fields
+            form_result = validator.to_python(request.params)
+            log.debug(form_result)
 
+            # Check if the user has selected any cases
+            if (len(form_result.get('case_id', [])) <= 0
+                and not form_result.get('all_cases')):
+                return self._empty_caselist()
+
+            # Delegate to concrete action
+            action = form_result.get('action')
+            if action == 'no_action':
+                return self.no_action()
+            if action == 'evaluate':
+                session["evaluation_ids"] = form_result.get('case_id') 
+                session["id_field"] = form_result.get('id_field') 
+                if form_result.get('all_cases') > 0:
+                    session["evaluation_ids"] = form_result.get('all_ids') 
+                session.save()
+                c.url_ok = url_for(controller='/evaluation_overview')
+                num = len(session["evaluation_ids"])
+                c.dialog_title= ungettext("Agency was marked for evaluation",
+                                          "Agency were marked for evaluation",
+                                          num)
+                c.dialog_text = \
+                    ungettext("%d agency was marked for evaluation."
+                              " All following evaluations will be limited"
+                              " to that agency. Click 'OK' to continue.",
+                              "%d agencys were marked for evaluation."
+                              " All following evalutations will be limited"
+                              " to those agencys. Click 'OK' to continue.",
+                              num) % num
+
+                return render('/casebundle/dialogs/success_markevaluate.mako')
+        except formencode.Invalid, error:
+            log.exception(error)
+            raise
+        except Exception, e:
+            log.exception(e)
+            raise
+        return "Not implemented"
+
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list