[Mpuls-commits] r6133 - in base/trunk/mpulsweb: controllers templates/evaluation

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 1 16:59:08 CET 2012


Author: torsten
Date: 2012-11-01 16:59:08 +0100 (Thu, 01 Nov 2012)
New Revision: 6133

Modified:
   base/trunk/mpulsweb/controllers/evaluate.py
   base/trunk/mpulsweb/templates/evaluation/evaluate.mako
   base/trunk/mpulsweb/templates/evaluation/evaluate_extra.mako
Log:
Splitted up code which configures the evaluation form. Checks if options o
evaluations should be rendererd disabled (formerly only on adele) ist now
configurable per evaluation in the json file using (options_disabled) option.
This defaults to false which means the options are editable.


Modified: base/trunk/mpulsweb/controllers/evaluate.py
===================================================================
--- base/trunk/mpulsweb/controllers/evaluate.py	2012-11-01 15:04:52 UTC (rev 6132)
+++ base/trunk/mpulsweb/controllers/evaluate.py	2012-11-01 15:59:08 UTC (rev 6133)
@@ -146,31 +146,31 @@
     def _get_validator(self):
         return EvaluationFormValidator()
 
+    def _get_options(self, id, evalconfig):
+        common_options = get_common_options(evalconfig, id,
+                                            session.get("evaluation_ids", ()))
+        return [get_default_options(), common_options, get_session_options()]
+
+    def _render_options_disabled(self, id):
+        for evaluation in g.mpuls_config.get('evaluations', 'enabled'):
+            if evaluation.get("id") == str(id):
+                return evaluation.get('options_disabled', "0") == "1"
+        return False
+
     def evaluate(self, id=None):
-        c.evalconfig = EvaluationConfig(get_configfile(id), None, None, None,
+        evalconfig = EvaluationConfig(get_configfile(id), None, None, None,
                                         None, None, None, None, None)
-        common_options = get_common_options(c.evalconfig, id,
-                                            session.get("evaluation_ids", ()))
 
-        if id == "0":
-            # If user selects adele-evaluation render page with disabled
-            # configuration elements and use different default options
-            # and no session options.
-            c.adele_evaluation = True
-            option_sources = [common_options, get_default_adele_options()]
-        else:
-            c.adele_evaluation = False
-            option_sources  = [get_default_options(), common_options,
-                               get_session_options()]
-
         evaloptions = dict()
-        for options in option_sources:
+        for options in self._get_options(id, evalconfig):
             evaloptions.update(options)
         validator = self._get_validator()
         defaults = validator.from_python(evaloptions)
 
         c.phases = PhaseFactory().build()
         c.eval_config_id = id
+        c.evalconfig = evalconfig
+        c.render_options_disabled = self._render_options_disabled(id)
         form = render('/evaluation/evaluate.mako')
         return formencode.htmlfill.render(form, defaults=defaults,
                                           errors={}, auto_insert_errors=False)

Modified: base/trunk/mpulsweb/templates/evaluation/evaluate.mako
===================================================================
--- base/trunk/mpulsweb/templates/evaluation/evaluate.mako	2012-11-01 15:04:52 UTC (rev 6132)
+++ base/trunk/mpulsweb/templates/evaluation/evaluate.mako	2012-11-01 15:59:08 UTC (rev 6133)
@@ -9,10 +9,10 @@
 <div>
 <form action="${h.url(controller='evaluate', action='evaluateAction')}" method="POST" target="_blank">
 <% 
-   if c.adele_evaluation:
-       adele_disabled = h.literal('disabled="disabled"')
+   if c.render_options_disabled:
+       disabled_options = h.literal('disabled="disabled"')
    else:
-       adele_disabled = ""
+       disabled_options = ""
 %>
 <input type="hidden" name="id">
 <table>
@@ -29,7 +29,7 @@
     <td>
       % for n,p in enumerate(c.phases):
         <input type="checkbox" name="phase" id="phase_${n}" value="${p.id}" 
-               ${adele_disabled}>
+               ${disabled_options}>
           <label for="phase_${n}">
             ${p.getDescription()}<br>
           </label>
@@ -39,19 +39,18 @@
   <tr>
     <td class="label">${_('Start')}</td>
     <td>
-      <input type="text" name="start_date" class="datefield" ${adele_disabled}>
+      <input type="text" name="start_date" class="datefield" ${disabled_options}>
       <form:error name="start_date" format="">
     </td>
   </tr>
   <tr>
     <td class="label">${_('End')}</td>
     <td>
-      <input type="text" name="end_date" class="datefield" ${adele_disabled}>
+      <input type="text" name="end_date" class="datefield" ${disabled_options}>
       <form:error name="end_date" format="">
     </td>
   </tr>
-  <%include file="/evaluation/evaluate_extra.mako" 
-            args="adele_disabled=adele_disabled"/>
+  <%include file="/evaluation/evaluate_extra.mako" args="disabled_options=disabled_options"/>
   <%
      evaluation_ids = session.get("evaluation_ids")
    %>

Modified: base/trunk/mpulsweb/templates/evaluation/evaluate_extra.mako
===================================================================
--- base/trunk/mpulsweb/templates/evaluation/evaluate_extra.mako	2012-11-01 15:04:52 UTC (rev 6132)
+++ base/trunk/mpulsweb/templates/evaluation/evaluate_extra.mako	2012-11-01 15:59:08 UTC (rev 6133)
@@ -1,4 +1,4 @@
 ## Define this template in derived mpuls application to add extra case
 ## search options to the evaluation form
-## The evaluate_extra template must accept one argument, adele_disabled.
-<%page args="adele_disabled"/>
+## The evaluate_extra template must accept one argument, disabled_options.
+<%page args="disabled_options"/>



More information about the Mpuls-commits mailing list