On affiche le nombre d'événements aux mêmes dates
This commit is contained in:
parent
36a1815a4e
commit
e05f4d4869
@ -54,16 +54,20 @@ class CalendarDay:
|
||||
|
||||
class CalendarList:
|
||||
|
||||
def __init__(self, firstdate, lastdate, filter):
|
||||
def __init__(self, firstdate, lastdate, filter=None, exact=False):
|
||||
self.firstdate = firstdate
|
||||
self.lastdate = lastdate
|
||||
self.now = date.today()
|
||||
self.filter = filter
|
||||
|
||||
# start the first day of the first week
|
||||
self.c_firstdate = firstdate + timedelta(days=-firstdate.weekday())
|
||||
# end the last day of the last week
|
||||
self.c_lastdate = lastdate + timedelta(days=6-lastdate.weekday())
|
||||
if exact:
|
||||
self.c_firstdate = self.firstdate
|
||||
self.c_lastdate = self.lastdate
|
||||
else:
|
||||
# start the first day of the first week
|
||||
self.c_firstdate = firstdate + timedelta(days=-firstdate.weekday())
|
||||
# end the last day of the last week
|
||||
self.c_lastdate = lastdate + timedelta(days=6-lastdate.weekday())
|
||||
|
||||
|
||||
# create a list of CalendarDays
|
||||
@ -85,7 +89,8 @@ class CalendarList:
|
||||
|
||||
def fill_calendar_days(self):
|
||||
if self.filter is None:
|
||||
qs = Event.objects()
|
||||
from .models import Event
|
||||
qs = Event.objects.all()
|
||||
else:
|
||||
qs = self.filter.qs
|
||||
self.events = qs.filter(
|
||||
|
@ -16,6 +16,7 @@ from django.db.models import Q
|
||||
|
||||
from django.template.defaultfilters import date as _date
|
||||
from datetime import datetime, time, timedelta
|
||||
from .calendar import CalendarList
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -178,6 +179,14 @@ class Event(models.Model):
|
||||
last = self.get_consolidated_end_day()
|
||||
return [first + timedelta(n) for n in range(int((last - first).days) + 1)]
|
||||
|
||||
|
||||
def get_nb_events_same_dates(self):
|
||||
first = self.start_day
|
||||
last = self.get_consolidated_end_day()
|
||||
calendar = CalendarList(first, last, exact=True)
|
||||
return [(len(d.events), d.date) for dstr, d in calendar.calendar_days.items()]
|
||||
|
||||
|
||||
def is_single_day(self, intuitive=True):
|
||||
return self.start_day == self.get_consolidated_end_day(intuitive)
|
||||
|
||||
|
@ -19,13 +19,17 @@
|
||||
<!-- TODO: en même temps -->
|
||||
<article>
|
||||
<head>
|
||||
{% if event.is_single_day %}
|
||||
<h2>À la même date</h2>
|
||||
{% else %}
|
||||
<h2>Aux mêmes dates</h2>
|
||||
{% endif %}
|
||||
</head>
|
||||
<nav>
|
||||
<ul>
|
||||
{% for d in event.get_dates %}
|
||||
{% for nbevents_date in event.get_nb_events_same_dates %}
|
||||
<li>
|
||||
<a href="{% url 'day_view' d.year d.month d.day %}">{{ d }}</a>
|
||||
<a href="{% url 'day_view' nbevents_date.1.year nbevents_date.1.month nbevents_date.1.day %}">{{ nbevents_date.0 }} événement{{ nbevents_date.0 | pluralize }} le {{ nbevents_date.1 }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user