Mercurial > public > madeira
comparison photologue/management/commands/plflush.py @ 71:e2868ad47a1e
For Django 1.4, using the new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 14 Apr 2012 16:40:29 -0500 |
parents | madeira/photologue/management/commands/plflush.py@63e4211628e1 |
children |
comparison
equal
deleted
inserted
replaced
70:f26cdda0ad8b | 71:e2868ad47a1e |
---|---|
1 from django.core.management.base import BaseCommand, CommandError | |
2 from optparse import make_option | |
3 from photologue.models import PhotoSize, ImageModel | |
4 | |
5 class Command(BaseCommand): | |
6 help = ('Clears the Photologue cache for the given sizes.') | |
7 args = '[sizes]' | |
8 | |
9 requires_model_validation = True | |
10 can_import_settings = True | |
11 | |
12 def handle(self, *args, **options): | |
13 return create_cache(args, options) | |
14 | |
15 def create_cache(sizes, options): | |
16 """ | |
17 Clears the cache for the given files | |
18 """ | |
19 size_list = [size.strip(' ,') for size in sizes] | |
20 | |
21 if len(size_list) < 1: | |
22 sizes = PhotoSize.objects.all() | |
23 else: | |
24 sizes = PhotoSize.objects.filter(name__in=size_list) | |
25 | |
26 if not len(sizes): | |
27 raise CommandError('No photo sizes were found.') | |
28 | |
29 print 'Flushing cache...' | |
30 | |
31 for cls in ImageModel.__subclasses__(): | |
32 for photosize in sizes: | |
33 print 'Flushing %s size images' % photosize.name | |
34 for obj in cls.objects.all(): | |
35 obj.remove_size(photosize) |