diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-10-18 05:50:54 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-10-18 05:50:54 +0000 |
| commit | 1dc3907e59995852d5ee0251c1c92a360f03ed35 (patch) | |
| tree | 38da7879503f2b55b995cee89a2aebe6c7d6f076 /repoze/bfg/tests/grokkedapp | |
| parent | 2cce431f02a37c119eacfc3dfa94af9fe3305de1 (diff) | |
| download | pyramid-1dc3907e59995852d5ee0251c1c92a360f03ed35.tar.gz pyramid-1dc3907e59995852d5ee0251c1c92a360f03ed35.tar.bz2 pyramid-1dc3907e59995852d5ee0251c1c92a360f03ed35.zip | |
- The ``@bfg_view`` decorator can now be used against a class method::
from webob import Response
from repoze.bfg.view import bfg_view
class MyView(object):
def __init__(self, context, request):
self.context = context
self.request = request
@bfg_view(name='hello')
def amethod(self):
return Response('hello from %s!' % self.context)
When the bfg_view decorator is used against a class method, a view
is registered for the *class* (it's a "class view" where the "attr"
happens to be the method they're attached to), so the view class
must have a suitable constructor.
Diffstat (limited to 'repoze/bfg/tests/grokkedapp')
| -rw-r--r-- | repoze/bfg/tests/grokkedapp/__init__.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/repoze/bfg/tests/grokkedapp/__init__.py b/repoze/bfg/tests/grokkedapp/__init__.py index 5a00adbeb..5d2843885 100644 --- a/repoze/bfg/tests/grokkedapp/__init__.py +++ b/repoze/bfg/tests/grokkedapp/__init__.py @@ -52,6 +52,29 @@ class Foo(object): grokked_instance = Foo() grokked_instance = bfg_view(name='grokked_instance')(grokked_instance) +class Base(object): + @bfg_view(name='basemethod') + def basemethod(self): + """ """ + +class MethodViews(Base): + def __init__(self, context, request): + self.context = context + self.request = request + + @bfg_view(name='method1') + def method1(self): + return 'method1' + + @bfg_view(name='method2') + def method2(self): + return 'method2' + + @bfg_view(name='stacked_method2') + @bfg_view(name='stacked_method1') + def stacked(self): + return 'stacked_method' + # ungrokkable A = 1 @@ -59,4 +82,9 @@ B = {} def stuff(): """ """ - + +class Whatever(object): + pass + +class Whatever2: + pass |
