Skip to content

Commit

Permalink
- config.add_view(<aninstancemethod>) raised AttributeError invol…
Browse files Browse the repository at this point in the history
…ving

  ``__text__``.  See #461

Fixes #461.
  • Loading branch information
mcdonc committed Mar 12, 2012
1 parent cd7ca31 commit 4a6f532
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Next release
============

Bug Fixes
---------

- ``config.add_view(<aninstancemethod>)`` raised AttributeError involving
``__text__``. See https://github.com/Pylons/pyramid/issues/461

1.3b2 (2012-03-02)
==================

Expand Down
9 changes: 5 additions & 4 deletions pyramid/config/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,16 @@ def __call__(self, view):
self.decorated_view(
self.rendered_view(
self.mapped_view(
self.text_wrapped_view(view))))))))))
self.text_wrapped_view(
view))))))))))

@wraps_view
def text_wrapped_view(self, view):
# if the method is an instance method, we need to wrap it in order
# to be able to assign a __text__ value to it later. see #461.
if inspect.ismethod(view):
if hasattr(view, '__text__'):
return view
def text_wrapper(context, request):
return view(context, request)
text_wrapper.__text__ = ''
return text_wrapper
return view

Expand Down
6 changes: 5 additions & 1 deletion pyramid/tests/test_config/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,14 @@ def __call__(self, context, request):
def test_add_view_as_instancemethod(self):
from pyramid.renderers import null_renderer
class View:
def index(self, context, request): pass
def index(self, context, request):
return 'OK'
view = View()
config=self._makeOne(autocommit=True)
config.add_view(view=view.index, renderer=null_renderer)
wrapper = self._getViewCallable(config)
result = wrapper(None, None)
self.assertEqual(result, 'OK')

def test_add_view_as_instance_requestonly(self):
from pyramid.renderers import null_renderer
Expand Down

0 comments on commit 4a6f532

Please sign in to comment.