Implémentation de "l'heure du dodo": les événements qui finissent avant 8h du matin ne sont pas affichés à la date de fin.

Fix #4
On en profite pour régler un bug dans la recherche par intervalle
This commit is contained in:
Jean-Marie Favreau 2023-11-25 22:13:00 +01:00
parent b21cc8ee8c
commit ce5ad3501f
3 changed files with 34 additions and 13 deletions

View File

@ -1,5 +1,9 @@
from datetime import datetime, timedelta, date, time from datetime import datetime, timedelta, date, time
import calendar import calendar
from django.db.models import Q
import logging
logger = logging.getLogger(__name__)
def daterange(start, end, step=timedelta(1)): def daterange(start, end, step=timedelta(1)):
@ -32,15 +36,8 @@ class CalendarDay:
def is_today(self): def is_today(self):
return self.today return self.today
def is_event_finishing_early_in_this_day(self, event):
if event.end_day is None or event.end_time is None:
return False
if event.start_day == event.end_day:
return False
return event.end_day == self.date and event.end_time < time(8)
def add_event(self, event): def add_event(self, event):
if not self.is_event_finishing_early_in_this_day(event): if event.contains_date(self.date):
self.events.append(event) self.events.append(event)
if event.category is None: if event.category is None:
if not "" in self.events_by_category: if not "" in self.events_by_category:
@ -91,10 +88,14 @@ class CalendarList:
qs = Event.objects() qs = Event.objects()
else: else:
qs = self.filter.qs qs = self.filter.qs
self.events = qs.filter(start_day__lte=self.c_lastdate, start_day__gte=self.c_firstdate).order_by("start_day", "start_time") self.events = qs.filter(
(Q(end_day__isnull=True) & Q(start_day__gte=self.c_firstdate) & Q(start_day__lte=self.c_lastdate)) |
(Q(end_day__isnull=False) & ~(Q(start_day__gt=self.c_lastdate) | Q(end_day__lt=self.c_firstdate)))
).order_by("start_day", "start_time")
logger.error(str(len(self.events)) + " events")
for e in self.events: for e in self.events:
for d in daterange(e.start_day, e.end_day): for d in daterange(e.start_day, e.end_day):
logger.error(d)
if d.__str__() in self.calendar_days: if d.__str__() in self.calendar_days:
self.calendar_days[d.__str__()].add_event(e) self.calendar_days[d.__str__()].add_event(e)

View File

@ -8,7 +8,10 @@ from ckeditor.fields import RichTextField
from django.template.defaultfilters import date as _date from django.template.defaultfilters import date as _date
from datetime import datetime from datetime import datetime, time, timedelta
import logging
logger = logging.getLogger(__name__)
class StaticContent(models.Model): class StaticContent(models.Model):
@ -120,6 +123,23 @@ class Event(models.Model):
tags = ArrayField(models.CharField(max_length=64), verbose_name=_('Tags'), help_text=_("A list of tags that describe the event."), blank=True, null=True) tags = ArrayField(models.CharField(max_length=64), verbose_name=_('Tags'), help_text=_("A list of tags that describe the event."), blank=True, null=True)
def get_consolidated_end_day(self, intuitive=True):
if intuitive:
end_day = self.get_consolidated_end_day(False)
if end_day != self.start_day and self.end_time and self.end_time < time(8):
return end_day + timedelta(days=-1)
else:
return end_day
else:
return self.end_day if self.end_day else self.start_day
def is_single_day(self, intuitive=True):
return self.start_day == self.get_consolidated_end_day(intuitive)
def contains_date(self, d, intuitive=True):
logger.error("et toc")
#logger.error(str(d) + " " + str(self.start_day) + " " + str(self.get_consolidated_end_day(intuitive)))
return d >= self.start_day and d <= self.get_consolidated_end_day(intuitive)
def get_absolute_url(self): def get_absolute_url(self):
return reverse("view_event", kwargs={"pk": self.pk, "extra": slugify(self.title)}) return reverse("view_event", kwargs={"pk": self.pk, "extra": slugify(self.title)})

View File

@ -1,7 +1,7 @@
{% load utils_extra %} {% load utils_extra %}
<article class='ephemeris'> <article class='ephemeris'>
{% if not event.end_day or event.start_day == event.end_day %} {% if event.is_single_day %}
{{ event.start_day |date:"l" }}<br /> {{ event.start_day |date:"l" }}<br />
<a href="{{ event.start_day | url_day }}?{{ filter.get_url }}"><span class="large">{{ event.start_day |date:"j" }}</span><br /> <a href="{{ event.start_day | url_day }}?{{ filter.get_url }}"><span class="large">{{ event.start_day |date:"j" }}</span><br />
{{ event.start_day |date:"F" }}</a> {{ event.start_day |date:"F" }}</a>
@ -18,7 +18,7 @@
{{ event.start_day |date:"F" }} {{ event.start_day |date:"F" }}
{% endif %}</a><br /> {% endif %}</a><br />
au au
{{ event.start_day |date:"D" }} <br /> {{ event.end_day |date:"D" }} <br />
<a href="{{ event.end_day | url_day }}?{{ filter.get_url }}"><span class="large">{{ event.end_day |date:"j" }}</span><br /> <a href="{{ event.end_day | url_day }}?{{ filter.get_url }}"><span class="large">{{ event.end_day |date:"j" }}</span><br />
{{ event.end_day |date:"F" }}</a> {{ event.end_day |date:"F" }}</a>
{% endif %} {% endif %}