Convert back to print since not needed on web any more
This commit is contained in:
parent
a37e59ed02
commit
bd714538df
1 changed files with 9 additions and 13 deletions
|
@ -30,26 +30,24 @@ def assign_reservations(self):
|
||||||
:param self:
|
:param self:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
out = []
|
|
||||||
|
|
||||||
# Get all events of tomorrow
|
# Get all events of tomorrow
|
||||||
events = Event.objects.filter(date=date.today() + timedelta(days=1))
|
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
|
# Reservations
|
||||||
registrations: List[EventRegistration] = EventRegistration.objects.filter(
|
registrations: List[EventRegistration] = EventRegistration.objects.filter(
|
||||||
event_id__in=map(lambda event: event.id, events))
|
event_id__in=map(lambda event: event.id, events))
|
||||||
|
|
||||||
out.append(f"{len(registrations) if registrations else 'Geen'} registratie(s)")
|
print(f"{len(registrations) if registrations else 'Geen'} registratie(s)")
|
||||||
out.append("")
|
print("")
|
||||||
|
|
||||||
# Relevant users
|
# Relevant users
|
||||||
users = [r.user for r in registrations if r.state == EventRegistration.INTERESTED]
|
users = [r.user for r in registrations if r.state == EventRegistration.INTERESTED]
|
||||||
scores = list(map(calc_score, users))
|
scores = list(map(calc_score, users))
|
||||||
queue = sorted(list(zip(users, scores)), key=lambda tup: tup[1])
|
queue = sorted(list(zip(users, scores)), key=lambda tup: tup[1])
|
||||||
out.append("Prioriteiten: " + ", ".join(f"{u.username} ({s})" for u, s in queue))
|
print("Prioriteiten: " + ", ".join(f"{u.username} ({s})" for u, s in queue))
|
||||||
out.append("")
|
print("")
|
||||||
|
|
||||||
for event in events:
|
for event in events:
|
||||||
registrations = [r for r in registrations if r.event == event]
|
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)
|
left = max(event.capacity - sum(1 for r in already_admitted_regs), 0)
|
||||||
|
|
||||||
moment_str = Event.TIME_SLOTS[event.time]
|
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:
|
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
|
interested_users = {r.user for r in registrations
|
||||||
if r.state == EventRegistration.INTERESTED}
|
if r.state == EventRegistration.INTERESTED}
|
||||||
user_queue = list(filter(lambda element: element[0] in interested_users, queue))
|
user_queue = list(filter(lambda element: element[0] in interested_users, queue))
|
||||||
|
|
||||||
for user in user_queue[0:left]:
|
for user in user_queue[0:left]:
|
||||||
out.append(f" + {user[0].username}")
|
print(f" + {user[0].username}")
|
||||||
r = EventRegistration.objects.get(
|
r = EventRegistration.objects.get(
|
||||||
event_id=event.id,
|
event_id=event.id,
|
||||||
user_id=user[0].id
|
user_id=user[0].id
|
||||||
|
@ -76,6 +74,4 @@ def assign_reservations(self):
|
||||||
r.save()
|
r.save()
|
||||||
left -= 1
|
left -= 1
|
||||||
|
|
||||||
out.append(f" → Vrije plaatsen: {left}/{event.capacity}")
|
print(f" → Vrije plaatsen: {left}/{event.capacity}")
|
||||||
|
|
||||||
return "\n".join(out)
|
|
||||||
|
|
Loading…
Reference in a new issue