bgneal@1: from django.core.management.base import BaseCommand, CommandError bgneal@1: from optparse import make_option bgneal@1: from photologue.models import PhotoSize, ImageModel bgneal@1: bgneal@1: class Command(BaseCommand): bgneal@1: help = ('Clears the Photologue cache for the given sizes.') bgneal@1: args = '[sizes]' bgneal@1: bgneal@1: requires_model_validation = True bgneal@1: can_import_settings = True bgneal@1: bgneal@1: def handle(self, *args, **options): bgneal@1: return create_cache(args, options) bgneal@1: bgneal@1: def create_cache(sizes, options): bgneal@1: """ bgneal@1: Clears the cache for the given files bgneal@1: """ bgneal@1: size_list = [size.strip(' ,') for size in sizes] bgneal@1: bgneal@1: if len(size_list) < 1: bgneal@1: sizes = PhotoSize.objects.all() bgneal@1: else: bgneal@1: sizes = PhotoSize.objects.filter(name__in=size_list) bgneal@1: bgneal@1: if not len(sizes): bgneal@1: raise CommandError('No photo sizes were found.') bgneal@1: bgneal@1: print 'Flushing cache...' bgneal@1: bgneal@1: for cls in ImageModel.__subclasses__(): bgneal@1: for photosize in sizes: bgneal@1: print 'Flushing %s size images' % photosize.name bgneal@1: for obj in cls.objects.all(): bgneal@1: obj.remove_size(photosize)