From 52b2c31c10c6c805e64a5a7b176379db38e1090f Mon Sep 17 00:00:00 2001 From: redfast00 Date: Sun, 9 May 2021 02:42:15 +0200 Subject: [PATCH] Round amount of interested/admitted people in events We round this number to avoid people not registering for an event because the event is at max capacity and they would bump it to an online event. We don't hide the number entirely in order to not put off people when there aren't a lot of people interested/admitted. --- events/models.py | 26 ++++++++++++++++++++++ events/templates/events/registrations.html | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/events/models.py b/events/models.py index 2fdd95b..a11360a 100644 --- a/events/models.py +++ b/events/models.py @@ -45,6 +45,32 @@ class TimeSlot(models.Model): def count_admitted(self): return self.count_with_status(EventRegistration.ADMITTED) + + def precision(self): + # TODO put this in a database field? + return 10 + + def lower_round(self, n): + return (n // self.precision()) * self.precision() + + def upper_round(self, n): + return ((n + self.precision()) // self.precision()) * self.precision() + + # Unfortunately, Django doesn't support arguments in templates + + def lower_interested(self): + return self.lower_round(self.count_interested()) + + def upper_interested(self): + return self.upper_round(self.count_interested()) + + def lower_admitted(self): + return self.lower_round(self.count_admitted()) + + def upper_admitted(self): + return self.upper_round(self.count_admitted()) + + def registration_of(self, user): if not user.is_authenticated: return None diff --git a/events/templates/events/registrations.html b/events/templates/events/registrations.html index c8591a6..a6331e7 100644 --- a/events/templates/events/registrations.html +++ b/events/templates/events/registrations.html @@ -4,8 +4,8 @@
{% endif %} {% csrf_token %} -

{{ timeslot.time_str }}, {{ timeslot.count_admitted }}/{{ event.capacity }} bevestigd{% if timeslot.count_interested %}, - {{ timeslot.count_interested }} op wachtlijst +

{{ timeslot.time_str }}, tussen {{ timeslot.lower_admitted }} en {{ timeslot.upper_admitted }} van de mogelijke {{ event.capacity }} aanwezigheden bevestigd{% if timeslot.count_interested %}, + tussen {{ timeslot.lower_interested }} en {{ timeslot.upper_interested }} mensen op wachtlijst {% endif %}