agendas: check event fullness on save

This is useful when the capacity of an event is changed after the fact.
This commit is contained in:
Frédéric Péters 2016-07-07 16:33:22 +02:00
parent 5aeb24d58a
commit dfed6a5bbe
1 changed files with 10 additions and 4 deletions

View File

@ -70,6 +70,15 @@ class Event(models.Model):
return self.label
return date_format(localtime(self.start_datetime), format='DATETIME_FORMAT')
def save(self, *args, **kwargs):
self.check_full()
return super(Event, self).save(*args, **kwargs)
def check_full(self):
self.full = bool(
(self.booked_places >= self.places and self.waiting_list_places == 0) or
(self.waiting_list_places and self.waiting_list >= self.waiting_list_places))
@property
def booked_places(self):
return self.booking_set.filter(cancellation_datetime__isnull=True,
@ -92,10 +101,7 @@ class Booking(models.Model):
with transaction.atomic():
super(Booking, self).save(*args, **kwargs)
initial_value = self.event.full
self.event.full = bool(
(self.event.booked_places >= self.event.places and
self.event.waiting_list_places == 0) or
self.event.waiting_list >= self.event.waiting_list_places)
self.event.check_full()
if self.event.full != initial_value:
self.event.save()