bgneal@532: """ bgneal@532: Signal handlers for the potd application. bgneal@532: bgneal@532: """ bgneal@532: from django.db.models.signals import post_save, post_delete bgneal@532: bgneal@532: from potd.models import Photo, Sequence bgneal@532: bgneal@532: bgneal@532: def on_photo_save(sender, **kwargs): bgneal@532: """ bgneal@532: This function is executed when a Photo is saved. It inserts the photo into bgneal@532: the current sequence. bgneal@532: bgneal@532: """ bgneal@532: photo = kwargs['instance'] bgneal@532: Sequence.objects.insert_photo(photo.pk) bgneal@532: bgneal@532: bgneal@532: def on_photo_delete(sender, **kwargs): bgneal@532: """ bgneal@532: This function is executed when a Photo is deleted. It removes the photo from bgneal@532: the current sequence of photos. bgneal@532: bgneal@532: """ bgneal@532: photo = kwargs['instance'] bgneal@532: Sequence.objects.remove_photo(photo.pk) bgneal@532: bgneal@532: bgneal@532: post_save.connect(on_photo_save, sender=Photo, dispatch_uid='potd.signals') bgneal@532: post_delete.connect(on_photo_delete, sender=Photo, dispatch_uid='potd.signals')