Projet

Général

Profil

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

Valentin Deniaud, 16 juillet 2020 15:29

Télécharger (2,71 ko)

Voir les différences:

Subject: [PATCH 1/2] agendas: add almost_full event flag (#44158)

 .../migrations/0053_event_almost_full.py       | 18 ++++++++++++++++++
 chrono/agendas/models.py                       |  6 ++++--
 2 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 chrono/agendas/migrations/0053_event_almost_full.py
chrono/agendas/migrations/0053_event_almost_full.py
1
# -*- coding: utf-8 -*-
2
# Generated by Django 1.11.18 on 2020-07-16 13:14
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', '0052_event_cancelled'),
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
749 749
    )
750 750
    pricing = models.CharField(_('Pricing'), max_length=150, null=True, blank=True)
751 751
    url = models.CharField(_('URL'), max_length=200, null=True, blank=True)
752
    almost_full = models.BooleanField(default=False)
752 753
    full = models.BooleanField(default=False)
753 754
    cancelled = models.BooleanField(
754 755
        default=False, help_text=_("Cancel this event so that it won't be bookable anymore.")
......
788 789
            (self.booked_places >= self.places and self.waiting_list_places == 0)
789 790
            or (self.waiting_list_places and self.waiting_list >= self.waiting_list_places)
790 791
        )
792
        self.almost_full = bool(self.booked_places >= 0.9 * self.places)
791 793

  
792 794
    def in_bookable_period(self):
793 795
        if self.publication_date and localtime(now()).date() < self.publication_date:
......
931 933
    def save(self, *args, **kwargs):
932 934
        with transaction.atomic():
933 935
            super(Booking, self).save(*args, **kwargs)
934
            initial_value = self.event.full
936
            initial_values = self.event.full, self.event.almost_full
935 937
            self.event.check_full()
936
            if self.event.full != initial_value:
938
            if (self.event.full, self.event.almost_full) != initial_values:
937 939
                self.event.save()
938 940

  
939 941
    def cancel(self, trigger_callback=True):
940
-