Added compatibility with Python 2.7 as to the method escape_values.

This commit is contained in:
Max P 2018-11-07 17:38:57 -08:00
parent d5335cb36f
commit 4564fed0b3
4 changed files with 4 additions and 4 deletions

View File

@ -181,7 +181,7 @@ class DocxTemplate(object):
"""Escape string values of the passed :dict: `d` in-place """Escape string values of the passed :dict: `d` in-place
including nested dictionaries of any depth. including nested dictionaries of any depth.
""" """
for k, v in d.items(): for k, v in six.iteritems(d):
if isinstance(v, dict): if isinstance(v, dict):
identity = id(v) identity = id(v)
if identity not in identities: if identity not in identities:

View File

@ -3,10 +3,10 @@ from docxtpl import *
tpl = DocxTemplate("test_files/escape_tpl_auto.docx") tpl = DocxTemplate("test_files/escape_tpl_auto.docx")
context = {'myvar': R('"less than" must be escaped : <, this can be done with RichText() or R()'), context = {'myvar': R('"less than" must be escaped : <, this can be done with RichText() or R()'),
'myescvar':'It can be escaped with a "|e" jinja filter in the template too : < ', 'myescvar': 'It can be escaped with a "|e" jinja filter in the template too : < ',
'nlnp' : R('Here is a multiple\nlines\nstring\aand some\aother\aparagraphs\aNOTE: the current character styling is removed'), 'nlnp': R('Here is a multiple\nlines\nstring\aand some\aother\aparagraphs\aNOTE: the current character styling is removed'),
'mylisting': Listing('the listing\nwith\nsome\nlines\nand special chars : <>&'), 'mylisting': Listing('the listing\nwith\nsome\nlines\nand special chars : <>&'),
'autoescape': """These string should be auto escaped for an XML Word document which may contain <, >, &, ", and '.""" 'autoescape': """<, >, &, ", and '."""
} }
tpl.render(context, autoescape=True) tpl.render(context, autoescape=True)

Binary file not shown.