Better way to perform callable check. Allow callables from context attributes.

This commit is contained in:
Joshua Roesslein
2009-11-17 11:05:50 +08:00
committed by Chris Wanstrath
parent ae58a99fa4
commit 08b06f9cab
+5 -8
View File
@@ -76,15 +76,12 @@ class View(object):
return re.sub('[A-Z]', repl, name)[1:]
def get(self, attr, default):
if attr in self.context:
return self.context[attr]
elif hasattr(self, attr):
try:
return getattr(self, attr)()
except TypeError:
return getattr(self, attr)
attr = self.context.get(attr, getattr(self, attr, default))
if callable(attr):
return attr()
else:
return default
return attr
def render(self):
template = self.load_template()