django-imagekit / src / imagekit / management / commands /

from django.db.models.loading import cache
from 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)
        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,, None)
                if prop is not None:
                if spec.pre_cache:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.