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.
This commit is contained in:
redfast00 2021-05-09 02:42:15 +02:00
parent 1402884361
commit 52b2c31c10
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C
2 changed files with 28 additions and 2 deletions

View file

@ -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

View file

@ -4,8 +4,8 @@
<form action="{% url 'events:deregister' timeslot.id %}" method="post">
{% endif %}
{% csrf_token %}
<p>{{ timeslot.time_str }}, {{ timeslot.count_admitted }}/{{ event.capacity }} bevestigd{% if timeslot.count_interested %},
{{ timeslot.count_interested }} op wachtlijst
<p>{{ 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 %}
</p>