diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-05-21 16:01:58 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-05-21 16:01:58 +0000 |
| commit | 5a11e2ad0828b7c763d0c81211f686a85bc0324c (patch) | |
| tree | 750deaa5086279a1cd0baa28c0d5bdaa17414463 /repoze/bfg/tests/grokkedapp | |
| parent | 385084582eeff5f2f1a93f3b90c091dc1a4ad50e (diff) | |
| download | pyramid-5a11e2ad0828b7c763d0c81211f686a85bc0324c.tar.gz pyramid-5a11e2ad0828b7c763d0c81211f686a85bc0324c.tar.bz2 pyramid-5a11e2ad0828b7c763d0c81211f686a85bc0324c.zip | |
- Class objects may now be used as view callables (both via ZCML and
via use of the ``bfg_view`` decorator in Python 2.6 as a class
decorator). The calling semantics when using a class as a view
callable is similar to that of using a class as a Zope "browser
view": the class' ``__init__`` must accept two positional parameters
(conventionally named ``context``, and ``request``). The resulting
instance must be callable (it must have a ``__call__`` method).
When called, the instance should return a response. For example::
from webob import Response
class MyView(object):
def __init__(self, context, request):
self.context = context
self.request = request
def __call__(self):
return Response('hello from %s!' % self.context)
See the "Views" chapter in the documentation and the
``repoze.bfg.view`` API documentation for more information.
Diffstat (limited to 'repoze/bfg/tests/grokkedapp')
| -rw-r--r-- | repoze/bfg/tests/grokkedapp/__init__.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/repoze/bfg/tests/grokkedapp/__init__.py b/repoze/bfg/tests/grokkedapp/__init__.py index 9d91eb80f..aeedd4dba 100644 --- a/repoze/bfg/tests/grokkedapp/__init__.py +++ b/repoze/bfg/tests/grokkedapp/__init__.py @@ -8,4 +8,19 @@ class INothing(Interface): def grokked(context, request): """ """ +class grokked_klass(object): + """ """ + def __init__(self, context, request): + self.context = context + self.request = request + def __call__(self): + """ """ + +# in 2.6+ the below can be spelled as a class decorator: +# +# @bfg_view(for_=INothing, name='grokked_klass') +# class grokked_class(object): +# .... +# +grokked_klass = bfg_view(for_=INothing, name='grokked_klass')(grokked_klass) |
