From 9c02e2913ea552ee0c4157d5e2ee2c6e7c2ee2f1 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 27 Aug 2018 10:51:18 +0000 Subject: [PATCH] sanitze fallback --- content/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/content/models.py b/content/models.py index 069e9b6..2157031 100644 --- a/content/models.py +++ b/content/models.py @@ -21,7 +21,11 @@ import lxml.html # Create your models here. def sanitize_html(string): - return '\n'.join(lxml.html.tostring(x) for x in lxml.html.fragment_fromstring(string).iterchildren()) + try: + html = '\n'.join(lxml.html.tostring(x) for x in lxml.html.fragment_fromstring(string).iterchildren()) + except: + html = ox.strip_tags(string.replace('
', '\n')).replace('\n\n', '\n').replace('\n', '
') + return html class Acrolike(models.Model): title = models.CharField(max_length=255)