Source code for collective.transmute.steps.image

"""
Pipeline steps for handling image conversion in ``collective.transmute``.

This module provides functions and async generator steps for converting image fields
into preview image links and managing image relations in the transformation pipeline.
These steps are used by ``collective.transmute`` for content types requiring
image conversion.
"""

from collective.transmute import _types as t
from collective.transmute.utils import item as utils


IMAGE_FIELDS: tuple[str, ...] = ("image", "preview_image")


[docs] def get_conversion_types(settings: t.TransmuteSettings) -> tuple[str, ...]: """ Get content types that require ``image`` to ``preview_image_link`` conversion. Parameters ---------- settings : TransmuteSettings The transmute settings object. Returns ------- tuple[str, ...] Tuple of content type strings. Example ------- .. code-block:: pycon >>> get_conversion_types(settings) ('News Item', 'Document') """ return settings.images["to_preview_image_link"]
[docs] def cleanup_image_fields(item: t.PloneItem) -> t.PloneItem: """ Remove image fields from an item. Parameters ---------- item : PloneItem The item to clean up. Returns ------- PloneItem The cleaned-up item without image fields. Example ------- .. code-block:: pycon >>> cleaned_item = cleanup_image_fields(item) >>> 'image' not in cleaned_item True >>> 'preview_image' not in cleaned_item True """ for image_field in IMAGE_FIELDS: item.pop(image_field, None) item.pop(f"{image_field}_caption", None) return item