Coverage for apps/organizations/signals.py: 33%
17 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-09-29 13:04 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-09-29 13:04 -0600
1from django.db.models import signals
2from django.dispatch import receiver
4from .models import Organization, OrganizationCampaignLabel, OrganizationSiteLabel
7@receiver(signals.post_save, sender=Organization)
8def set_organization_default_labels(sender, instance: Organization, created, *args, **kwargs):
9 if created:
10 OrganizationSiteLabel.objects.get_or_create(
11 organization=instance,
12 label=OrganizationSiteLabel.Labels.CAMPAIGNS,
13 defaults={"singular": "Campaign", "plural": "Campaigns"},
14 )
15 OrganizationSiteLabel.objects.get_or_create(
16 organization=instance,
17 label=OrganizationSiteLabel.Labels.FANS,
18 defaults={"singular": "Fan", "plural": "Fans"},
19 )
20 OrganizationSiteLabel.objects.get_or_create(
21 organization=instance,
22 label=OrganizationSiteLabel.Labels.REWARDS,
23 defaults={"singular": "Reward", "plural": "Rewards"},
24 )
26 OrganizationCampaignLabel.objects.get_or_create(
27 organization=instance,
28 label=OrganizationCampaignLabel.Labels.VIDEO_CAMPAIGN,
29 defaults={"singular": "Video Campaign", "plural": "Video Campaigns"},
30 )
31 OrganizationCampaignLabel.objects.get_or_create(
32 organization=instance,
33 label=OrganizationCampaignLabel.Labels.GEOLOCATION_CAMPAIGN,
34 defaults={"singular": "Geolocation Campaign", "plural": "Geolocation Campaigns"},
35 )
36 OrganizationCampaignLabel.objects.get_or_create(
37 organization=instance,
38 label=OrganizationCampaignLabel.Labels.SUBMIT_CAMPAIGN,
39 defaults={"singular": "Submit Campaign", "plural": "Submit Campaigns"},
40 )
41 OrganizationCampaignLabel.objects.get_or_create(
42 organization=instance,
43 label=OrganizationCampaignLabel.Labels.QUIZZ_CAMPAIGN,
44 defaults={"singular": "Quizz Campaign", "plural": "Quizz Campaigns"},
45 )
48@receiver(signals.post_save, sender=Organization)
49def set_cc_domain_for_children(sender, instance: Organization, created, *args, **kwargs):
50 if instance.parent is None:
51 instance.get_descendants().all().update(cc_domain=instance.cc_domain)