From b5093905759f246176ca9f8992fb99cbb4aa9739 Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Wed, 13 May 2009 06:24:52 +0100 Subject: [svn] Switch from photologue to imagekit. Less bloat. Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8338 by cucc @ 5/11/2009 3:08 AM --- imagekit/management/commands/ikflush.py | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 imagekit/management/commands/ikflush.py (limited to 'imagekit/management/commands/ikflush.py') diff --git a/imagekit/management/commands/ikflush.py b/imagekit/management/commands/ikflush.py new file mode 100644 index 0000000..c03440f --- /dev/null +++ b/imagekit/management/commands/ikflush.py @@ -0,0 +1,38 @@ +from django.db.models.loading import cache +from django.core.management.base import BaseCommand, CommandError +from optparse import make_option +from imagekit.models import ImageModel +from imagekit.specs import ImageSpec + + +class Command(BaseCommand): + help = ('Clears all ImageKit cached files.') + args = '[apps]' + requires_model_validation = True + can_import_settings = True + + def handle(self, *args, **options): + return flush_cache(args, options) + +def flush_cache(apps, options): + """ Clears the image cache + + """ + apps = [a.strip(',') for a in apps] + if apps: + print 'Flushing cache for %s...' % ', '.join(apps) + else: + print 'Flushing caches...' + + for app_label in apps: + app = cache.get_app(app_label) + models = [m for m in cache.get_models(app) if issubclass(m, ImageModel)] + + for model in models: + for obj in model.objects.all(): + for spec in model._ik.specs: + prop = getattr(obj, spec.name(), None) + if prop is not None: + prop._delete() + if spec.pre_cache: + prop._create() -- cgit v1.2.3