ó
Ń7ec           @   sL  d  d l  m Z d  d l Z d  d l m Z m Z m Z d  d l m Z d  d l	 m
 Z
 m Z d  d l m Z d  d l m Z d   Z d	   Z d
   Z d d  Z d e d  Z d   Z e j e  e j e  e j e  d e j k r>y4 d  d l m Z m Z e j e  e j e  Wq>e k
 r:q>Xn  e d  d S(   i˙˙˙˙(   t   FileSystemStorageN(   t	   post_savet   post_deletet   pre_save(   t	   FileField(   t   ObjectDoesNotExistt   MultipleObjectsReturned(   t   settings(   t   IMAGE_CACHE_STORAGEc         C   s^   t  t t  rM t j j t j |   } t j j |  rM t j |  d  Sn  t j	 |   d  S(   N(
   t
   isinstanceR   R    t   ost   patht   joint   locationt   isdirt   rmdirt   delete(   R   t	   full_path(    (    s6   /usr/local/lib/python2.7/dist-packages/image/models.pyt   safe_delete   s    c         C   sŁ   y t  j |   } Wn t k
 r& n] Xx+ | d D] } t t j j |  |   q2 Wx+ | d D] } t t j j |  |   q` Wt  j |   r t |   n  d  S(   Ni    i   (   R   t   listdirt   OSErrorR   R
   R   R   t   exists(   t   dir_patht   contentst	   directoryt   filename(    (    s6   /usr/local/lib/python2.7/dist-packages/image/models.pyt   remove_directory   s    c         C   s   |  r t  |   n  d  S(   N(   R   (   t
   image_path(    (    s6   /usr/local/lib/python2.7/dist-packages/image/models.pyt   remove_cache%   s    c         K   sĽ   | d  k r d  Si  | _ d  } x | j j D]q } t | t  r, | s y |  j j d | j  } Wq t	 t
 f k
 r} d  SXn  | j |  | j | j <q, q, Wd  S(   Nt   pk(   t   Nonet   old_image_fieldst   _metat   fieldsR	   R   t   objectst   getR   R   R   t   value_to_stringt   attname(   t   sendert   instancet   kwargst   old_instancet   field(    (    s6   /usr/local/lib/python2.7/dist-packages/image/models.pyt   prepare_image_cache_cleanup*   s    	c         K   s}   | r
 d  S| d  k r d  Sx\ | j j D]N } t | t  r' | j | j | j |  k ru t | j | j  qu q' q' Wd  S(   N(	   R   R    R!   R	   R   R   R%   R$   R   (   R&   R'   t   createdR(   R*   (    (    s6   /usr/local/lib/python2.7/dist-packages/image/models.pyt"   clear_prepared_image_cache_cleanup<   s    c         K   s@   x9 | j  j D]+ } t | t  r t | j |   q q Wd  S(   N(   R    R!   R	   R   R   R$   (   R&   R'   R(   R*   (    (    s6   /usr/local/lib/python2.7/dist-packages/image/models.pyt   clear_image_cacheG   s    t	   reversion(   t   pre_revision_committ   post_revision_commits   actuality/file0001116000079.jpg(   t   django.core.files.storageR    R
   t   django.db.models.signalsR   R   R   t   django.db.models.fields.filesR   t   django.core.exceptionsR   R   t   django.confR   t   django_settingst   image.storageR   R   R   R   R   R+   t   FalseR-   R.   t   connectt   INSTALLED_APPSt   reversion.modelsR0   R1   t   ImportError(    (    (    s6   /usr/local/lib/python2.7/dist-packages/image/models.pyt   <module>   s.   					