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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue May 24 12:54:26 CEST 2011


Author: bh
Date: 2011-05-24 12:54:25 +0200 (Tue, 24 May 2011)
New Revision: 4992

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/controllers/evaluate.py
Log:
* mpulsweb/controllers/evaluate.py (get_search_options)
(get_default_options, get_common_options, get_session_options):
Split get_search_options into the separate new functions
get_default_options, get_common_options and
get_session_options. This will allow more control over which
sources of evaluation options to use, which is necessary to make
sure the "adele"-evaluations always use the correct
parameters.
(EvaluateController.evaluate): adapt to get_search_options split.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2011-05-24 09:20:39 UTC (rev 4991)
+++ base/trunk/ChangeLog	2011-05-24 10:54:25 UTC (rev 4992)
@@ -1,3 +1,15 @@
+2011-05-24  Bernhard Herzog  <bh at intevation.de>
+
+	* mpulsweb/controllers/evaluate.py (get_search_options)
+	(get_default_options, get_common_options, get_session_options):
+	Split get_search_options into the separate new functions
+	get_default_options, get_common_options and
+	get_session_options. This will allow more control over which
+	sources of evaluation options to use, which is necessary to make
+	sure the "adele"-evaluations always use the correct
+	parameters.
+	(EvaluateController.evaluate): adapt to get_search_options split.
+
 2011-05-24  Ludwig Reiter <ludwig.reiter at inteation.de>
 
 	* mpulsweb/i18n/mpulsweb.pot,

Modified: base/trunk/mpulsweb/controllers/evaluate.py
===================================================================
--- base/trunk/mpulsweb/controllers/evaluate.py	2011-05-24 09:20:39 UTC (rev 4991)
+++ base/trunk/mpulsweb/controllers/evaluate.py	2011-05-24 10:54:25 UTC (rev 4992)
@@ -48,44 +48,45 @@
     return sdate, edate
 
 
-def get_search_options(soptions=None, id=None, selected_ids=()):
-    """Return the values for the search parameters in the evaluation form.
+def get_default_options():
+    """Return a dictionary with the default evaluation options"""
+    return dict(phase=g.mpuls_config.get('evaluations', 'default-phases'),
+                type_ending=g.mpuls_config.get('evaluations', 'default-ending'),
+                start_date=g.mpuls_config.get_date('search',
+                                                   'default-start-date'),
+                end_date=g.mpuls_config.get_date('search', 'default-end-date'))
 
-    The return value is a dictionary. The default values are taken from
-    the configuration. The parameter soptions, if given, should be a
-    dictionary containing previously used parameters. Usually this will
-    be a copy of a dictionary previously returned by this function.
 
+def get_common_options(id, selected_ids):
+    """Return a dictionary with common evaluation options.
+
     The parameter id should be the id of the evaluation. It will be
     returned in the dictionary with the key 'id'. The information from
-    the configuration file for the evaluation is expected to already be
-    available in the global c.evalconfig.
+    the configuration file for the evaluation is taken from the
+    evalconfig parameter which is expected to be an instance of
+    EvaluationConfig.
 
     The parameter selected_ids should be a sequence of integers with the
     ids of the cases selected for evaluation. If no cases were selected,
     it should be an empty sequence.
     """
-    options = {}
-    options['id'] = id
-    options["selected_ids"] = selected_ids
-    options['typelist'] = c.evalconfig.get_evaluations()
+    return dict(id=id, selected_ids=selected_ids,
+                typelist=c.evalconfig.get_evaluations())
 
-    # set default evaluation options.
-    options['phase'] = g.mpuls_config.get('evaluations', 'default-phases')
-    options['type_ending'] = g.mpuls_config.get('evaluations', 'default-ending')
-    options['start_date'] = g.mpuls_config.get_date('search',
-                                                    'default-start-date')
-    options['end_date'] = g.mpuls_config.get_date('search', 'default-end-date')
 
-    # copy options from soptions if included there
+def get_session_options():
+    """Return a dictionary with the evaluation options stored in the session
+    """
+    options = dict()
+    soptions = session.get('evaluation.options')
     if soptions:
         for name in ["start_date", "end_date", "phase", "type_ending"]:
             if name in soptions:
                 options[name] = soptions[name]
-
     return options
 
 
+
 class EvaluateController(BaseController):
 
     def index(self):
@@ -104,8 +105,10 @@
     def evaluate(self, id=None):
         c.evalconfig = EvaluationConfig(get_configfile(id), None, None, None,
                                         None, None, None, None, None)
-        evaloptions = get_search_options(session.get('evaluation.options'), id,
-                                         session.get("evaluation_ids", ()))
+        evaloptions = get_default_options()
+        evaloptions.update(get_common_options(id, session.get("evaluation_ids",
+                                                              ())))
+        evaloptions.update(get_session_options())
 
         # If user selects adele-evaluation render page with disabled
         # configuration elements.  Change default params



More information about the Mpuls-commits mailing list