diff --git a/events/tasks.py b/events/tasks.py index ffa9e38..3a28805 100644 --- a/events/tasks.py +++ b/events/tasks.py @@ -30,26 +30,24 @@ def assign_reservations(self): :param self: :return: """ - out = [] - # Get all events of tomorrow events = Event.objects.filter(date=date.today() + timedelta(days=1)) - out.append(f"{len(events) if events else 'Geen'} event(s)") + print(f"{len(events) if events else 'Geen'} event(s)") # Reservations registrations: List[EventRegistration] = EventRegistration.objects.filter( event_id__in=map(lambda event: event.id, events)) - out.append(f"{len(registrations) if registrations else 'Geen'} registratie(s)") - out.append("") + print(f"{len(registrations) if registrations else 'Geen'} registratie(s)") + print("") # Relevant users users = [r.user for r in registrations if r.state == EventRegistration.INTERESTED] scores = list(map(calc_score, users)) queue = sorted(list(zip(users, scores)), key=lambda tup: tup[1]) - out.append("Prioriteiten: " + ", ".join(f"{u.username} ({s})" for u, s in queue)) - out.append("") + print("Prioriteiten: " + ", ".join(f"{u.username} ({s})" for u, s in queue)) + print("") for event in events: registrations = [r for r in registrations if r.event == event] @@ -58,16 +56,16 @@ def assign_reservations(self): left = max(event.capacity - sum(1 for r in already_admitted_regs), 0) moment_str = Event.TIME_SLOTS[event.time] - out.append(f"• Event: {event.date}, {moment_str}. Vrije plaatsen: {left}/{event.capacity}") + print(f"• Event: {event.date}, {moment_str}. Vrije plaatsen: {left}/{event.capacity}") for reg in already_admitted_regs: - out.append(f" = {reg.user.username}") + print(f" = {reg.user.username}") interested_users = {r.user for r in registrations if r.state == EventRegistration.INTERESTED} user_queue = list(filter(lambda element: element[0] in interested_users, queue)) for user in user_queue[0:left]: - out.append(f" + {user[0].username}") + print(f" + {user[0].username}") r = EventRegistration.objects.get( event_id=event.id, user_id=user[0].id @@ -76,6 +74,4 @@ def assign_reservations(self): r.save() left -= 1 - out.append(f" → Vrije plaatsen: {left}/{event.capacity}") - - return "\n".join(out) + print(f" → Vrije plaatsen: {left}/{event.capacity}")