From 4a254c90d199d0144908eee4604eb5c284443a6c Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 16 Jul 2020 15:07:18 +0200 Subject: [PATCH 1/2] agendas: add almost_full event flag (#44158) --- .../migrations/0057_event_almost_full.py | 18 ++++++++++++++++++ chrono/agendas/models.py | 6 ++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 chrono/agendas/migrations/0057_event_almost_full.py diff --git a/chrono/agendas/migrations/0057_event_almost_full.py b/chrono/agendas/migrations/0057_event_almost_full.py new file mode 100644 index 0000000..eb0044b --- /dev/null +++ b/chrono/agendas/migrations/0057_event_almost_full.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2020-07-29 09:50 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('agendas', '0056_event_cancelled'), + ] + + operations = [ + migrations.AddField( + model_name='event', name='almost_full', field=models.BooleanField(default=False), + ), + ] diff --git a/chrono/agendas/models.py b/chrono/agendas/models.py index 1703381..a2cb121 100644 --- a/chrono/agendas/models.py +++ b/chrono/agendas/models.py @@ -771,6 +771,7 @@ class Event(models.Model): ) pricing = models.CharField(_('Pricing'), max_length=150, null=True, blank=True) url = models.CharField(_('URL'), max_length=200, null=True, blank=True) + almost_full = models.BooleanField(default=False) full = models.BooleanField(default=False) cancelled = models.BooleanField( default=False, help_text=_("Cancel this event so that it won't be bookable anymore.") @@ -810,6 +811,7 @@ class Event(models.Model): (self.booked_places >= self.places and self.waiting_list_places == 0) or (self.waiting_list_places and self.waiting_list >= self.waiting_list_places) ) + self.almost_full = bool(self.booked_places >= 0.9 * self.places) def in_bookable_period(self): if self.publication_date and localtime(now()).date() < self.publication_date: @@ -965,9 +967,9 @@ class Booking(models.Model): def save(self, *args, **kwargs): with transaction.atomic(): super(Booking, self).save(*args, **kwargs) - initial_value = self.event.full + initial_values = self.event.full, self.event.almost_full self.event.check_full() - if self.event.full != initial_value: + if (self.event.full, self.event.almost_full) != initial_values: self.event.save() def cancel(self, trigger_callback=True): -- 2.20.1