Пример #1
0
    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()
Пример #2
0
def job_pre_save(sender, instance, using, **kwargs):
    """ Add badge defaults if necessary.

    This is a signal handler, that is called, before a job is saved. It
    adds the badge defaults if badge creation is enabled and it is not
    there already.
    """
    if instance.event.badges and not instance.badge_defaults:
        defaults = BadgeDefaults()
        defaults.save()

        instance.badge_defaults = defaults
Пример #3
0
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)