Simplify template loading and render() now returns rendere document instead of an instance of StringIO.
This commit is contained in:
parent
46ec22b187
commit
d1226e852c
1 changed files with 4 additions and 8 deletions
10
__init__.py
10
__init__.py
|
|
@ -136,11 +136,7 @@ class Render():
|
|||
CRUD operations into the ZIP archive.
|
||||
"""
|
||||
|
||||
if os.path.exists(self.template):
|
||||
f = open(self.template, 'r')
|
||||
self._unpacked_template = zipfile.ZipFile(f, "r" )
|
||||
else:
|
||||
self._unpacked_template = zipfile.ZipFile(self._template, "r" )
|
||||
self._unpacked_template = zipfile.ZipFile(self.template, 'r')
|
||||
|
||||
# go through the files in source
|
||||
for zi in self._unpacked_template.filelist:
|
||||
|
|
@ -218,7 +214,7 @@ class Render():
|
|||
self.headers = None
|
||||
|
||||
self.pack_document()
|
||||
return self.rendered
|
||||
return self.rendered.getvalue()
|
||||
|
||||
|
||||
def node_parents(self, node, parent_type):
|
||||
|
|
@ -316,6 +312,6 @@ if __name__ == "__main__":
|
|||
result = render.render(countries=countries, document=document)
|
||||
|
||||
output = open('rendered.odt', 'w')
|
||||
output.write(result.getvalue())
|
||||
output.write(result)
|
||||
|
||||
print "Template rendering finished! Check rendered.odt file."
|
||||
Loading…
Add table
Add a link
Reference in a new issue