Exemplo n.º 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
                )
            get_handler(Registration).handle_admin_registration(registration)
            return registration
Exemplo n.º 2
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)
         get_handler(Registration).handle_admin_unregistration(registration)
         return registration
Exemplo n.º 3
0
    def create(self, validated_data):
        semesters = validated_data.pop('semesters')
        company_interest = CompanyInterest.objects.create(**validated_data)
        company_interest.semesters.add(*semesters)
        company_interest.save()
        get_handler(CompanyInterest).handle_interest(company_interest)

        return company_interest
Exemplo n.º 4
0
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)
                get_handler(Registration).handle_payment_overdue(registration)
Exemplo n.º 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()
             get_handler(Registration).handle_bump(reg)
     self.check_for_bump_or_rebalance(opening_pool)
Exemplo n.º 6
0
def add_to_feeds(self, instance, action='update', logger_context=None):
    """
    Add action to feed and notificationfeed of appropriate users
    """
    self.setup_logger(logger_context)

    handler = get_handler(instance._meta.model)
    if handler is None:
        # No handler registered for model
        return

    handler.handle_event(instance, action)
Exemplo n.º 7
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 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()
                    get_handler(Registration).handle_bump(reg)
            self.check_for_bump_or_rebalance(pool)
Exemplo n.º 8
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'])
                get_handler(Registration).handle_bump(first_waiting)
Exemplo n.º 9
0
 def __init__(self, sender, message, message_data):
     self.sender = sender
     self.message = message
     self.message_data = message_data
     self.feed_handler = get_handler(RestrictedMail)