a
    9XhS                     @   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 rt }t D ]j}| |s| jd|  z|| W q ty } z$| jd| d|  W Y d }~qd }~0 0 q| jd n| jd d S )NZCKEDITOR_IMAGE_BACKENDzCreating thumbnail for %szCouldn't create thumbnail for z: ZFinishedzNo thumbnail backend is enabled)	getattrr   r   r   _thumbnail_existsstdoutwriteZcreate_thumbnail	Exception)selfargsoptionsbackendimagee r   /var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/ckeditor_uploader/management/commands/generateckeditorthumbnails.pyhandle   s    

0zCommand.handlec                 C   s   |  t|}tj|S N)_to_absolute_pathr   ospathisfile)r   
image_pathZ
thumb_pathr   r   r   r	      s    zCommand._thumbnail_existsc                 C   s   t jtj| S r   )r   r   joinr   Z
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   Zdjango.confr   Zdjango.core.management.baser   Zckeditor_uploader.backendsr   Zckeditor_uploader.utilsr   Zckeditor_uploader.viewsr   r   r   r   r   r   <module>   s   