Source code for memopolis.signals

from django.conf import settings
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver
from rest_framework.authtoken.models import Token

from . import models


[docs] @receiver(post_save, sender=settings.AUTH_USER_MODEL) def create_auth_token(sender, instance=None, created=False, **kwargs): # if created: # Token.objects.create(user=instance) pass
[docs] @receiver(post_save, sender=models.Organization) def init_organization_quest(sender, instance=None, created=False, **kwargs): pass
# if created: # team = models.Team.objects.create(name=instance.name, organization=instance) # team.admins.add() # quest = models.Quest.objects.create(name=instance.name, organization=instance) # models.Map.objects.create(name=instance.name, quest=quest)
[docs] @receiver(post_delete, sender=models.Map) def delete_quests_without_maps(sender, instance=None, created=False, **kwargs): if len(instance.quest.maps.all()) < 1: print("deleted map %s and quest %s has no more maps!!" % (instance.name, instance.quest.name)) instance.quest.delete()