Projet

Général

Profil

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

Valentin Deniaud, 29 juillet 2020 11:51

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-07-29 09:50
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_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
771 771
    )
772 772
    pricing = models.CharField(_('Pricing'), max_length=150, null=True, blank=True)
773 773
    url = models.CharField(_('URL'), max_length=200, null=True, blank=True)
774
    almost_full = models.BooleanField(default=False)
774 775
    full = models.BooleanField(default=False)
775 776
    cancelled = models.BooleanField(
776 777
        default=False, help_text=_("Cancel this event so that it won't be bookable anymore.")
......
810 811
            (self.booked_places >= self.places and self.waiting_list_places == 0)
811 812
            or (self.waiting_list_places and self.waiting_list >= self.waiting_list_places)
812 813
        )
814
        self.almost_full = bool(self.booked_places >= 0.9 * self.places)
813 815

  
814 816
    def in_bookable_period(self):
815 817
        if self.publication_date and localtime(now()).date() < self.publication_date:
......
965 967
    def save(self, *args, **kwargs):
966 968
        with transaction.atomic():
967 969
            super(Booking, self).save(*args, **kwargs)
968
            initial_value = self.event.full
970
            initial_values = self.event.full, self.event.almost_full
969 971
            self.event.check_full()
970
            if self.event.full != initial_value:
972
            if (self.event.full, self.event.almost_full) != initial_values:
971 973
                self.event.save()
972 974

  
973 975
    def cancel(self, trigger_callback=True):
974
-