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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Oct 8 20:49:23 CEST 2010


Author: bh
Date: 2010-10-08 20:49:23 +0200 (Fri, 08 Oct 2010)
New Revision: 3946

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/controllers/evaluate.py
Log:
* mpulsweb/controllers/evaluate.py
(EvaluateController.evaluateAction): Refactor the code
substantially: Apply the same conn Parameter change to
EvaluationConfig instantiation as previously in the evaluate
method in the case of invalid form parameters where the
evaluate.mako template has to be rerendered.  Remove some
superfluous variables.  Move the code that renders the evaluation
result out of the try-finally block because the db connection will
not be needed at that point anymore.  Reduce some code
duplication.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-10-08 18:08:01 UTC (rev 3945)
+++ base/trunk/ChangeLog	2010-10-08 18:49:23 UTC (rev 3946)
@@ -1,5 +1,18 @@
 2010-10-08  Bernhard Herzog  <bh at intevation.de>
 
+	* mpulsweb/controllers/evaluate.py
+	(EvaluateController.evaluateAction): Refactor the code
+	substantially: Apply the same conn Parameter change to
+	EvaluationConfig instantiation as previously in the evaluate
+	method in the case of invalid form parameters where the
+	evaluate.mako template has to be rerendered.  Remove some
+	superfluous variables.  Move the code that renders the evaluation
+	result out of the try-finally block because the db connection will
+	not be needed at that point anymore.  Reduce some code
+	duplication.
+
+2010-10-08  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/controllers/evaluate.py (EvaluateController.evaluate):
 	Do not instantiate the EvaluationConfig with an actual db
 	connection.  It will never be used and the previous code would

Modified: base/trunk/mpulsweb/controllers/evaluate.py
===================================================================
--- base/trunk/mpulsweb/controllers/evaluate.py	2010-10-08 18:08:01 UTC (rev 3945)
+++ base/trunk/mpulsweb/controllers/evaluate.py	2010-10-08 18:49:23 UTC (rev 3946)
@@ -179,25 +179,23 @@
 
 
     def evaluateAction(self):
-        '''Return an HTML file containing the result of one or more evaluations.
-        '''
+        """Return an HTML file containing the result of one or more evaluations.
+        """
         params = formencode.variabledecode.variable_decode(request.params)
         validator = EvaluationFormValidator()
-        form_result = {}
-        form_errors = {}
 
+        id = int(params['id'])
+        config_file = get_configfile(id)
+
         # Check values
-        conn, cur = None, None
-        conn = db.getConnection()
-        id = int(params['id'])
-        c.evalconfig = EvaluationConfig(get_configfile(id), conn, None, None,
-                                        None, None, None, None, None)
         try:
             form_result = validator.to_python(params)
         except formencode.Invalid, error:
             log.exception("Error while decoding form parameters")
             form_result = error.value
             form_errors = error.error_dict or {}
+            c.evalconfig = EvaluationConfig(config_file, None, None, None,
+                                            None, None, None, None, None)
             c.evaloptions = get_search_options(session.get('evaluation.options'),
                                                id,
                                                session.get("evaluation_ids",
@@ -211,25 +209,27 @@
         eval_params = self._get_evalparams(form_result)
         try:
             try:
-                evalconfig = EvaluationConfig(get_configfile(form_result['id']),
-                                              conn, eval_params['start_date'],
+                conn = db.getConnection()
+                evalconfig = EvaluationConfig(config_file, conn,
+                                              eval_params['start_date'],
                                               eval_params['end_date'],
-                                              None, 
-                                              None, 
-                                              None,
+                                              None, None, None,
                                               eval_params['sql'],
                                               eval_params['typelist'])
                 evalset = EvaluationSet(evalconfig)
                 evalset.evaluate()
-                c.result = evalset.export(EvaluationExportHTML(show_percent=form_result['show_percent']))
-                session['evaluation.params'] = eval_params
-                session.save()
-                return render('/evaluation/result.mako')
             except:
                 log.exception(_('Error: Evaluation failed'))
         finally:
-            db.recycleConnection(conn, cur)
+            db.recycleConnection(conn, None)
 
+        exporter = EvaluationExportHTML(show_percent=form_result['show_percent'])
+        c.result = evalset.export(exporter)
+        session['evaluation.params'] = eval_params
+        session.save()
+        return render('/evaluation/result.mako')
+
+
     def exportXML(self):
         '''Return an XML file containing the result of one or more evaluations.
         '''



More information about the Mpuls-commits mailing list