Coverage for apps/users/signals.py: 31%
22 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-09-08 12:47 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-09-08 12:47 -0600
1from django.db.models import signals
2from django.dispatch import receiver
4from apps.accounting.models import Accounting
6from .models import Employee, Fan, SuperUser
9@receiver(signals.post_save, sender=SuperUser)
10def set_superuser_permissions(sender, instance, created, *args, **kwargs):
11 if created:
12 instance.is_superuser = True
13 instance.is_staff = True
16@receiver(signals.post_save, sender=Fan)
17def create_fan_accounting_account(sender, instance: Fan, created, *args, **kwargs):
18 for organization in instance.registered_organizations.all():
19 Accounting.objects.get_or_create(organization=organization, fan=instance)
22@receiver(signals.post_save, sender=Employee)
23def set_admin_organizations(sender, instance, created, *args, **kwargs):
24 if created:
25 if not instance.registered_organizations.exists():
26 instance.registered_organizations.add(instance.parent_organization)
27 descendant_organizations = instance.parent_organization.get_descendants()
28 for organization in descendant_organizations:
29 instance.registered_organizations.add(organization)
30 instance.save()