[Mpuls-commits] r4597 - in base/trunk: . mpulsweb/controllers
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Feb 9 18:06:14 CET 2011
Author: bh
Date: 2011-02-09 18:06:12 +0100 (Wed, 09 Feb 2011)
New Revision: 4597
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/controllers/formularpage.py
Log:
* mpulsweb/controllers/formularpage.py (get_rendered_page):
Simplify the control flow a little by exiting early if the page
wasn't found.
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2011-02-09 09:11:39 UTC (rev 4596)
+++ base/trunk/ChangeLog 2011-02-09 17:06:12 UTC (rev 4597)
@@ -1,3 +1,9 @@
+2011-02-09 Bernhard Herzog <bh at intevation.de>
+
+ * mpulsweb/controllers/formularpage.py (get_rendered_page):
+ Simplify the control flow a little by exiting early if the page
+ wasn't found.
+
2011-02-09 Torsten Irlaender <torsten at intevation.de>
* mpulsweb/controllers/usersettings.py
Modified: base/trunk/mpulsweb/controllers/formularpage.py
===================================================================
--- base/trunk/mpulsweb/controllers/formularpage.py 2011-02-09 09:11:39 UTC (rev 4596)
+++ base/trunk/mpulsweb/controllers/formularpage.py 2011-02-09 17:06:12 UTC (rev 4597)
@@ -78,54 +78,57 @@
log.debug('Getting page "%s"' % id)
page = instance_tree.getItem(id)
- if page:
- page_label = page.getMeta().getDescription()
+ # Abort with a 404 HTTP response if the page wasn't found. abort
+ # raises an exception, so in the code after this branch we can
+ # assume that the page was found.
+ if not page:
+ log.error('Page not found %s' % id)
+ abort(404)
- # Check if there is help available for this page
- help = []
- if page.getMeta().hasHelp():
- help.append(tag("a", target="_blank",
- href=url_for(controller="/annotations",
- action="help", id=page.getMeta().getName())))
- help.append(tag("img", src=icon("formular/help.png"), alt="help",
- width=12,
- height=12))
- help.append('</a>')
+ page_label = page.getMeta().getDescription()
- if isinstance(page.getParent(), RepeatInstanceNode):
- page_label += " %s" % get_child_num(page.getParent())
- c.formularheader = ("<h1>%s %s</h1>" % (escape(page_label), "".join(help)))
- if isinstance(page, RepeatInstanceContainerNode):
- renderer = RepeatGroupRenderer(instance_tree, page,
- session.get('render_mode',
- 'ro') == 'ro',
- g.mpuls_config.get("renderer",
- "rg_digests"))
- errors = {}
- defaults = {}
+ # Check if there is help available for this page
+ help = []
+ if page.getMeta().hasHelp():
+ help.append(tag("a", target="_blank",
+ href=url_for(controller="/annotations",
+ action="help", id=page.getMeta().getName())))
+ help.append(tag("img", src=icon("formular/help.png"), alt="help",
+ width=12,
+ height=12))
+ help.append('</a>')
+
+ if isinstance(page.getParent(), RepeatInstanceNode):
+ page_label += " %s" % get_child_num(page.getParent())
+ c.formularheader = ("<h1>%s %s</h1>" % (escape(page_label), "".join(help)))
+ if isinstance(page, RepeatInstanceContainerNode):
+ renderer = RepeatGroupRenderer(instance_tree, page,
+ session.get('render_mode',
+ 'ro') == 'ro',
+ g.mpuls_config.get("renderer",
+ "rg_digests"))
+ errors = {}
+ defaults = {}
+ else:
+ c.formularerrors = u"Fehler"
+ renderer = ViewRenderer(instance_tree, page,
+ session.get('render_mode', 'ro') == 'ro')
+ errors, defaults = convert_error_items(page.getErrors())
+ try:
+ mark_folderopen(session['navigation.tree'].getTreeItem(id))
+ if session['navigation.tree'].getTreeItem(id).nextKey():
+ c.formular = renderer.render(showNext=True)
else:
- c.formularerrors = u"Fehler"
- renderer = ViewRenderer(instance_tree, page,
- session.get('render_mode', 'ro') == 'ro')
- errors, defaults = convert_error_items(page.getErrors())
- try:
- mark_folderopen(session['navigation.tree'].getTreeItem(id))
- if session['navigation.tree'].getTreeItem(id).nextKey():
- c.formular = renderer.render(showNext=True)
- else:
- c.formular = renderer.render(showNext=False)
- except Exception, e:
- log.exception(e)
- error_renderer = ErrorRenderer(errors, renderer.warnings,
- renderer.notices, renderer.widget_order)
- c.formularerrors = error_renderer.render(page)
- c.page_id = page.getIdentifier()
- session['case'].setPageId(c.page_id)
- session['navigation.selectedpage'] = id
- session.save()
- else:
- log.error('Page not found %s' % id)
- return abort(404)
+ c.formular = renderer.render(showNext=False)
+ except Exception, e:
+ log.exception(e)
+ error_renderer = ErrorRenderer(errors, renderer.warnings,
+ renderer.notices, renderer.widget_order)
+ c.formularerrors = error_renderer.render(page)
+ c.page_id = page.getIdentifier()
+ session['case'].setPageId(c.page_id)
+ session['navigation.selectedpage'] = id
+ session.save()
# Render form and use htmlfill to fillout the form and mark errorfields.
form = render('/formularpage/content.mako')
More information about the Mpuls-commits
mailing list