mirror of
https://github.com/kennethreitz-archive/pystache.git
synced 2026-06-05 23:40:16 +00:00
Better way to perform callable check. Allow callables from context attributes.
This commit is contained in:
committed by
Chris Wanstrath
parent
ae58a99fa4
commit
08b06f9cab
+5
-8
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user