<s> from cuddlybuddly . thumbnail . processors import CropToFitProcessor , ResizeProcessor <EOL> LOADING = False <EOL> PROCESSORS = { <EOL> '<STR_LIT>' : CropToFitProcessor , <EOL> '<STR_LIT>' : ResizeProcessor <EOL> } <EOL> DEFAULT_PROCESSOR = ResizeProcessor <EOL> def register_processor ( name , processor , default = False ) : <EOL> global PROCESSORS <EOL> PROCESSORS [ name ] = processor <EOL> if default : <EOL> global DEFAULT_PROCESSOR <EOL> DEFAULT_PROCESSOR = processor <EOL> def get_processor ( name ) : <EOL> return PROCESSORS . get ( name , DEFAULT_PROCESSOR ) <EOL> def get_default_processor ( ) : <EOL> return DEFAULT_PROCESSOR <EOL> def autodiscover ( ) : <EOL> from django . conf import settings <EOL> cache = getattr ( settings , '<STR_LIT>' , None ) <EOL> if cache is None : <EOL> return <EOL> global LOADING <EOL> if LOADING : <EOL> return <EOL> LOADING = True <EOL> import imp <EOL> from django . db . models import Model <EOL> from django . db . models . base import ModelBase <EOL> from django . db . models . fields . files import FieldFile <EOL> from django . db . models . signals import post_save , pre_delete <EOL> from django . utils . importlib import import_module <EOL> from cuddlybuddly . thumbnail . listeners import update_cache <EOL> for app in settings . INSTALLED_APPS : <EOL> try : <EOL> app_path = import_module ( app ) . __path__ <EOL> except AttributeError : <EOL> continue <EOL> try : <EOL> imp . find_module ( '<STR_LIT>' , app_path ) <EOL> except ImportError : <EOL> continue <EOL> models = import_module ( "<STR_LIT>" % app ) <EOL> for model in models . __dict__ . values ( ) : <EOL> if isinstance ( model , ModelBase ) and model is not Model : <EOL> modelinit = model ( ) <EOL> for field in modelinit . __dict__ . keys ( ) : <EOL> if isinstance ( getattr ( modelinit , field , None ) , FieldFile ) : <EOL> post_save . connect ( update_cache , sender = model ) <EOL> pre_delete . connect ( update_cache , sender = model ) <EOL> LOADING = False </s>
