Source code for festivalgrid.signals

import os
import binascii

from django.db.models.signals import post_save
from django.dispatch import receiver
from django.core.exceptions import ObjectDoesNotExist

from .models import APIUser, Node, Device, Timer


[docs]@receiver(post_save, sender=APIUser) def create_auth_token(sender, instance=None, created=False, **kwargs): if instance.token is None: instance.token = binascii.hexlify(os.urandom(20)).decode() instance.save()
[docs]@receiver(post_save, sender=Device) def device_setup_changed(sender, instance=None, created=False, **kwargs): instance.get_template().notify_setup_change("device")
[docs]@receiver(post_save, sender=Node) def node_setup_changed(sender, instance=None, created=False, **kwargs): try: instance.device.get_template().notify_setup_change("node") except (ObjectDoesNotExist, AttributeError): pass
[docs]@receiver(post_save, sender=Timer) def timer_setup_changed(sender, instance=None, created=False, **kwargs): try: instance.node.device.get_template().notify_setup_change("timer") except ObjectDoesNotExist: pass