Ejemplo n.º 1
0
 def get_description_display(self, device):
     html = etree.fromstring("<div>%s</div>" % self.description, parser=etree.HTMLParser())
     for img in html.findall(".//img"):
         eis = resize_external_image(img.attrib["src"], device.max_image_width - 10)
         if eis != None:
             img.attrib["src"] = eis.get_absolute_url()
             img.attrib["width"] = "%d" % eis.width
             img.attrib["height"] = "%d" % eis.height
     return etree.tostring(html.find(".//div"), method="html")[5:-6]
Ejemplo n.º 2
0
    def render(self, context):
        try:
            width = int(self.max_width.resolve(context))
        except Exception:
            width = float('inf')

        url, width = self.url.resolve(context), min(width, context['device'].max_image_width)
        
        try:
            eis = resize_external_image(url, width)
        except IOError:
            eis = None

        if self.just_url:
            return eis.get_absolute_url() if eis != None else url
        elif eis is None:
            return """<div class="backgrounded-image" style="background-image:url('%s');"> </div>""" % (eis.get_absolute_url() if eis != None else url)
        else:
            return """<div class="backgrounded-image" style="background-image:url('%s'); height:%dpx"> </div>""" % (eis.get_absolute_url(), eis.height)