from django.utils.html import conditional_escape as esc
from itertools import groupby
from calendar import HTMLCalendar
from django.utils.translation import gettext_lazy as _
from datetime import date
class EventCalendar(HTMLCalendar):
def __init__(self, pEvents):
super(EventCalendar, self).__init__()
self.events = self.group_by_day(pEvents.order_by('date'))
def formatday(self, day, weekday):
if day != 0:
cssclass = self.cssclasses[weekday]
if date.today() == date(self.year, self.month, day):
cssclass += ' today'
if day in self.events:
cssclass += ' filled'
body = []
for ev in self.events[day]:
body.append(_('' % ev.id)
body.append(esc(ev.nom))
body.append('
')
return self.day_cell(cssclass,
'