[Mpuls-commits] r3810 - in base/trunk: . mpulsweb/controllers mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Sep 28 17:38:34 CEST 2010
Author: bh
Date: 2010-09-28 17:38:22 +0200 (Tue, 28 Sep 2010)
New Revision: 3810
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/controllers/formularpage.py
base/trunk/mpulsweb/lib/renderer.py
Log:
Show errors and warnings in the same order as the widgets on the
page. Fixes mpuls/issue1106
* mpulsweb/controllers/formularpage.py (get_rendered_page):
Instantiate the ErrorRenderer with the widget_order list of the
rendered page.
* mpulsweb/lib/renderer.py (ViewRenderer.__init__): New instance
variable widget_order to collect the order of the widgets on the
rendered page.
(ViewRenderer._checkWarnings): Add widget id to the widget_order
list.
(ErrorRenderer.__init__): New parameter and instance variable
widget_order. Usually initialized with the widget_order list from
a ViewRenderer instance.
(ErrorRenderer.in_widget_order): Helper method to get the items
from a dictionary of errors or warnings in widget_order
(ErrorRenderer.render_items): Iterate over the items in widget
order.
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2010-09-28 15:29:38 UTC (rev 3809)
+++ base/trunk/ChangeLog 2010-09-28 15:38:22 UTC (rev 3810)
@@ -1,3 +1,25 @@
+2010-09-28 Bernhard Herzog <bh at intevation.de>
+
+ Show errors and warnings in the same order as the widgets on the
+ page. Fixes mpuls/issue1106
+
+ * mpulsweb/lib/renderer.py (ViewRenderer.__init__): New instance
+ variable widget_order to collect the order of the widgets on the
+ rendered page.
+ (ViewRenderer._checkWarnings): Add widget id to the widget_order
+ list.
+ (ErrorRenderer.__init__): New parameter and instance variable
+ widget_order. Usually initialized with the widget_order list from
+ a ViewRenderer instance.
+ (ErrorRenderer.in_widget_order): Helper method to get the items
+ from a dictionary of errors or warnings in widget_order
+ (ErrorRenderer.render_items): Iterate over the items in widget
+ order.
+
+ * mpulsweb/controllers/formularpage.py (get_rendered_page):
+ Instantiate the ErrorRenderer with the widget_order list of the
+ rendered page.
+
2010-09-28 Torsten Irländer <torsten.irlaender at intevation.de>
* mpulsweb/lib/helper/case.py (phase_time_in_weeks): Issue1121: Added
Modified: base/trunk/mpulsweb/controllers/formularpage.py
===================================================================
--- base/trunk/mpulsweb/controllers/formularpage.py 2010-09-28 15:29:38 UTC (rev 3809)
+++ base/trunk/mpulsweb/controllers/formularpage.py 2010-09-28 15:38:22 UTC (rev 3810)
@@ -106,7 +106,9 @@
c.formular = renderer.render(showNext=False)
except Exception, e:
log.exception(e)
- c.formularerrors = ErrorRenderer(errors, renderer.warnings).render(page)
+ error_renderer = ErrorRenderer(errors, renderer.warnings,
+ renderer.widget_order)
+ c.formularerrors = error_renderer.render(page)
c.page_id = page.getIdentifier()
session['case'].setPageId(c.page_id)
session['navigation.selectedpage'] = id
Modified: base/trunk/mpulsweb/lib/renderer.py
===================================================================
--- base/trunk/mpulsweb/lib/renderer.py 2010-09-28 15:29:38 UTC (rev 3809)
+++ base/trunk/mpulsweb/lib/renderer.py 2010-09-28 15:38:22 UTC (rev 3810)
@@ -182,6 +182,7 @@
self.ro_mode = ro_mode
self.tabindex = 3
self.warnings = {}
+ self.widget_order = []
def next_tabindex(self):
tabindex = self.tabindex
@@ -338,6 +339,12 @@
name = meta.getName()
id = node.getIdentifier()
+
+ # add all checked widgets to warning order, even if the have no
+ # warnings or no warning rules so that the widget_order list
+ # can be used to order the errors too.
+ self.widget_order.append(id)
+
formed = self.it.getFormEd()
rules = [rule for rule in formed.name2markingrules.get(name, ())
if rule.isWarning()]
@@ -1035,10 +1042,31 @@
class ErrorRenderer(object):
- def __init__(self, error_items, warnings):
+ def __init__(self, error_items, warnings, widget_order):
self.error_items = error_items
self.warnings = warnings
+ self.widget_order = widget_order
+ def in_widget_order(self, items):
+ """Generate the items in the dictionary items in widget order.
+ The dictionary should map widget ids to errors or warnings.
+ The widget order is defined by the widget_order parameter given
+ to the constructor when the ErrorRenderer was instantiated.
+ """
+ copy = items.copy()
+ for id in self.widget_order:
+ value = copy.pop(id, None)
+ if value is not None:
+ yield (id, value)
+ if copy:
+ # This shouldn't happen, but if it does happen, log a debug
+ # message and yield the rest of the items in an arbitrary
+ # order, so that all are at least shown to the user.
+ log.debug("ErrorRenderer: not all items occur in the widget_order"
+ " list")
+ for key, value in copy.iteritems():
+ yield (key, value)
+
def render(self, page):
tree = page.getInstanceTree()
@@ -1062,7 +1090,7 @@
out.append('</h1>')
out.append('<ol>')
- for k, values in items.iteritems():
+ for k, values in self.in_widget_order(items):
element = tree.getFormEd().findByName(k.split(':')[0])
description = element.getDescription()
# the values in the items dict may either be strings or
More information about the Mpuls-commits
mailing list