Commit 8954e01f by Carl Whittaker

Fixing views as attributes not being rendered before display

parent c859dfa2
...@@ -99,19 +99,15 @@ class Template(object): ...@@ -99,19 +99,15 @@ class Template(object):
from view import View from view import View
view = View(context=context) view = View(context=context)
view.template_path = self.view.template_path
view.template_encoding = self.view.template_encoding
view.parent = self.view view.parent = self.view
return Template(template, view).render() return Template(template, view).render()
def _render_list(self, template, listing): def _render_list(self, template, listing):
from view import View
insides = [] insides = []
for item in listing: for item in listing:
view = View(context=item) insides.append(self._render_dictionary(template, item))
view.template_path = self.view.template_path
view.template_encoding = self.view.template_encoding
view.parent = self.view
insides.append(Template(template, view).render())
return ''.join(insides) return ''.join(insides)
......
...@@ -20,6 +20,8 @@ class View(object): ...@@ -20,6 +20,8 @@ class View(object):
attr = self.context.get(attr, getattr(self, attr, self._get_from_parent(attr, default))) attr = self.context.get(attr, getattr(self, attr, self._get_from_parent(attr, default)))
if hasattr(attr, '__call__') and type(attr) is UnboundMethodType: if hasattr(attr, '__call__') and type(attr) is UnboundMethodType:
return attr() return attr()
if hasattr(attr, 'render'):
return attr.render(encoding=self.template_encoding)
else: else:
return attr return attr
......
...@@ -31,7 +31,7 @@ class TestSimple(unittest.TestCase): ...@@ -31,7 +31,7 @@ class TestSimple(unittest.TestCase):
view = TemplatePartial() view = TemplatePartial()
self.assertEquals(pystache.Template('{{>inner_partial}}', view).render(), 'Again, Welcome!') self.assertEquals(pystache.Template('{{>inner_partial}}', view).render(), 'Again, Welcome!')
self.assertEquals(pystache.Template('{{#looping}}{{>inner_partial}} {{/looping}}', view).render(), '''Again, Welcome! Again, Welcome! Again, Welcome!''') self.assertEquals(pystache.Template('{{#looping}}{{>inner_partial}} {{/looping}}', view).render(), '''Again, Welcome! Again, Welcome! Again, Welcome! ''')
def test_non_existent_value_renders_blank(self): def test_non_existent_value_renders_blank(self):
view = Simple() view = Simple()
......
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