o
    =gS                     @   sX   d dl Z d dlmZ 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 )	    N)settings)BaseCommand)get_backend)get_thumb_filename)get_image_filesc                   @   s,   e Zd ZdZdd Zdd Zedd ZdS )	Commandz
    Creates thumbnail files for the CKEditor file image browser.
    Useful if starting to use django-ckeditor with existing images.
    c                 O   s   t tdd rJt }t D ]5}| |sA| jd|  z|| W q ty@ } z| jd| d|  W Y d }~qd }~ww q| jd d S | jd d S )NCKEDITOR_IMAGE_BACKENDzCreating thumbnail for %szCouldn't create thumbnail for z: FinishedzNo thumbnail backend is enabled)	getattrr   r   r   _thumbnail_existsstdoutwritecreate_thumbnail	Exception)selfargsoptionsbackendimagee r   s/var/www/html/venv/lib/python3.10/site-packages/ckeditor_uploader/management/commands/generateckeditorthumbnails.pyhandle   s   

$zCommand.handlec                 C   s   |  t|}tj|S N)_to_absolute_pathr   ospathisfile)r   
image_path
thumb_pathr   r   r   r      s   zCommand._thumbnail_existsc                 C   s   t jtj| S r   )r   r   joinr   
MEDIA_ROOT)r   r   r   r   r   #   s   zCommand._to_absolute_pathN)__name__
__module____qualname____doc__r   r   staticmethodr   r   r   r   r   r      s    r   )r   django.confr   django.core.management.baser   ckeditor_uploader.backendsr   ckeditor_uploader.utilsr   ckeditor_uploader.viewsr   r   r   r   r   r   <module>   s    