From 951cf4f4d79c73f86b6ed73a04be1239c8e9752c Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Tue, 26 May 2020 19:36:18 +0200
Subject: [PATCH 1/2] manager: add stop_datetime on event (#37352)

---
 .../migrations/0044_auto_20200526_1933.py     | 24 +++++++++++++++++++
 chrono/agendas/models.py                      |  3 ++-
 chrono/manager/forms.py                       |  2 ++
 3 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 chrono/agendas/migrations/0044_auto_20200526_1933.py

diff --git a/chrono/agendas/migrations/0044_auto_20200526_1933.py b/chrono/agendas/migrations/0044_auto_20200526_1933.py
new file mode 100644
index 0000000..22d9036
--- /dev/null
+++ b/chrono/agendas/migrations/0044_auto_20200526_1933.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2020-05-26 17:33
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('agendas', '0043_booking_user_external_id'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='event',
+            options={'ordering': ['agenda', 'start_datetime', 'stop_datetime', 'label']},
+        ),
+        migrations.AddField(
+            model_name='event',
+            name='stop_datetime',
+            field=models.DateTimeField(blank=True, null=True, verbose_name='Date/time'),
+        ),
+    ]
diff --git a/chrono/agendas/models.py b/chrono/agendas/models.py
index 65c86d3..4e04477 100644
--- a/chrono/agendas/models.py
+++ b/chrono/agendas/models.py
@@ -633,16 +633,17 @@ class MeetingType(models.Model):
             'slug': self.slug,
             'duration': self.duration,
         }
 
 
 class Event(models.Model):
     agenda = models.ForeignKey(Agenda, on_delete=models.CASCADE)
     start_datetime = models.DateTimeField(_('Date/time'))
+    stop_datetime = models.DateTimeField(_('Ending date/time'), null=True, blank=True)
     places = models.PositiveIntegerField(_('Places'))
     waiting_list_places = models.PositiveIntegerField(_('Places in waiting list'), default=0)
     label = models.CharField(
         _('Label'),
         max_length=150,
         null=True,
         blank=True,
         help_text=_('Optional label to identify this date.'),
@@ -653,17 +654,17 @@ 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)
     full = models.BooleanField(default=False)
     meeting_type = models.ForeignKey(MeetingType, null=True, on_delete=models.CASCADE)
     desk = models.ForeignKey('Desk', null=True, on_delete=models.CASCADE)
 
     class Meta:
-        ordering = ['agenda', 'start_datetime', 'label']
+        ordering = ['agenda', 'start_datetime', 'stop_datetime', 'label']
         unique_together = ('agenda', 'slug')
 
     def __str__(self):
         if self.label:
             return self.label
         return date_format(localtime(self.start_datetime), format='DATETIME_FORMAT')
 
     def save(self, *args, **kwargs):
diff --git a/chrono/manager/forms.py b/chrono/manager/forms.py
index 277ccc7..a49549c 100644
--- a/chrono/manager/forms.py
+++ b/chrono/manager/forms.py
@@ -68,26 +68,28 @@ class AgendaEditForm(AgendaAddForm):
 
 
 class NewEventForm(forms.ModelForm):
     class Meta:
         model = Event
         widgets = {
             'agenda': forms.HiddenInput(),
             'start_datetime': DateTimeWidget(),
+            'stop_datetime': DateTimeWidget(),
         }
         exclude = ['full', 'meeting_type', 'desk', 'slug']
 
 
 class EventForm(forms.ModelForm):
     class Meta:
         model = Event
         widgets = {
             'agenda': forms.HiddenInput(),
             'start_datetime': DateTimeWidget(),
+            'stop_datetime': DateTimeWidget(),
         }
         exclude = ['full', 'meeting_type', 'desk']
 
 
 class NewMeetingTypeForm(forms.ModelForm):
     class Meta:
         model = MeetingType
         widgets = {
-- 
2.26.2

