summaryrefslogtreecommitdiff
path: root/repoze/bfg/view.py
diff options
context:
space:
mode:
Diffstat (limited to 'repoze/bfg/view.py')
-rw-r--r--repoze/bfg/view.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/repoze/bfg/view.py b/repoze/bfg/view.py
index 180c020a0..e3f22dc08 100644
--- a/repoze/bfg/view.py
+++ b/repoze/bfg/view.py
@@ -39,10 +39,11 @@ def render_view_to_iterable(context, request, name='', secure=True):
found and called but the view does not return an object which
implements ``repoze.bfg.interfaces.IResponse``. You can usually
get the string representation of the return value of this function
- by calling ``''.join(iterable)``. If ``secure`` is ``True``, and
- the view is protected by a permission, the permission will be
- checked before calling the view function. If the permission check
- disallows view execution (based on the current security policy), a
+ by calling ``''.join(iterable)``, or just use ``render_view``
+ instead. If ``secure`` is ``True``, and the view is protected by
+ a permission, the permission will be checked before calling the
+ view function. If the permission check disallows view execution
+ (based on the current security policy), a
``repoze.bfg.security.Unauthorized`` exception will be raised; its
``message`` attribute explains why the view access was disallowed.
If ``secure`` is ``False``, no permission checking is done."""
@@ -53,6 +54,27 @@ def render_view_to_iterable(context, request, name='', secure=True):
raise ValueError('response did not implement IResponse: %r' % response)
return response.app_iter
+def render_view(context, request, name='', secure=True):
+ """ Render the view named ``name`` against the specified
+ ``context`` and ``request``, and unwind the the view response's
+ ``app_iter`` (see the interface named
+ ``repoze.bfg.interfaces.IResponse``) into a single string. This
+ function will return ``None`` if a corresponding view cannot be
+ found. Additionally, this function will raise a ``ValueError`` if
+ a view function is found and called but the view does not return
+ an object which implements ``repoze.bfg.interfaces.IResponse``.
+ If ``secure`` is ``True``, and the view is protected by a
+ permission, the permission will be checked before calling the view
+ function. If the permission check disallows view execution (based
+ on the current security policy), a
+ ``repoze.bfg.security.Unauthorized`` exception will be raised; its
+ ``message`` attribute explains why the view access was disallowed.
+ If ``secure`` is ``False``, no permission checking is done."""
+ iterable = render_view_to_iterable(context, request, name, secure)
+ if iterable is None:
+ return None
+ return ''.join(iterable)
+
def is_response(ob):
""" Return True if ``ob`` implements the
``repoze.bfg.interfaces.IResponse`` interface, False if not. Note