[Mpuls-commits] r5976 - base/trunk/mpulsweb/controllers
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Thu Jun 7 09:14:11 CEST 2012
Author: bricks
Date: 2012-06-07 09:14:11 +0200 (Thu, 07 Jun 2012)
New Revision: 5976
Modified:
base/trunk/mpulsweb/controllers/formularpage.py
Log:
Add a new PageRenderer class
This class can be used to set mpuls application specific
renderers. In addition to the get_rendered_page function
it is possible to pass additional arguments to the special
renderers. This has become necessary for mpuls_S and it's
university specific key values for studienfachrichtung.
It would have been possible to implement a special renderer
for the studienfachrichtung field with the get_rendered_page
function too but the new PageRenderer class is more flexible.
Part of mpuls/issue3156 (muls_S: Stipendienserver hochschulspezifische Schl?\195?\188ssel)
Modified: base/trunk/mpulsweb/controllers/formularpage.py
===================================================================
--- base/trunk/mpulsweb/controllers/formularpage.py 2012-06-06 12:21:00 UTC (rev 5975)
+++ base/trunk/mpulsweb/controllers/formularpage.py 2012-06-07 07:14:11 UTC (rev 5976)
@@ -107,6 +107,92 @@
return render('/formularpage/content.mako')
+class PageRenderer(object):
+
+ def __init__(self):
+ self.set_viewrenderer(ViewRenderer)
+ self.set_errorrenderer(ErrorRenderer)
+ self.set_printrenderer(ViewPrintRenderer)
+ self.set_rgrenderer(RepeatGroupRenderer)
+
+ def set_viewrenderer(self, viewrenderer, **kw_args):
+ self.viewrenderer = viewrenderer
+ self.viewrenderer_args = kw_args
+
+ def set_errorrenderer(self, errorrenderer, **kw_args):
+ self.errorrenderer = errorrenderer
+ self.errorrenderer_args = kw_args
+
+ def set_printrenderer(self, printrenderer, **kw_args):
+ self.printrenderer = printrenderer
+ self.printrenderer_args = kw_args
+
+ def set_rgrenderer(self, rgrenderer, **kw_args):
+ self.rgrenderer = rgrenderer
+ self.rgrenderer_args = kw_args
+
+ def get_rendered_page(self, id, instance_tree=None):
+ if instance_tree is None:
+ factory = InstanceFactory(g.formedTree, PostgresDBInterface())
+ instance_tree = factory.loadInstanceTreeByIdentifier(
+ session['case'].id,
+ session.get('uncommited_fields'))
+
+ log.debug('Getting page "%s"' % id)
+ page = instance_tree.getItem(id)
+
+ # 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)
+
+ page_label = page.getMeta().getDescription()
+
+ url_factory = UrlFactory()
+ renderer_kw_args = dict(read_only=session.get('render_mode', 'ro') == 'ro',
+ languages=get_lang())
+ if isinstance(page, RepeatInstanceContainerNode):
+ formdata = TreeFormData(instance_tree)
+ renderer_kw_args.update(self.rgrenderer_args)
+ renderer = self.rgrenderer(formdata, page.getMeta(), url_factory,
+ **renderer_kw_args)
+ errors = {}
+ defaults = {}
+ else:
+ errors, defaults = convert_error_items(page.getErrors())
+ formdata = TreeFormData(instance_tree, shadow=defaults,
+ errors=errors, node=page)
+ if c.print_version:
+ renderer_kw_args.update(self.printrenderer_args)
+ renderer = self.printrenderer(formdata, page.getMeta(),
+ url_factory, **renderer_kw_args)
+ else:
+ renderer_kw_args.update(self.viewrenderer_args)
+ renderer = self.viewrenderer(formdata, page.getMeta(),
+ url_factory, **renderer_kw_args)
+
+ navigation_item = session['navigation.tree'].getTreeItem(id)
+ mark_folderopen(navigation_item)
+
+ c.formularheader = renderer.render_page_headings()
+ c.formular = renderer.render(show_next=navigation_item.nextKey(),
+ hidden_fields=[("page",
+ page.getIdentifier())])
+
+ error_renderer = self.errorrenderer(formdata, g.formedTree, errors,
+ renderer.warnings, renderer.notices,
+ renderer.widget_order, url_factory,
+ languages=get_lang())
+ c.formularerrors = error_renderer.render()
+ c.page_id = page.getIdentifier()
+ session['navigation.selectedpage'] = id
+ session.save()
+
+ return render('/formularpage/content.mako')
+
+
class FormularpageController(BaseController):
def index(self):
More information about the Mpuls-commits
mailing list