Private
Public Access
1
0

improved html tag stripping

This commit is contained in:
Sander Roosendaal
2018-12-12 10:34:12 +01:00
parent 3a06408d3f
commit 6da4c36c68
5 changed files with 17 additions and 4 deletions

View File

@@ -53,6 +53,14 @@ def textify(html):
# Strip single spaces in the beginning of each line
return text_only.replace('\n ', '\n').strip()
def htmlstripnobr(html):
safe_html = re.sub('[ \t]+', ' ', strip_tags(html))
return safe_html
def htmlstrip(html):
safe_html = re.sub('[ \t]+', ' ', strip_tags(html))
return newlinetobr(safe_html)
def newlinetobr(html):
html = html.replace('\n\n','<br>')
return html.replace('\n','<br>')
@@ -65,7 +73,7 @@ def send_template_email(from_email,to_email,subject,
html_content = htmly.render(context)
text_content = textify(html_content)
html_content = newlinetobr(html_content)
# html_content = newlinetobr(html_content)
if 'cc' in kwargs:
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email,cc=kwargs['cc'])

View File

@@ -25,6 +25,8 @@ from rowers.models import (
from rowers.courses import get_time_course
from rowers.emails import htmlstrip,htmlstripnobr
import rowers.mytypes as mytypes
import metrics
@@ -616,6 +618,7 @@ def update_plannedsession(ps,cd):
def update_indoorvirtualrace(ps,cd):
for attr, value in cd.items():
if attr == 'comment':
value = htmlstripnobr(value)
value.replace("\r\n", "&#10");
value.replace("\n", "&#10");
setattr(ps, attr, value)
@@ -666,6 +669,7 @@ def update_indoorvirtualrace(ps,cd):
def update_virtualrace(ps,cd):
for attr, value in cd.items():
if attr == 'comment':
value = htmlstripnobr(value)
value.replace("\r\n", "&#10");
value.replace("\n", "&#10");
setattr(ps, attr, value)

View File

@@ -40,6 +40,7 @@ from django.utils import timezone
from django.utils.html import strip_tags
from utils import deserialize_list,ewmovingaverage,wavg
from emails import htmlstrip
from HTMLParser import HTMLParser
class MLStripper(HTMLParser):
@@ -819,7 +820,7 @@ def handle_send_disqualification_email(
'username':username,
'reason':reason,
'siteurl':siteurl,
'message': strip_tags(message),
'message': htmlstrip(message),
'racename':racename,
}

View File

@@ -39,7 +39,7 @@
</table>
<p>
{% csrf_token %}
<input class="button green" type="submit" value="Submit">
<input type="submit" value="Submit">
</p>
</li>
</ul>

View File

@@ -186,7 +186,7 @@ import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from rowers.emails import send_template_email
from rowers.emails import send_template_email,htmlstrip
from pytz import timezone as tz,utc
from timezonefinder import TimezoneFinder