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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Oct 4 20:08:59 CEST 2010


Author: bh
Date: 2010-10-04 20:08:56 +0200 (Mon, 04 Oct 2010)
New Revision: 3885

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/controllers/formularpage.py
   base/trunk/mpulsweb/lib/renderer.py
Log:
Render notices in a separate block, but treat them as warnings
otherwise.  Implements mpuls/issue1110.

* mpulsweb/controllers/formularpage.py (get_rendered_page): Pass
the notices to the error renderer, too
(get_rendered_page): Add notices to the warningList for htmlfill,
too.

* mpulsweb/lib/renderer.py (ViewRenderer.__init__): New instance
variable "notices".
(ViewRenderer._has_warnings): notice rules are warnings, too, so
check self.notices as well
(ViewRenderer._checkWarnings): Add notice warnings to
self.notices.
(ErrorRenderer.__init__): New parameter and instance variable:
notices.
(ErrorRenderer.render): Render notices in a separate block after
errors but before warnings


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-10-04 17:59:56 UTC (rev 3884)
+++ base/trunk/ChangeLog	2010-10-04 18:08:56 UTC (rev 3885)
@@ -1,5 +1,26 @@
 2010-10-04  Bernhard Herzog  <bh at intevation.de>
 
+	Render notices in a separate block, but treat them as warnings
+	otherwise.  Implements mpuls/issue1110.
+
+	* mpulsweb/controllers/formularpage.py (get_rendered_page): Pass
+	the notices to the error renderer, too
+	(get_rendered_page): Add notices to the warningList for htmlfill,
+	too.
+
+	* mpulsweb/lib/renderer.py (ViewRenderer.__init__): New instance
+	variable "notices".
+	(ViewRenderer._has_warnings): notice rules are warnings, too, so
+	check self.notices as well
+	(ViewRenderer._checkWarnings): Add notice warnings to
+	self.notices.
+	(ErrorRenderer.__init__): New parameter and instance variable:
+	notices.
+	(ErrorRenderer.render): Render notices in a separate block after
+	errors but before warnings
+
+2010-10-04  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/lib/renderer.py (ViewRenderer._has_warnings): New.
 	Check whether there are known warnings for a given node
 	(ViewRenderer._renderLabel, ViewRenderer._renderErrors): Use

Modified: base/trunk/mpulsweb/controllers/formularpage.py
===================================================================
--- base/trunk/mpulsweb/controllers/formularpage.py	2010-10-04 17:59:56 UTC (rev 3884)
+++ base/trunk/mpulsweb/controllers/formularpage.py	2010-10-04 18:08:56 UTC (rev 3885)
@@ -4,6 +4,7 @@
 import traceback
 from cgi import escape
 import datetime
+import itertools
 
 import formencode
 
@@ -107,7 +108,7 @@
         except Exception, e:
             log.exception(e)
         error_renderer = ErrorRenderer(errors, renderer.warnings,
-                                       renderer.widget_order)
+                                       renderer.notices, renderer.widget_order)
         c.formularerrors = error_renderer.render(page)
         c.page_id = page.getIdentifier()
         session['case'].setPageId(c.page_id)
@@ -135,8 +136,9 @@
     # make a new dictionary because the warnings have the warning text in a (one
     #element) list
     warningList = {}
-    for i in renderer.warnings.keys():
-        warningList[i] = renderer.warnings[i][0]
+    for key, value in itertools.chain(renderer.warnings.iteritems(),
+                                      renderer.notices.iteritems()):
+        warningList[key] = value[0]
 
     # Let htmlfill parse the form again
     parsedForm = formencode.htmlfill.render(parsedForm, errors=warningList,

Modified: base/trunk/mpulsweb/lib/renderer.py
===================================================================
--- base/trunk/mpulsweb/lib/renderer.py	2010-10-04 17:59:56 UTC (rev 3884)
+++ base/trunk/mpulsweb/lib/renderer.py	2010-10-04 18:08:56 UTC (rev 3885)
@@ -183,6 +183,7 @@
         self.ro_mode = ro_mode
         self.tabindex = 3
         self.warnings = {}
+        self.notices = {}
         self.widget_order = []
 
     def next_tabindex(self):
@@ -324,7 +325,8 @@
 
     def _has_warnings(self, node):
         """Return whether there are known warnings for the node"""
-        return node.getIdentifier() in self.warnings
+        identifier = node.getIdentifier()
+        return identifier in self.warnings or identifier in self.notices
 
     def _checkWarnings(self, node):
         """Check node for warnings by evaluating the relevant warning rules.
@@ -361,7 +363,11 @@
                 continue
             for result, variables in rule.getExpr().evaluate_instances(context):
                 if not result and id in variables:
-                    self.warnings.setdefault(id, []).append(rule.getValue())
+                    if rule.getMark().startswith("notice"):
+                        collection = self.notices
+                    else:
+                        collection = self.warnings
+                    collection.setdefault(id, []).append(rule.getValue())
 
     def _renderGroup(self, node):
         meta = self._getMeta(node)
@@ -1085,9 +1091,10 @@
 
 class ErrorRenderer(object):
 
-    def __init__(self, error_items, warnings, widget_order):
+    def __init__(self, error_items, warnings, notices, widget_order):
         self.error_items = error_items
         self.warnings = warnings
+        self.notices = notices
         self.widget_order = widget_order
 
     def in_widget_order(self, items):
@@ -1116,6 +1123,10 @@
         out = []
         out.append(self.render_items(self.error_items, _('Formular errors'),
                                      icon("info/alert.png"), tree))
+        out.append(self.render_items(self.notices, _('Formular notices'),
+                                     icon("info/info.png"), tree,
+                                     css_class='warning-box',
+                                     show_undo=False))
         out.append(self.render_items(self.warnings, _('Formular warnings'),
                                      icon("info/info.png"), tree,
                                      css_class='warning-box',



More information about the Mpuls-commits mailing list