
    |{Ig                         d Z ddlmZ ddlmZ ddlmZ ddlmZ dZ	d Z
 ee
          Zd Z ee          Z ee          Zd	 Zd
 ZddZddZd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Z dS )zF Our local cache of filefields, everything is private to this package.    )defaultdict)apps)models)import_string_django_cleanup_original_cachec                      t                      S N)set     V/var/www/CMSBlueprintStation/venv/lib/python3.11/site-packages/django_cleanup/cache.pyfields_defaultr      s    55Lr   c                      i S r	   r   r   r   r   fields_dict_defaultr      s    Ir   c                 @   t           rdS t          j                    D ]}t          ||           rt	          |          }t          |          r2|j        }|                                D ]2}t          |t          j
                  rt          ||j        |           3dS )z/Prepare the cache for all models, non-reentrantN)FIELDSr   
get_modelsignore_modelget_model_namemodel_has_filefields_meta
get_fields
isinstancer   	FileFieldadd_field_for_modelname)select_modemodelr   optsfields        r   preparer!      s     "" 	= 	={++ 	e$$%% 	{__&& 	= 	=E%!122 =#D%*e<<<	=	= 	=r   c                     t           |                              |           t          |          t          |          |<   t          |j                  t
          |          |<   dS )z2Centralized function to make all our local caches.N)r   addget_dotted_pathFIELDS_FIELDSstorageFIELDS_STORAGE)
model_name
field_namer    s      r   r   r   +   sU     ::&&& -<E,B,BM*j)-<U]-K-KN:z***r   Nc              #      K   t          |           rDt          |          }|,t          |t                    sJ |                    |          }|D ]}|V  dS dS )z-Get the filefields for a model if it has themN)r   r   r   r
   
difference)r(   excludefieldsr)   s       r   get_fields_for_modelr.   9   s      J'' 
#gs+++++&&w//F  	 	J 	 	r   c              #      K   || }t          |           }|                                 }t          ||          D ]7}t          | |          }||                    ||j        |j                  fV  8dS )z
        Yields (name, descriptor) for each file field given an instance

        Can use the `using` kwarg to change the instance that the `FieldFile`
        will receive.
    N)r,   )r   get_deferred_fieldsr.   getattr	__class__r    r   )instanceusingr(   deferred_fieldsr)   	fieldfiles         r   fields_for_model_instancer7   F   s       }))J2244O*:OOO V V
Hj11	)--eY_inUUUUUUUV Vr   c                 B    t          t          |          |                   S )z$Restore a field from its dotted path)r   r%   r(   r)   s     r   	get_fieldr:   [   s    z2:>???r   c                 B    t          t          |          |                   S )z&Restore a storage from its dotted path)r   r'   r9   s     r   get_field_storager<   `   s    
3J?@@@r   c                 2    | j         }|j         d|j         S )z!get the dotted path for an object.)r2   
__module____qualname__)object_klasss     r   r$   r$   h   s$    E55!3555r   c                 2    | j         }|j         d|j         S )zreturns a unique model namer>   )r   	app_labelr(   r   opts     r   r   r   n   s!    
+Cm..cn...r   c                 6    | j         }d|j         d|j         dS )zOreturns a mangled attribute name specific to the model for ignore functionality____cleanup_ignorer   r(   rD   rE   s     r   get_mangled_ignorerL   t   &    
+C?s~??????r   c                 6    | j         }d|j         d|j         dS )zOreturns a mangled attribute name specific to the model for select functionalityrH   rI   _cleanup_selectrK   rE   s     r   get_mangled_selectrP   z   rM   r   c                     | t           v S )zCheck if a model has filefields)r   r(   s    r   r   r      s    r   c                 |    |rt          | t          |                      nt          | t          |                     S )z"Check if a model should be ignored)hasattrrP   rL   )r   r   s     r   r   r      sD     F 25 9 9::::#E+=e+D+DEEGr   c                 R    t          |           rt          | t                     dS dS )z!Remove the cache from an instanceN)	has_cachedelattr
CACHE_NAMEr3   s    r   remove_instance_cacherZ      s2     &*%%%%%& &r   c           
      r    || }t          | t          t          t          ||                                dS )z~
        Make the cleanup cache for an instance.

        Can also change the source of the data with the `source` kwarg.
    N)r4   )setattrrX   dictr7   )r3   sources     r   make_cleanup_cacher_      sJ     ~Hj$!&999#; #; < < < < <r   c                 ,    t          | t                    S )z&Check if an instance has a cache on it)rT   rX   rY   s    r   rV   rV      s    8Z(((r   c                 8    t          | t                    |         S )z)Get a value from the cache on an instance)r1   rX   )r3   r)   s     r   get_field_attrrb      s    8Z((44r   c               #   J   K   t           D ]} t          j        |           V  dS )z.Get all the models we have in the FIELDS cacheN)r   r   	get_modelrR   s    r   cleanup_modelsre      s8       ) )
nZ(((((() )r   c                  4    t                                           S )zGet a copy of the FIELDS cache)r   copyr   r   r   cleanup_fieldsrh      s    ;;==r   r	   )!__doc__collectionsr   django.appsr   	django.dbr   django.utils.module_loadingr   rX   r   r   r   r%   r'   r!   r   r.   r7   r:   r<   r$   r   rL   rP   r   r   rZ   r_   rV   rb   re   rh   r   r   r   <module>rn      s   L L # # # # # #             5 5 5 5 5 5 .
  	^	$	$  /00011= = ="L L L
 
 
 
V V V V*@ @ @
A A A6 6 6/ / /@ @ @@ @ @     
G G G& & &
< 
< 
< 
<) ) )
5 5 5) ) )    r   