django-imagekit/imagekit/management/commands/ikflush.py
Matthew Tretter 3d810e7be5 Rename ImageSpecFile properties
`_obj` and `_spec` are now `instance` and `field`, to match FieldFile.
2011-09-22 18:13:32 -04:00

33 lines
1.1 KiB
Python

from django.db.models.loading import cache
from django.core.management.base import BaseCommand, CommandError
from optparse import make_option
from imagekit.utils import get_spec_files
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:
for app_label in apps:
app = cache.get_app(app_label)
for model in [m for m in cache.get_models(app)]:
print 'Flushing cache for "%s.%s"' % (app_label, model.__name__)
for obj in model.objects.order_by('-id'):
for spec_file in get_spec_files(obj):
if spec_file is not None:
spec_file._delete()
if spec_file.field.pre_cache:
spec_file._create()
else:
print 'Please specify on or more app names'