annotate mysite/photologue/management/commands/plflush.py @ 88:7245c769e31e django1.3

Close this branch. I'm not sure if I merged it correctly to the default branch, because the graphlog doesn't look right. But the changes were made to default somehow. So closing this off to prevent future confusion.
author Brian Neal <bgneal@gmail.com>
date Sat, 13 Apr 2013 18:08:19 -0500
parents 0dcfcdf50c62
children
rev   line source
bgneal@1 1 from django.core.management.base import BaseCommand, CommandError
bgneal@1 2 from optparse import make_option
bgneal@1 3 from photologue.models import PhotoSize, ImageModel
bgneal@1 4
bgneal@1 5 class Command(BaseCommand):
bgneal@1 6 help = ('Clears the Photologue cache for the given sizes.')
bgneal@1 7 args = '[sizes]'
bgneal@1 8
bgneal@1 9 requires_model_validation = True
bgneal@1 10 can_import_settings = True
bgneal@1 11
bgneal@1 12 def handle(self, *args, **options):
bgneal@1 13 return create_cache(args, options)
bgneal@1 14
bgneal@1 15 def create_cache(sizes, options):
bgneal@1 16 """
bgneal@1 17 Clears the cache for the given files
bgneal@1 18 """
bgneal@1 19 size_list = [size.strip(' ,') for size in sizes]
bgneal@1 20
bgneal@1 21 if len(size_list) < 1:
bgneal@1 22 sizes = PhotoSize.objects.all()
bgneal@1 23 else:
bgneal@1 24 sizes = PhotoSize.objects.filter(name__in=size_list)
bgneal@1 25
bgneal@1 26 if not len(sizes):
bgneal@1 27 raise CommandError('No photo sizes were found.')
bgneal@1 28
bgneal@1 29 print 'Flushing cache...'
bgneal@1 30
bgneal@1 31 for cls in ImageModel.__subclasses__():
bgneal@1 32 for photosize in sizes:
bgneal@1 33 print 'Flushing %s size images' % photosize.name
bgneal@1 34 for obj in cls.objects.all():
bgneal@1 35 obj.remove_size(photosize)