def _setup_badge_settings(self): """ Set up badges for all jobs and helpers (called from post_save handler). It adds the badge settings if badge creation is enabled and it is not there already. It also adds badge defaults to all jobs and badges to all helpers and coordinators if necessary. """ # badge settings for event if not self.badge_settings: settings = BadgeSettings() settings.event = self settings.save() # badge defaults for jobs for job in self.job_set.all(): if not job.badge_defaults: defaults = BadgeDefaults() defaults.save() job.badge_defaults = defaults job.save() # badge for helpers for helper in self.helper_set.all(): if not hasattr(helper, 'badge'): badge = Badge() badge.event = self badge.helper = helper badge.save()
def helper_saved(sender, instance, using, **kwargs): """ Add badge and gifts to helper if necessary. This is a signal handler, that is called, when a helper is saved. It adds the badge if badge creation is enabled and it is not there already. """ if instance.event: if instance.event.badges and not hasattr(instance, 'badge'): badge = Badge() badge.helper = instance badge.save() if instance.event.gifts and not hasattr(instance, 'gifts'): gifts = HelpersGifts() gifts.helper = instance gifts.save()
def event_saved(sender, instance, using, **kwargs): """ Add badge settings, badges and gifts if necessary. This is a signal handler, that is called, when a event is saved. It adds the badge settings if badge creation is enabled and it is not there already. It also adds badge defaults to all jobs and badges to all helpers and coordinators if necessary. """ if instance.badges: # badge settings for event if not instance.badge_settings: settings = BadgeSettings() settings.event = instance settings.save() # badge defaults for jobs for job in instance.job_set.all(): if not job.badge_defaults: defaults = BadgeDefaults() defaults.save() job.badge_defaults = defaults job.save() # badge for helpers for helper in instance.helper_set.all(): if not hasattr(helper, 'badge'): badge = Badge() badge.helper = helper badge.save() if instance.gifts: for helper in instance.helper_set.all(): if not hasattr(helper, 'gifts'): gifts = HelpersGifts() gifts.helper = helper gifts.save() if instance.inventory: if not instance.inventory_settings: InventorySettings.objects.create(event=instance)