Commit f03c85c7 by Joshua Roesslein Committed by Chris Wanstrath

Add support for using non-callables as View attributes.

parent 613a8cd2
## 0.2.0 (2009-11-16)
* Add support for using non-callables as View attributes. [joshthecoder]
## 0.1.1 (2009-11-13)
* Ensure we're dealing with strings, always
......
......@@ -79,7 +79,10 @@ class View(object):
if attr in self.context:
return self.context[attr]
elif hasattr(self, attr):
return getattr(self, attr)()
try:
return getattr(self, attr)()
except TypeError:
return getattr(self, attr)
else:
return default
......
......@@ -21,6 +21,11 @@ class TestView(unittest.TestCase):
view = Simple()
self.assertEquals(view.render(), "Hi pizza!")
def test_non_callable_attributes(self):
view = Simple()
view.thing = 'Chris'
self.assertEquals(view.render(), "Hi Chris!")
def test_complex(self):
self.assertEquals(ComplexView().render(), """<h1>Colors</h1>
<ul>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment