improved html tag stripping
This commit is contained in:
@@ -53,6 +53,14 @@ def textify(html):
|
|||||||
# Strip single spaces in the beginning of each line
|
# Strip single spaces in the beginning of each line
|
||||||
return text_only.replace('\n ', '\n').strip()
|
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):
|
def newlinetobr(html):
|
||||||
html = html.replace('\n\n','<br>')
|
html = html.replace('\n\n','<br>')
|
||||||
return html.replace('\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)
|
html_content = htmly.render(context)
|
||||||
text_content = textify(html_content)
|
text_content = textify(html_content)
|
||||||
html_content = newlinetobr(html_content)
|
# html_content = newlinetobr(html_content)
|
||||||
|
|
||||||
if 'cc' in kwargs:
|
if 'cc' in kwargs:
|
||||||
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email,cc=kwargs['cc'])
|
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email,cc=kwargs['cc'])
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ from rowers.models import (
|
|||||||
|
|
||||||
from rowers.courses import get_time_course
|
from rowers.courses import get_time_course
|
||||||
|
|
||||||
|
from rowers.emails import htmlstrip,htmlstripnobr
|
||||||
|
|
||||||
import rowers.mytypes as mytypes
|
import rowers.mytypes as mytypes
|
||||||
|
|
||||||
import metrics
|
import metrics
|
||||||
@@ -616,6 +618,7 @@ def update_plannedsession(ps,cd):
|
|||||||
def update_indoorvirtualrace(ps,cd):
|
def update_indoorvirtualrace(ps,cd):
|
||||||
for attr, value in cd.items():
|
for attr, value in cd.items():
|
||||||
if attr == 'comment':
|
if attr == 'comment':
|
||||||
|
value = htmlstripnobr(value)
|
||||||
value.replace("\r\n", "
");
|
value.replace("\r\n", "
");
|
||||||
value.replace("\n", "
");
|
value.replace("\n", "
");
|
||||||
setattr(ps, attr, value)
|
setattr(ps, attr, value)
|
||||||
@@ -666,6 +669,7 @@ def update_indoorvirtualrace(ps,cd):
|
|||||||
def update_virtualrace(ps,cd):
|
def update_virtualrace(ps,cd):
|
||||||
for attr, value in cd.items():
|
for attr, value in cd.items():
|
||||||
if attr == 'comment':
|
if attr == 'comment':
|
||||||
|
value = htmlstripnobr(value)
|
||||||
value.replace("\r\n", "
");
|
value.replace("\r\n", "
");
|
||||||
value.replace("\n", "
");
|
value.replace("\n", "
");
|
||||||
setattr(ps, attr, value)
|
setattr(ps, attr, value)
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ from django.utils import timezone
|
|||||||
from django.utils.html import strip_tags
|
from django.utils.html import strip_tags
|
||||||
|
|
||||||
from utils import deserialize_list,ewmovingaverage,wavg
|
from utils import deserialize_list,ewmovingaverage,wavg
|
||||||
|
from emails import htmlstrip
|
||||||
|
|
||||||
from HTMLParser import HTMLParser
|
from HTMLParser import HTMLParser
|
||||||
class MLStripper(HTMLParser):
|
class MLStripper(HTMLParser):
|
||||||
@@ -819,7 +820,7 @@ def handle_send_disqualification_email(
|
|||||||
'username':username,
|
'username':username,
|
||||||
'reason':reason,
|
'reason':reason,
|
||||||
'siteurl':siteurl,
|
'siteurl':siteurl,
|
||||||
'message': strip_tags(message),
|
'message': htmlstrip(message),
|
||||||
'racename':racename,
|
'racename':racename,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
</table>
|
</table>
|
||||||
<p>
|
<p>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input class="button green" type="submit" value="Submit">
|
<input type="submit" value="Submit">
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ import pandas as pd
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
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 pytz import timezone as tz,utc
|
||||||
from timezonefinder import TimezoneFinder
|
from timezonefinder import TimezoneFinder
|
||||||
|
|||||||
Reference in New Issue
Block a user