Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from django.conf import settings
- from django.core.management.base import BaseCommand
- from django.core.files.base import ContentFile
- from lfs.catalog.models import Image
- class Command(BaseCommand):
- help = "Removes and recreates all scales for all LFS Images"
- args = ''
- def handle(self, *args, **options):
- if settings.MEDIA_ROOT == '':
- print "MEDIA_ROOT is not set, nothing to do"
- return
- progress = 0
- total = Image.objects.count()
- for img in Image.objects.all():
- filename = img.image.name.split('/')[-1]
- try:
- content = ContentFile(img.image.read())
- except IOError:
- print >>sys.stderr, "Invalid file:", img.pk, filename
- continue
- img.image.delete() # remove all scales and files in media dir
- img.image.save(filename, content)
- del content
- del filename
- progress += 1
- if progress % 500 == 0:
- print >>sys.stderr, "Progress: %s/%s" % (progress, total)
Advertisement
Add Comment
Please, Sign In to add comment