コード例 #1
0
    def admin_register(self, user, admin_registration_reason, pool=None, feedback=''):
        """
        Used to force registration for a user, even if the event is full
        or if the user isn't allowed to register.

        :param user: The user who will be registered
        :param pool: What pool the registration will be created for
        :param feedback: Feedback to organizers
        :return: The registration
        """
        if pool and not self.pools.filter(id=pool.id).exists():
            raise NoSuchPool()
        with transaction.atomic():
            registration = self.registrations.get_or_create(event=self, user=user)[0]
            if registration.pool_id:
                raise RegistrationExists()

            if pool:
                locked_pool = Pool.objects.select_for_update().get(pk=pool.id)
                locked_pool.increment()

                registration.add_direct_to_pool(
                    pool, feedback=feedback, admin_registration_reason=admin_registration_reason
                )
            else:
                registration.add_to_waiting_list(
                    feedback=feedback, admin_registration_reason=admin_registration_reason
                )
            handle_event(registration, 'admin_registration')
            return registration
コード例 #2
0
ファイル: tasks.py プロジェクト: webkom/lego
def notify_user_when_payment_soon_overdue(self, logger_context=None):
    self.setup_logger(logger_context)

    time = timezone.now()
    events = (
        Event.objects.filter(
            payment_due_date__range=(
                time - timedelta(days=2),
                time + timedelta(days=3),
            ),
            is_priced=True,
            use_stripe=True,
        )
        .exclude(registrations=None)
        .prefetch_related("registrations")
    )
    for event in events:
        for registration in event.registrations.exclude(pool=None):
            if registration.should_notify(time):
                log.info(
                    "registration_notified_overdue_payment",
                    event_id=event.id,
                    registration_id=registration.id,
                )
                handle_event(registration, "payment_overdue")
コード例 #3
0
ファイル: models.py プロジェクト: webkom/lego
    def send(self):
        if self.sent:
            # Message is sent already, nothing to do!
            return

        handle_event(self, "send")
        self.sent = timezone.now()
        self.save()
コード例 #4
0
 def admin_unregister(self, user, admin_unregistration_reason):
     with transaction.atomic():
         registration = self.registrations.filter(user=user).first()
         if not registration:
             raise NoSuchRegistration()
         self.unregister(registration, admin_unregistration_reason=admin_unregistration_reason)
         handle_event(registration, 'admin_unregistration')
         return registration
コード例 #5
0
 def early_bump(self, opening_pool):
     """
     Used when bumping users from waiting list to a pool that is about to be activated,
     using an async task. This is done to make sure these existing registrations are given
     the spot ahead of users that register at activation time.
     :param opening_pool: The pool about to be activated.
     :return:
     """
     for reg in self.waiting_registrations:
         if opening_pool.is_full:
             break
         if self.heed_penalties and reg.user.number_of_penalties() >= 3:
             continue
         if self.can_register(reg.user, opening_pool, future=True):
             reg.pool = opening_pool
             reg.save()
             handle_event(reg, 'bump')
     self.check_for_bump_or_rebalance(opening_pool)
コード例 #6
0
    def bump_on_pool_creation_or_expansion(self):
        """
        Used when a pool's capacity is expanded or a new pool is created,
        so that waiting registrations are bumped before anyone else can fill
        the open spots. This is done on event update.

        This method does the same as `early_bump`, but only accepts people that can be bumped now,
        not people that can be bumped in the future.
        :return:
        """
        open_pools = [pool for pool in self.pools.all() if not pool.is_full]
        for pool in open_pools:
            for reg in self.waiting_registrations:
                if self.is_full or pool.is_full:
                    break
                if self.heed_penalties and reg.user.number_of_penalties() >= 3:
                    continue
                if self.can_register(reg.user, pool, future=True):
                    reg.pool = pool
                    reg.save()
                    handle_event(reg, 'bump')
            self.check_for_bump_or_rebalance(pool)
コード例 #7
0
    def bump(self, to_pool=None):
        """
        Pops the appropriate registration from the waiting list,
        and moves the registration from the waiting list to `to pool`.

        :param to_pool: A pool with a free slot. If the event is merged, this will be null.
        """
        if self.waiting_registrations.exists():
            first_waiting = self.pop_from_waiting_list(to_pool)
            if first_waiting:
                new_pool = None
                if to_pool:
                    new_pool = to_pool
                    new_pool.increment()
                else:
                    for pool in self.pools.all():
                        if self.can_register(first_waiting.user, pool):
                            new_pool = pool
                            new_pool.increment()
                            break
                first_waiting.pool = new_pool
                first_waiting.save(update_fields=['pool'])
                handle_event(first_waiting, 'bump')