Introducing pad filter.

This commit is contained in:
Christopher Ramírez 2013-07-18 15:10:34 -06:00
parent 1ad6849be2
commit c32ff51032

View file

@ -38,7 +38,7 @@ import zipfile
import StringIO import StringIO
import xml.dom.minidom import xml.dom.minidom
from os.path import isfile from os.path import isfile
from jinja2 import Template as TemplateEngine from jinja2 import Environment, Template as TemplateEngine
PARAGRAPH_TAG = '{% control_paragraph %}' PARAGRAPH_TAG = '{% control_paragraph %}'
@ -49,6 +49,18 @@ OOO_PARAGRAPH_NODE = 'text:p'
OOO_TABLEROW_NODE = 'table:table-row' OOO_TABLEROW_NODE = 'table:table-row'
OOO_TABLECELL_NODE = 'table:table-cell' OOO_TABLECELL_NODE = 'table:table-cell'
# ************************************************
#
# SECRETARY FILTERS
#
# ************************************************
def pad_string(value, length=5):
value = str(value)
return value.zfill(length)
class BaseRender(): class BaseRender():
""" """
Prapares a XML string or file to be processed by a templating system. Prapares a XML string or file to be processed by a templating system.
@ -94,7 +106,10 @@ class BaseRender():
to do the actual rendering. 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) rendered = template.render(**self.template_vars)
# Replace all \n in field values with a ODT line break # Replace all \n in field values with a ODT line break