ó
P'^c           @  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 e f d     YZ d e f d     YZ d e j e f d     YZ y d  d l m Z Wn e k
 rï n Xe g  d g  d S(   iĸĸĸĸ(   t   unicode_literals(   t   models(   t   class_preparedi   (   t   ProcessedImageFieldFile(   t   ImageSpecFileDescriptori   (   t   SpecHost(   t   ImageFieldSourceGroup(   t   registert   SpecHostFieldc           B  s   e  Z d    Z RS(   c         C  sZ   t  |  d d   } | s@ d | j j | j j | f j   } n  t t |   j |  d  S(   Nu   spec_idu   %s:%s:%s(	   t   getattrt   Nonet   _metat	   app_labelt   object_namet   lowert   superR   t   set_spec_id(   t   selft   clst   namet   spec_id(    (    sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyt   _set_spec_id   s
    (   t   __name__t
   __module__R   (    (    (    sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyR      s   t   ImageSpecFieldc           B  s>   e  Z d  Z d d d d d d d d d d d 
 Z d   Z RS(   u   
    The heart and soul of the ImageKit library, ImageSpecField allows you to add
    variants of uploaded images to your models.

    c         C  sP   t  j |  d | d | d | d | d | d | d | d |	 d	 |
 	| |  _ d  S(
   Nt
   processorst   formatt   optionst   cachefile_storaget   autoconvertt   cachefile_backendt   cachefile_strategyt   specR   (   R   t   __init__t   source(   R   R   R   R   R"   R   R   R   R   R    t   id(    (    sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyR!   !   s    c           s`       f d     j  r.   j   n.     f d   } t j | d   d t d  S(   Nc           sL   t     t   |     j     t j  j t   |    d  S(   N(   t   setattrR   R   R   t   source_groupR   R   (   R"   (   R   R   R   (    sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyt   register_source_group3   s    c           sĒ   g    j  j D]! } t | t j  r | j ^ q } t |  d k rb t d   j  f   n. t |  d k r t d   j  f   n   | d  d  S(   Ni    uU   %s does not define any ImageFields, so your %s ImageSpecField has no image to act on.i   u`   %s defines multiple ImageFields, but you have not specified a source for your %s ImageSpecField.(	   R   t   fieldst
   isinstanceR   t
   ImageFieldt   attnamet   lent	   ExceptionR   (   t   sendert   kwargst   ft   image_fields(   R   R   R&   (    sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyt   handle_model_preparation@   s    !R-   t   weak(   R"   R   t   connectt   False(   R   R   R   R1   (    (   R   R   R&   R   sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyt   contribute_to_class0   s
    	N(   R   R   t   __doc__R
   R!   R5   (    (    (    sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyR      s   			t   ProcessedImageFieldc           B  sD   e  Z d  Z e Z d d d d d d d e d d d 
 Z d   Z RS(   u  
    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.

    c         K  sT   t  j |  d | d | d | d | d |	 d |
 t j j |  | | | | |  d S(   u  
        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`.

        R   R   R   R   R    R   N(   R   R!   R   R)   (   R   R   R   R   t   verbose_nameR   t   width_fieldt   height_fieldR   R    R   R.   (    (    sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyR!   ]   s
    
c         C  s)   |  j  | |  t t |   j | |  S(   N(   R   R   R7   R5   (   R   R   R   (    (    sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyR5   m   s    N(	   R   R   R6   R   t
   attr_classR
   t   TrueR!   R5   (    (    (    sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyR7   S   s   	(   t   add_introspection_rulesu/   ^imagekit\.models\.fields\.ProcessedImageField$N(   t
   __future__R    t	   django.dbR   t   django.db.models.signalsR   t   filesR   t   utilsR   t   specsR   t   specs.sourcegroupsR   t   registryR   R   R   R)   R7   t   south.modelsinspectorR=   t   ImportError(    (    (    sA   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/models/fields/__init__.pyt   <module>   s   8