@@ -60,7 +60,7 @@
 | 
			
		||||
            </li>
 | 
			
		||||
          </ul>
 | 
			
		||||
        </header>
 | 
			
		||||
        <div>{{ object.message | safe }}</div>
 | 
			
		||||
        <div>{{ object.message | remove_oembed | safe }}</div>
 | 
			
		||||
      </article>
 | 
			
		||||
      <article>
 | 
			
		||||
        {% if object.message_type == "from_contributor" or object.message_type == "from_contrib_no_msg" %}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,7 @@ from django.templatetags.static import static
 | 
			
		||||
from django.urls import reverse_lazy
 | 
			
		||||
from django.utils.html import strip_tags
 | 
			
		||||
from django.utils.safestring import mark_safe
 | 
			
		||||
from bs4 import BeautifulSoup
 | 
			
		||||
 | 
			
		||||
register = template.Library()
 | 
			
		||||
 | 
			
		||||
@@ -280,3 +281,17 @@ def navigation_links(filter, category, calendar, current_view):
 | 
			
		||||
def per_day(nb, month):
 | 
			
		||||
    weekday, number_of_days = calendar.monthrange(month.year, month.month)
 | 
			
		||||
    return "%.1f" % (nb / number_of_days)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@register.filter
 | 
			
		||||
def remove_oembed(html):
 | 
			
		||||
    soup = BeautifulSoup(html, "html.parser")
 | 
			
		||||
 | 
			
		||||
    for f in soup.select("figure.media"):
 | 
			
		||||
        oe = f.select("oembed")
 | 
			
		||||
        if len(oe) == 1 and oe[0].has_attr("url"):
 | 
			
		||||
            a = soup.new_tag("a")
 | 
			
		||||
            a.attrs["href"] = oe[0].attrs["url"]
 | 
			
		||||
            a.string = oe[0].attrs["url"]
 | 
			
		||||
            f.replaceWith(a)
 | 
			
		||||
    return str(soup)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user