o
    vh                     @   s   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	 ddl
mZ dd	lmZ G d
d deZG dd deZG dd dejeZdS )    )models)class_prepared   )register)SpecHost)ImageFieldSourceGroup   )ProcessedImageFieldFile)ImageSpecFileDescriptorc                       s   e Zd Z fddZ  ZS )SpecHostFieldc                    s:   t | dd }|sd|jj|jj|f  }t | d S )Nspec_idz%s:%s:%s)getattr_meta	app_labelobject_namelowersuperset_spec_id)selfclsnamer   	__class__ ]/var/www/html/hyperkenya/venv/lib/python3.10/site-packages/imagekit/models/fields/__init__.py_set_spec_id   s   zSpecHostField._set_spec_id)__name__
__module____qualname__r   __classcell__r   r   r   r   r      s    r   c                   @   s*   e Zd ZdZ				dddZdd ZdS )ImageSpecFieldz
    The heart and soul of the ImageKit library, ImageSpecField allows you to add
    variants of uploaded images to your models.

    Nc                 C   s(   t j| ||||||||	|
d
 || _d S )N)	
processorsformatoptionscachefile_storageautoconvertcachefile_backendcachefile_strategyspecr   )r   __init__source)r   r!   r"   r#   r*   r$   r%   r&   r'   r(   idr   r   r   r)       s   

zImageSpecField.__init__c                    sH    fddj rj  d S  fdd}tj| dd d S )Nc                    s8   t  t|    tjt |  d S N)setattrr
   r   r   source_groupr   r   )r*   )r   r   r   r   r   register_source_group2   s   zAImageSpecField.contribute_to_class.<locals>.register_source_groupc                    s^   dd  j jD }t|dkrtd jf t|dkr'td jf |d  d S )Nc                 S   s   g | ]}t |tjr|jqS r   )
isinstancer   
ImageFieldattname).0fr   r   r   
<listcomp>A   s    
zXImageSpecField.contribute_to_class.<locals>.handle_model_preparation.<locals>.<listcomp>r   zU%s does not define any ImageFields, so your %s ImageSpecField has no image to act on.r   z`%s defines multiple ImageFields, but you have not specified a source for your %s ImageSpecField.)r   fieldslen	Exceptionr   )senderkwargsimage_fields)r   r   r/   r   r   handle_model_preparation?   s   zDImageSpecField.contribute_to_class.<locals>.handle_model_preparationF)r9   weak)r*   r   connect)r   r   r   r<   r   )r   r   r/   r   r   contribute_to_class/   s
   z"ImageSpecField.contribute_to_class
NNNNNNNNNN)r   r   r   __doc__r)   r?   r   r   r   r   r       s    
r    c                       s4   e Zd ZdZeZ			dddZ fddZ  ZS )ProcessedImageFielda  
    ProcessedImageField is an ImageField that runs processors on the uploaded
    image *before* saving it to storage. This is in contrast to specs, which
    maintain the original. Useful for coercing fileformats or keeping images
    within a reasonable size.

    Nc              	   K   sL   |	du r
|du r
d}t j| |||||	|
d tjj| ||||fi | dS )a  
        The ProcessedImageField constructor accepts all of the arguments that
        the :class:`django.db.models.ImageField` constructor accepts, as well
        as the ``processors``, ``format``, and ``options`` arguments of
        :class:`imagekit.models.ImageSpecField`.

        NT)r!   r"   r#   r%   r(   r   )r   r)   r   r1   )r   r!   r"   r#   verbose_namer   width_fieldheight_fieldr%   r(   r   r:   r   r   r   r)   \   s   

zProcessedImageField.__init__c                    s   |  || t ||S r,   )r   r   r?   )r   r   r   r   r   r   r?   p   s   z'ProcessedImageField.contribute_to_classr@   )	r   r   r   rA   r	   
attr_classr)   r?   r   r   r   r   r   rB   R   s    
rB   N)	django.dbr   django.db.models.signalsr   registryr   specsr   specs.sourcegroupsr   filesr	   utilsr
   r   r    r1   rB   r   r   r   r   <module>   s    8