Introducing pad filter.
This commit is contained in:
parent
1ad6849be2
commit
c32ff51032
1 changed files with 17 additions and 2 deletions
19
renders.py
19
renders.py
|
|
@ -38,7 +38,7 @@ import zipfile
|
|||
import StringIO
|
||||
import xml.dom.minidom
|
||||
from os.path import isfile
|
||||
from jinja2 import Template as TemplateEngine
|
||||
from jinja2 import Environment, Template as TemplateEngine
|
||||
|
||||
|
||||
PARAGRAPH_TAG = '{% control_paragraph %}'
|
||||
|
|
@ -49,6 +49,18 @@ OOO_PARAGRAPH_NODE = 'text:p'
|
|||
OOO_TABLEROW_NODE = 'table:table-row'
|
||||
OOO_TABLECELL_NODE = 'table:table-cell'
|
||||
|
||||
|
||||
# ************************************************
|
||||
#
|
||||
# SECRETARY FILTERS
|
||||
#
|
||||
# ************************************************
|
||||
|
||||
def pad_string(value, length=5):
|
||||
value = str(value)
|
||||
return value.zfill(length)
|
||||
|
||||
|
||||
class BaseRender():
|
||||
"""
|
||||
Prapares a XML string or file to be processed by a templating system.
|
||||
|
|
@ -94,7 +106,10 @@ class BaseRender():
|
|||
to do the actual rendering.
|
||||
"""
|
||||
|
||||
template = TemplateEngine(self.xml_document.toxml())
|
||||
environment = Environment()
|
||||
environment.filters['pad'] = pad_string
|
||||
|
||||
template = environment.from_string(self.xml_document.toxml())
|
||||
rendered = template.render(**self.template_vars)
|
||||
|
||||
# Replace all \n in field values with a ODT line break
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue