from django.db.models.signals import post_delete

from wagtail.images import get_image_model
from wagtail.images.apps import WagtailImagesAppConfig


class DontDeleteImagesWagtailImagesAppConfig(WagtailImagesAppConfig):
    """
    Use this app config to register wagtail.images without the post_delete
    handler that deletes images from disk.
    """

    def ready(self):
        super().ready()

        from wagtail.images.signal_handlers import (
            post_delete_file_cleanup,
            post_delete_purge_rendition_cache,
        )

        Image = get_image_model()
        Rendition = Image.get_rendition_model()
        post_delete.disconnect(post_delete_file_cleanup, sender=Image)
        post_delete.disconnect(post_delete_file_cleanup, sender=Rendition)
        post_delete.disconnect(post_delete_purge_rendition_cache, sender=Rendition)
