Projet

Général

Profil

0001-agendas-add-almost_full-event-flag-44158.patch

Valentin Deniaud, 01 septembre 2020 17:09

Télécharger (2,71 ko)

Voir les différences:

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
chrono/agendas/migrations/0057_event_almost_full.py
1
# -*- coding: utf-8 -*-
2
# Generated by Django 1.11.18 on 2020-08-12 10:11
3
from __future__ import unicode_literals
4

  
5
from django.db import migrations, models
6

  
7

  
8
class Migration(migrations.Migration):
9

  
10
    dependencies = [
11
        ('agendas', '0056_auto_20200811_1611'),
12
    ]
13

  
14
    operations = [
15
        migrations.AddField(
16
            model_name='event', name='almost_full', field=models.BooleanField(default=False),
17
        ),
18
    ]
chrono/agendas/models.py
773 773
    )
774 774
    pricing = models.CharField(_('Pricing'), max_length=150, null=True, blank=True)
775 775
    url = models.CharField(_('URL'), max_length=200, null=True, blank=True)
776
    almost_full = models.BooleanField(default=False)
776 777
    full = models.BooleanField(default=False)
777 778
    cancelled = models.BooleanField(
778 779
        default=False, help_text=_("Cancel this event so that it won't be bookable anymore.")
......
820 821
            (self.booked_places >= self.places and self.waiting_list_places == 0)
821 822
            or (self.waiting_list_places and self.waiting_list >= self.waiting_list_places)
822 823
        )
824
        self.almost_full = bool(self.booked_places >= 0.9 * self.places)
823 825

  
824 826
    def in_bookable_period(self):
825 827
        if self.publication_date and localtime(now()).date() < self.publication_date:
......
981 983
    def save(self, *args, **kwargs):
982 984
        with transaction.atomic():
983 985
            super(Booking, self).save(*args, **kwargs)
984
            initial_value = self.event.full
986
            initial_values = self.event.full, self.event.almost_full
985 987
            self.event.check_full()
986
            if self.event.full != initial_value:
988
            if (self.event.full, self.event.almost_full) != initial_values:
987 989
                self.event.save()
988 990

  
989 991
    def cancel(self, trigger_callback=True):
990
-