o
    &Zc                     @   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 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ejv rpzd dlmZ W n
 eyg   Y dS w eg dg dS dS )    )unicode_literals)settings)models)class_prepared   )ProcessedImageFieldFile)ImageSpecFileDescriptor   )SpecHost)ImageFieldSourceGroup)registerc                       s   e Zd Z fddZ  ZS )SpecHostFieldc                    s>   t | dd }|sd|jj|jj|f  }tt| | d S )Nspec_idz%s:%s:%s)getattr_meta	app_labelobject_namelowersuperr   set_spec_id)selfclsnamer   	__class__ T/var/www/jaguar/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_group4   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>C   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   r1   r   r   handle_model_preparationA   s   zDImageSpecField.contribute_to_class.<locals>.handle_model_preparationF)r;   weak)r,   r   connect)r   r   r   r>   r   )r   r   r1   r   r   contribute_to_class1   s
   z"ImageSpecField.contribute_to_class
NNNNNNNNNN)r   r   r    __doc__r+   rA   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   r3   )r   r#   r$   r%   verbose_namer   width_fieldheight_fieldr'   r*   r   r<   r   r   r   r+   ^   s   

zProcessedImageField.__init__c                    s   |  || tt| ||S r.   )r   r   rD   rA   )r   r   r   r   r   r   rA   r   s   z'ProcessedImageField.contribute_to_classrB   )	r   r   r    rC   r   
attr_classr+   rA   r!   r   r   r   r   rD   T   s    
rD   south)add_introspection_rulesz/^imagekit\.models\.fields\.ProcessedImageField$N)
__future__r   django.confr   	django.dbr   django.db.models.signalsr   filesr   utilsr   specsr
   specs.sourcegroupsr   registryr   r   r"   r3   rD   INSTALLED_APPSsouth.modelsinspectorrJ   ImportErrorr   r   r   r   <module>   s(    8
$