from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver


@receiver(post_save, sender='netscan.ScanProfile')
def reschedule_on_save(sender, instance, **kwargs):
    from netscan.tasks import schedule_profile, unschedule_profile
    if instance.enabled:
        schedule_profile(instance)
    else:
        unschedule_profile(instance)


@receiver(post_delete, sender='netscan.ScanProfile')
def unschedule_on_delete(sender, instance, **kwargs):
    from netscan.tasks import unschedule_profile
    unschedule_profile(instance)
