a
    DøgÝ  ã                   @   sD   d dl mZ d dlmZ ddlmZ ddlmZ G dd„ deƒZdS )	é    )ÚOrderedDict)ÚFieldé   )ÚSourceImageIOError)Úto_svg_safe_specc                       s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )ÚImageRenditionFielda:  
    A field that generates a rendition with the specified filter spec, and serialises
    details of that rendition.

    Example:
    "thumbnail": {
        "url": "/media/images/myimage.max-165x165.jpg",
        "full_url": "https://media.example.com/media/images/myimage.max-165x165.jpg",
        "width": 165,
        "height": 100,
        "alt": "Image alt text"
    }

    If there is an error with the source image. The dict will only contain a single
    key, "error", indicating this error:

    "thumbnail": {
        "error": "SourceImageIOError"
    }
    Fc                    s"   || _ || _tƒ j|i |¤Ž d S )N)Úfilter_specÚpreserve_svgÚsuperÚ__init__)Úselfr   r	   ÚargsÚkwargs©Ú	__class__© úX/var/www/lab.imftr.de/x/nb_venv/lib/python3.9/site-packages/wagtail/images/api/fields.pyr      s    zImageRenditionField.__init__c                 C   s~   z\|  ¡ r| jrt| jƒ}n| j}| |¡}td|jfd|jfd|jfd|j	fd|j
fgƒW S  tyx   tdgƒ Y S 0 d S )NÚurlÚfull_urlÚwidthÚheightÚalt)Úerrorr   )Zis_svgr	   r   r   Zget_renditionr   r   r   r   r   r   r   )r   Úimager   Z	thumbnailr   r   r   Úto_representation$   s$    
ûÿ	ÿÿz%ImageRenditionField.to_representation)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__classcell__r   r   r   r   r   	   s   r   N)	Úcollectionsr   Zrest_framework.fieldsr   Úmodelsr   Úutilsr   r   r   r   r   r   Ú<module>   s   