def thumbnails(html):
 from django.conf import settings
 from bs4 import BeautifulSoup
 from mezzanine.core.templatetags.mezzanine_tags import thumbnail
 if (settings.MEDIA_URL.lower() not in html.lower()):
  return html
 dom = BeautifulSoup(html, u'html.parser')
 for img in dom.findAll(u'img'):
  src = img.get(u'src', u'')
  src_in_media = src.lower().startswith(settings.MEDIA_URL.lower())
  width = img.get(u'width')
  height = img.get(u'height')
  if (src_in_media and width and height):
   img[u'src'] = (settings.MEDIA_URL + thumbnail(src, width, height))
 return str(dom).replace(u'</br>', u'')

def thumbnails ( html ) : from django . conf import settings from bs4 import BeautifulSoup from mezzanine . core . templatetags . mezzanine_tags import thumbnail if ( settings . MEDIA_URL . lower ( ) not in html . lower ( ) ) : return html dom = BeautifulSoup ( html , u'html.parser' ) for img in dom . findAll ( u'img' ) : src = img . get ( u'src' , u'' ) src_in_media = src . lower ( ) . startswith ( settings . MEDIA_URL . lower ( ) ) width = img . get ( u'width' ) height = img . get ( u'height' ) if ( src_in_media and width and height ) : img [ u'src' ] = ( settings . MEDIA_URL + thumbnail ( src , width , height ) ) return str ( dom ) . replace ( u'</br>' , u'' )
given a html string .