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:
parent
b21cc8ee8c
commit
ce5ad3501f
@ -1,5 +1,9 @@
|
||||
from datetime import datetime, timedelta, date, time
|
||||
import calendar
|
||||
from django.db.models import Q
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def daterange(start, end, step=timedelta(1)):
|
||||
@ -32,15 +36,8 @@ class CalendarDay:
|
||||
def is_today(self):
|
||||
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):
|
||||
if not self.is_event_finishing_early_in_this_day(event):
|
||||
if event.contains_date(self.date):
|
||||
self.events.append(event)
|
||||
if event.category is None:
|
||||
if not "" in self.events_by_category:
|
||||
@ -91,10 +88,14 @@ class CalendarList:
|
||||
qs = Event.objects()
|
||||
else:
|
||||
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 d in daterange(e.start_day, e.end_day):
|
||||
logger.error(d)
|
||||
if d.__str__() in self.calendar_days:
|
||||
self.calendar_days[d.__str__()].add_event(e)
|
||||
|
||||
|
@ -8,7 +8,10 @@ from ckeditor.fields import RichTextField
|
||||
|
||||
|
||||
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):
|
||||
@ -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)
|
||||
|
||||
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):
|
||||
return reverse("view_event", kwargs={"pk": self.pk, "extra": slugify(self.title)})
|
||||
|
@ -1,7 +1,7 @@
|
||||
{% load utils_extra %}
|
||||
|
||||
<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 />
|
||||
<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>
|
||||
@ -18,7 +18,7 @@
|
||||
{{ event.start_day |date:"F" }}
|
||||
{% endif %}</a><br />
|
||||
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 />
|
||||
{{ event.end_day |date:"F" }}</a>
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user