plflush.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from django.core.management.base import BaseCommand, CommandError
  2. from optparse import make_option
  3. from photologue.models import PhotoSize, ImageModel
  4. class Command(BaseCommand):
  5. help = ('Clears the Photologue cache for the given sizes.')
  6. args = '[sizes]'
  7. requires_model_validation = True
  8. can_import_settings = True
  9. def handle(self, *args, **options):
  10. return create_cache(args, options)
  11. def create_cache(sizes, options):
  12. """
  13. Clears the cache for the given files
  14. """
  15. size_list = [size.strip(' ,') for size in sizes]
  16. if len(size_list) < 1:
  17. sizes = PhotoSize.objects.all()
  18. else:
  19. sizes = PhotoSize.objects.filter(name__in=size_list)
  20. if not len(sizes):
  21. raise CommandError('No photo sizes were found.')
  22. print 'Flushing cache...'
  23. for cls in ImageModel.__subclasses__():
  24. for photosize in sizes:
  25. print 'Flushing %s size images' % photosize.name
  26. for obj in cls.objects.all():
  27. obj.remove_size(photosize)