Skip to content

meringue.thumbnail.dummy ¤

Dummy image returned instead of a thumbnail that can't be made or is not ready yet.

get_dummy_image_url ¤

get_dummy_image_url(
    job_chain: JobChainType | None = None,
) -> str

Returns the dummy image url used instead of a thumbnail that can't be made (an error, a missing source file) or is not ready yet (it is being made by another process).

In DEBUG mode the url is made from THUMBNAIL_DUMMYIMAGE_TEMPLATE, otherwise from THUMBNAIL_DUMMYIMAGE_URL ({static_url}images/noise.png by default). Both support {static_url} (STATIC_URL at the moment of the call), {width} and {height} (the final size of the job chain, 42x42 if there is none) placeholders.

Attributes:

  • job_chain –

    Thumbnail job chain (used to get the dummy size).

Returns:

  • str –

    Dummy image url.

Examples:

from meringue.thumbnail.dummy import get_dummy_image_url

get_dummy_image_url(["s:300x200", "resize"])
Source code in meringue/thumbnail/dummy.py
def get_dummy_image_url(job_chain: JobChainType | None = None) -> str:
    """
    Returns the dummy image url used instead of a thumbnail that can't be made (an error, a missing
    source file) or is not ready yet (it is being made by another process).

    In `DEBUG` mode the url is made from `THUMBNAIL_DUMMYIMAGE_TEMPLATE`, otherwise from
    `THUMBNAIL_DUMMYIMAGE_URL` (`{static_url}images/noise.png` by default). Both support
    `{static_url}` (`STATIC_URL` at the moment of the call), `{width}` and `{height}`
    (the final size of the job chain, `42x42` if there is none) placeholders.

    Attributes:
        job_chain: Thumbnail job chain (used to get the dummy size).

    Returns:
        Dummy image url.

    Examples:
        ```py
        from meringue.thumbnail.dummy import get_dummy_image_url

        get_dummy_image_url(["s:300x200", "resize"])
        ```
    """

    size = (42, 42)
    final_size = re.compile(r"s:(\d+)x(\d+)")
    for task in reversed(job_chain or []):
        try:
            size = final_size.search(task).groups()
            break
        except AttributeError:
            pass

    if settings.DEBUG:
        template = m_settings.THUMBNAIL_DUMMYIMAGE_TEMPLATE
    else:
        template = m_settings.THUMBNAIL_DUMMYIMAGE_URL

    return template.format(static_url=settings.STATIC_URL or "", width=size[0], height=size[1])