
    h
                     J    d dl mZ d dlmZ d dlmZ d dlmZ  G d de      Zy)    )ClearableFileInput)	mark_safe)get_thumbnailer)settingsc                   D     e Zd ZdZdZdZd fd	Zd Zd Zd fd	Z	 xZ
S )	ImageClearableFileInputa  
    Use this widget to show a thumbnail of the image next to the image file.

    If using the admin and :class:`~easy_thumbnails.fields.ThumbnailerField`,
    you can use this widget automatically with the following code::

        class MyModelAdmin(admin.ModelAdmin):
            formfield_overrides = {
                ThumbnailerField: {'widget': ImageClearableFileInput},
            }
    z1%(clear_template)s<br />%(input_text)s: %(input)szH%(template)s<br /><a href="%(source_url)s" target="_blank">%(thumb)s</a>c                     |xs t         j                  }|j                         }d|vrd|d<   || _        t        |   |       y)aq  
        Set up the thumbnail options for this widget.

        :param thumbnail_options: options used to generate the thumbnail. If no
            ``size`` is given, it'll be ``(80, 80)``. If not provided at all,
            default options will be used from the
            :attr:`~easy_thumbnails.conf.Settings.THUMBNAIL_WIDGET_OPTIONS`
            setting.
        size)P   r   N)r   THUMBNAIL_WIDGET_OPTIONScopythumbnail_optionssuper__init__)selfr   attrs	__class__s      G/home/dcms/DCMS/lib/python3.12/site-packages/easy_thumbnails/widgets.pyr   z ImageClearableFileInput.__init__   sP     B!B!B 	-224**(0f%!2    c                     d|z  S )Nz%s_thumb_id )r   names     r   thumbnail_idz$ImageClearableFileInput.thumbnail_id0   s    t##r   c                     t        ||j                        }|j                  |_        t	        |d      r|j
                  |_        |j                  | j                        S )Nthumbnail_storage)r   r   storagesource_storagehasattrr   get_thumbnailr   )r   valuethumbnailers      r   r   z%ImageClearableFileInput.get_thumbnail3   sN    %eUZZ8%*]]"5-.,1,C,CK)(()?)?@@r   c                 *   t         |   ||||      }|rt        |d      s|S | j                  |      }||j	                  | j                  |            |j                  j                  |j                        d}t        | j                  |z        S )Nr   )id)templatethumb
source_url)r   renderr   r   tagr   r   urlr   r   template_with_thumbnail)	r   r   r    r   rendereroutputr%   substitutionr   s	           r   r'   zImageClearableFileInput.render:   s    eUH=GE95M""5)YY$"3"3D"9Y:--++EJJ7

 55DEEr   )NN)__name__
__module____qualname____doc__template_with_initialr*   r   r   r   r'   __classcell__)r   s   @r   r   r      s9    
	$ 
	A 
 $$A
F 
Fr   r   N)	django.forms.widgetsr   django.utils.safestringr   easy_thumbnails.filesr   easy_thumbnails.confr   r   r   r   r   <module>r8      s     3 - 1 )<F0 <Fr   