from django.core.management.base import BaseCommand, CommandError

from wagtail.images.models import Rendition


class Command(BaseCommand):
    def handle(self, *args, **options):
        renditions = Rendition.objects.all()
        if renditions:
            message = (
                "\n"
                "This will REMOVE ALL IMAGE RENDITION FILES in!\n"
                "Are you sure you want to do this?\n\n"
                "Type 'yes' to continue, or 'no' to cancel: "
            )
            if input(message) != "yes":
                raise CommandError("Remove renditions cancelled.")
            else:
                for rendition in renditions:
                    rendition.delete()
                self.stdout.write("Done")
        else:
            self.stdout.write("There are no image renditions")
