Skip to content

Commit

Permalink
[FIX]docx文档打印时,如内容包含 & 符号会报错 osbzr#1543
Browse files Browse the repository at this point in the history
  • Loading branch information
floraXiao committed Jun 5, 2018
1 parent c87f4e0 commit 981e714
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion report_docx/report/report_docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def __getattr__(self, key):
return ""
temp = getattr(self.data, key)
field = self.data._fields.get(key)
if isinstance(temp, unicode) and ('&' in temp or '<' in temp or '>' in temp):
temp = temp.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')

if isinstance(temp, models.Model):
return DataModelProxy(temp)
Expand All @@ -89,7 +91,16 @@ def __iter__(self):

def __str__(self):
'''支持直接在word 上写 many2one 字段'''
return self.data and self.data.display_name or ''
name = ''
if self.data and self.data.display_name:
name = self.data.display_name
if '&' in self.data.display_name:
name = name.replace('&', '&amp;')
if '<' in self.data.display_name:
name = name.replace('<', '&lt;')
if '>' in self.data.display_name:
name = name.replace('>', '&gt;')
return name


class IterDataModelProxy(object):
Expand Down

0 comments on commit 981e714

Please sign in to comment.