summaryrefslogtreecommitdiff
path: root/repoze/bfg/view.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-09-01 03:03:51 +0000
committerChris McDonough <chrism@agendaless.com>2008-09-01 03:03:51 +0000
commit885bfb1a58303d197f689d13f79fb621b67860f2 (patch)
tree4f5d486663b77aec8f11d989439d287093bdf94f /repoze/bfg/view.py
parent7e2c6cbb452aa986891b2a99653a147bfb053e19 (diff)
downloadpyramid-885bfb1a58303d197f689d13f79fb621b67860f2.tar.gz
pyramid-885bfb1a58303d197f689d13f79fb621b67860f2.tar.bz2
pyramid-885bfb1a58303d197f689d13f79fb621b67860f2.zip
Add render_view function.
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