我的日历有一个功能
def formatweek(self, theweek, events):
week = ''
for d, weekday in theweek:
#return f'<tr style="color:blue";> {week} </tr>'
week += self.formatday(d, events)
return f'<tr> {week} </tr>'
def formatday(self, day, events):
events_per_day = events.filter(start_time__day=day)
d = ''
for event in events_per_day:
d += f'<li> {event.get_html_url} </li>'
if day != 0:
return f"<td><span class='date'>{day}</span><ul> {d} </ul></td>"
return '<td></td>'
其中theweek
是对列表:
[(1, 0), (2, 1), (3, 2), (4, 3), (5, 4), (6, 5), (7, 6)]
[(8, 0), (9, 1), (10, 2), (11, 3), (12, 4), (13, 5), (14, 6)]
[(15, 0), (16, 1), (17, 2), (18, 3), (19, 4), (20, 5), (21, 6)]
[(22, 0), (23, 1), (24, 2), (25, 3), (26, 4), (27, 5), (28, 6)]
[(29, 0), (30, 1), (31, 2), (0, 3), (0, 4), (0, 5), (0, 6)]
成对的第一个数字(例如(1))是一个月中的一天(1.januar),第二个是工作日名称的数字(0-星期一,1-星期二等)
d
和weekday
成为循环中的int
。 d
=每月的天数(1,2,3,4 ....),Weekday
=天数(星期一-0,星期二-1等)。
它为表返回此return f'<tr> {week} </tr>'
。我想另外返回f'<tr style="color:blue";> {5 (or 6)} </tr>'
的第5和第6个工作日数字(星期六,星期日)。
简单地说:我想度过一个周末变成蓝色。