2011-09-26 00:38:43 +00:00
|
|
|
"""
|
2011-10-31 14:12:03 +00:00
|
|
|
Flushes and re-caches all images under ImageKit.
|
2011-09-26 00:38:43 +00:00
|
|
|
|
2011-10-31 14:12:03 +00:00
|
|
|
"""
|
2011-02-11 03:00:26 +00:00
|
|
|
from django.db.models.loading import cache
|
2011-10-20 03:12:47 +00:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
2011-09-22 13:20:37 +00:00
|
|
|
from imagekit.utils import get_spec_files
|
2011-02-11 03:00:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2011-10-10 17:13:47 +00:00
|
|
|
|
2011-02-11 03:00:26 +00:00
|
|
|
def flush_cache(apps, options):
|
|
|
|
|
apps = [a.strip(',') for a in apps]
|
|
|
|
|
if apps:
|
|
|
|
|
for app_label in apps:
|
|
|
|
|
app = cache.get_app(app_label)
|
2011-09-22 00:21:15 +00:00
|
|
|
for model in [m for m in cache.get_models(app)]:
|
2011-02-11 03:00:26 +00:00
|
|
|
print 'Flushing cache for "%s.%s"' % (app_label, model.__name__)
|
2011-10-06 23:15:26 +00:00
|
|
|
for obj in model.objects.order_by('-pk'):
|
2011-09-22 13:20:37 +00:00
|
|
|
for spec_file in get_spec_files(obj):
|
|
|
|
|
if spec_file is not None:
|
2011-10-10 21:00:41 +00:00
|
|
|
spec_file.delete(save=False)
|
2011-09-22 22:13:32 +00:00
|
|
|
if spec_file.field.pre_cache:
|
2011-11-08 04:01:52 +00:00
|
|
|
spec_file.generate(False)
|
2011-02-11 03:00:26 +00:00
|
|
|
else:
|
2011-10-10 19:59:39 +00:00
|
|
|
print 'Please specify one or more app names'
|