from django.core.management import call_command
from django.dispatch import receiver

from ocyan.core.signals import post_loaddemodata
from ocyan.core.utils import find_fixture


@receiver(post_loaddemodata)
def import_oscar_images(has_unloaded_fixtures, **kwargs):  # pylint: disable=W0613
    if has_unloaded_fixtures:
        # this file is not in this plugin because it would always be installed
        # if wagtail is needed, that is why it is stored in the demo_data
        # plugin, if you remove the demo_data plugin the tarball is also gone
        images_path = find_fixture("demo_data/images.tar.gz")
        if images_path is not None:
            call_command("oscar_import_catalogue_images", images_path)
