data-import: fix UnicodeEncodeError on data import in python2 (#6448)

why is this not built into re by default?

Signed-off-by: Chinmay Pai <chinmaydpai@gmail.com>
This commit is contained in:
Chinmay Pai 2018-11-13 05:05:27 +00:00 committed by Rushabh Mehta
parent 8b08d1d5c5
commit 5f0dbecfed
2 changed files with 2 additions and 2 deletions

View file

@ -76,6 +76,6 @@ def format_value(value, df=None, doc=None, currency=None, translated=False):
elif df.get("fieldtype") in ("Text", "Small Text"):
if not re.search("(\<br|\<div|\<p)", value):
return value.replace("\n", "<br>")
return frappe.safe_decode(value).replace("\n", "<br>")
return value

View file

@ -290,7 +290,7 @@ def get_formatted_value(value, field):
if getattr(field, 'fieldtype', None) in ["Text", "Text Editor"]:
h = HTMLParser()
value = h.unescape(value)
value = h.unescape(frappe.safe_decode(value))
value = (re.subn(r'<[\s]*(script|style).*?</\1>(?s)', '', text_type(value))[0])
value = ' '.join(value.split())
return field.label + " : " + strip_html_tags(text_type(value))