Mercurial > public > madeira
annotate mysite/photologue/management/commands/plflush.py @ 1:0dcfcdf50c62
Initial import of Madeira project from the private repository.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 06 Apr 2009 03:10:59 +0000 |
parents | |
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) |