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.event = instance.event badge.helper = instance badge.save() if instance.event.gifts and not hasattr(instance, 'gifts'): gifts = HelpersGifts() gifts.helper = instance gifts.save()