Skip to content

Image

hypha.apply.utils.image

image_url_cache_key

image_url_cache_key(image_id, spec)
Source code in hypha/apply/utils/image.py
def image_url_cache_key(image_id, spec):
    return f"image_url_cache_{image_id}_{spec}"

generate_image_url

generate_image_url(image, filter_spec)
Source code in hypha/apply/utils/image.py
def generate_image_url(image, filter_spec):
    cache_key = image_url_cache_key(image.id, filter_spec)
    url = cache.get(cache_key)
    if url:
        return url
    from wagtail.images.views.serve import generate_signature

    signature = generate_signature(image.id, filter_spec)
    url = reverse("wagtailimages_serve", args=(signature, image.id, filter_spec))
    url += image.file.name[len("original_images/") :]
    cache.set(cache_key, url)
    return url

generate_image_tag

generate_image_tag(image, filter_spec, html_class='')
Source code in hypha/apply/utils/image.py
def generate_image_tag(image, filter_spec, html_class=""):
    url = generate_image_url(image, filter_spec)
    return format_html(f'<img alt="{image.title}" class="{html_class}"src="{url}">')