diff --git a/home/models.py b/home/models.py index 5d21b5ac258c5081f8fb1679ed2ba3c1a42e762f..78a8af3f57cdc0ac816d97921dcea8d25045be17 100644 --- a/home/models.py +++ b/home/models.py @@ -1,7 +1,11 @@ +import datetime + from django.db import models from django.utils.translation import gettext_lazy as _ +from django.utils import timezone from accounts.models import EmailUser +from site_settings.models import SiteSettings class InterludesActivity(models.Model): """une activité des interludes (i.e. JDR, murder)...""" @@ -138,7 +142,7 @@ class InterludesSlot(models.Model): help_text="Utilisez '{}' pour insérer le titre de l'activité correspondante".format( TITLE_SPECIFIER), ) - start = models.DateTimeField("début", null=True, blank=True) + start = models.DateTimeField("début") room = models.CharField("salle", max_length=100, null=True, blank=True) on_planning = models.BooleanField( "afficher sur le planning", default=False, @@ -158,18 +162,62 @@ class InterludesSlot(models.Model): @property def end(self): """Heure de fin du créneau""" - if (not self.start) or (not self.activity.duration): - return None return self.start + self.activity.duration def conflicts(self, other: "InterludesSlot") -> bool: """Check whether these slots overlap""" - if self.end is None or other.end is None: - return False if self.start <= other.start: return other.start <= self.end return self.start <= other.end + @staticmethod + def relative_day(date: datetime.datetime) -> int: + """Relative day to start. + - friday 04:00 -> 03:59 = day 0 + - saturday 04:00 -> 03:59 = day 1 + - sunday 04:00 -> 03:59 = day 2 + returns 0 if no date_start is defined in settings""" + settings = SiteSettings.load() + if settings.date_start: + return (date - timezone.datetime.combine( + settings.date_start, datetime.time(hour=4), timezone.get_current_timezone() + )).days + else: + return 0 + + @staticmethod + def fake_date(date: datetime.datetime): + """Fake day for display on the (single day planning)""" + print("hllo!!!! ================") + settings = SiteSettings.load() + if settings.date_start: + x = timezone.datetime.combine( + settings.date_start, + date.time(), + timezone.get_current_timezone() + ) + print(x) + return x + return None + + @property + def start_day(self) -> int: + """returns a day (0-2)""" + return self.relative_day(self.start) + + @property + def end_day(self) -> int: + """returns a day (0-2)""" + return self.relative_day(self.end) + + @property + def planning_start(self) -> int: + return self.fake_date(self.start) + + @property + def planning_end(self) -> int: + return self.fake_date(self.end) + def __str__(self) -> str: return self.title.replace(self.TITLE_SPECIFIER, self.activity.title) diff --git a/home/templates/_planning.html b/home/templates/_planning.html index cac6d4c67c329897ff5a930a3f362725aeaba4df..2453992e9c6f8b6f8f95b887f4f4d63385b8dbd6 100644 --- a/home/templates/_planning.html +++ b/home/templates/_planning.html @@ -9,41 +9,41 @@ I.E we set all dates to the first day (Friday) and set groups allowing vertical const container = document.getElementById('planning'); const groups = new vis.DataSet([ - {id: {{ friday }}, content: "Ven.", order: 0}, - {id: {{ saturday }}, content: "Sam.", order: 1}, - {id: {{ sunday }}, content: "Dim.", order: 2}, + {id: 0, content: "Ven.", order: 0}, + {id: 1, content: "Sam.", order: 1}, + {id: 2, content: "Dim.", order: 2}, ]); // Items in the timeline const items = new vis.DataSet([ {% for slot in planning %} - {% if slot.start|date:"d" == slot.end|date:"d" %} + {% if slot.start_day == slot.end_day %} { content: '<div style="background-color: yellow;"><a class="hidden" href="#{{ slot.activity.slug }}"><div><strong>{{ slot }}</strong><br>{{ slot.room|default:"" }}</div></a></div>', title: '<strong>{{ slot }}</strong><br>{{ slot.room|default:"" }}', - start: '{{ settings.date_start|date:"Y-m-d"}} {{ slot.start|date:"H:i:s" }}', + start: '{{ slot.planning_start|date:"Y-m-d H:i:s"}}', align: 'left', - group: {{ slot.start|date:"d" }}, - end:'{{ settings.date_start|date:"Y-m-d"}} {{ slot.end|date:"H:i:s" }}', + group: {{ slot.start_day }}, + end:'{{ slot.planning_end|date:"Y-m-d H:i:s"}}', className: "color-{{ slot.color }}", }, {% else %} // activity spans multiple days { content: '<a class="hidden" href="#{{ slot.activity.slug }}"><div><strong>{{ slot }}</strong><br>{{ slot.room|default:"" }}</div></a>', title: '<strong>{{ slot }}</strong><br>{{ slot.room|default:"" }}', - start: '{{ settings.date_start|date:"Y-m-d"}} {{ slot.start|date:"H:i:s" }}', + start: '{{ slot.planning_start|date:"Y-m-d H:i:s"}}', align: 'left', - group: {{ slot.start|date:"d" }}, - end:'{{ settings.date_start|date:"Y-m-d"}} 23:59:59', + group: {{ slot.start_day }}, + end:'{{ settings.date_2|date:"Y-m-d"}} 04:00:00', className: "color-{{ slot.color }}", }, { content: '<a class="hidden" href="#{{ slot.activity.slug }}"><div><strong>{{ slot }}</strong><br>{{ slot.room|default:"" }}</div></a>', title: '<strong>{{ slot }}</strong><br>{{ slot.room|default:"" }}', - start: '{{ settings.date_start|date:"Y-m-d"}} 00:00:00', + start: '{{ settings.date_start|date:"Y-m-d"}} 04:00:00', align: 'left', - group: {{ slot.start|date:"d"|add:"1" }}, - end:'{{ settings.date_start|date:"Y-m-d"}} {{ slot.end|date:"H:i:s" }}', + group: {{ slot.end_day }}, + end:'{{ slot.planning_end|date:"Y-m-d H:i:s"}}', className: "color-{{ slot.color }}", }, {% endif %} @@ -51,8 +51,8 @@ I.E we set all dates to the first day (Friday) and set groups allowing vertical ]); // Configuration for the Timeline - const start = '{{ settings.date_start|date:"Y-m-d"}} 00:00:00'; - const end = '{{ settings.date_start|date:"Y-m-d"}} 23:59:59'; + const start = '{{ settings.date_start|date:"Y-m-d"}} 04:00:00'; + const end = '{{ settings.date_start|date:"Y-m"}}-{{ saturday }} 04:00:00'; const options = { showMajorLabels: false, showCurrentTime: false, @@ -84,7 +84,7 @@ I.E we set all dates to the first day (Friday) and set groups allowing vertical .vis-item a, .vis-item a:link, .vis-item a:visited { text-decoration: none; color: white; - width: 100% + width: 100%; } .vis-item a div { width: 100%; diff --git a/site_settings/models.py b/site_settings/models.py index 3df3873581451caf90a3c3d09258d4057420b381..1dc8fc6148374eff228fbfb9d68fe635d9fca233 100644 --- a/site_settings/models.py +++ b/site_settings/models.py @@ -1,3 +1,5 @@ +from datetime import timedelta + from django.db import models from django.core.cache import cache from django.utils.timezone import now @@ -107,6 +109,12 @@ class SiteSettings(SingletonModel): return now() >= self.inscriptions_end return False + @property + def date_2(self): + """The date of the second day""" + if self.date_start: + return self.date_start + timedelta(days=1) + class Meta: verbose_name = "paramètres" verbose_name_plural = "paramètres"