示例#1
0
    def process(self, node):
        """If this node has a marker for an image in it, note where to get
        that image."""
        matches_by_text = defaultdict(list)
        for match in Graphics.gid.finditer(node.text):
            matches_by_text[match.group(0)].append(match)

        layer_el = []
        for text in matches_by_text:
            match = matches_by_text[text][0]
            url = content.ImageOverrides().get(
                match.group(2), settings.DEFAULT_IMAGE_URL % match.group(2))
            layer_el_vals = {
                'text': match.group(0),
                'url': url,
                'alt': match.group(1),
                'locations': list(range(len(matches_by_text[text])))
            }
            thumb_url = self.check_for_thumb(url)

            if thumb_url:
                layer_el_vals['thumb_url'] = thumb_url
            layer_el.append(layer_el_vals)

        if layer_el:
            return layer_el
示例#2
0
def gid_to_url(gid):
    """Take a few guesses as to where this image may be. This will be
    simplified once FR.gov adds image data to their API"""
    override = content.ImageOverrides().get(gid)
    if override and check_url(override):
        return override
    elif override:
        logger.warning("Overridden image 404s: %s->%s", gid, override)

    default = settings.DEFAULT_IMAGE_URL
    png = settings.DEFAULT_IMAGE_URL.replace('.gif', '.png')
    urls = [default % gid, default % gid.lower(), png % gid.lower()]
    for url in urls:
        if check_url(url):
            return url

    logger.warning("No image could be found for %s. Tried:\n%s", gid,
                   "\n".join(urls))
    return url  # last option
示例#3
0
 def content_obj(self):
     return content.ImageOverrides()