forked from nequals30/MDcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendarClass.py
68 lines (58 loc) · 2.36 KB
/
calendarClass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
This extends the HTMLCalendar class from calendar.
All aesthetic adjustments should be made in the mdStyle.css function
"""
from calendar import HTMLCalendar
import datetime
# Extending HTMLCalendar class from calendar
class mdCalendar(HTMLCalendar):
def __init__(self,firstweekday=6):
self.firstweekday = firstweekday
self.cssclass_today = "today"
self.dtToday = datetime.datetime.today().date()
def formatMonthMd(self, theyear, themonth, mdList, rrList, customIdDict):
v=[]
a = v.append
a('<table '
'width="100%%" '
'cellpadding="0" '
'cellspacing="0" '
'class="%s">' % (self.cssclass_month))
a('\n')
a(self.formatmonthname(theyear,themonth))
a('\n')
a(self.formatweekheader())
a('\n')
for week in self.monthdays2calendar(theyear, themonth):
a(self.formatweekMd(week,themonth,theyear,mdList,rrList,customIdDict))
a('\n')
a('</table>')
a('\n')
return ''.join(v)
def formatweekMd(self,theweek,mo,yr,mdList,rrList,customIdDict):
# just passes mdList through
s = ''.join(self.formatdayMd(d,wd,mo,yr,mdList,rrList,customIdDict) for (d,wd) in theweek)
return '<tr>%s</tr>' % s
def formatdayMd(self,day,weekday,mo,yr,mdList,rrList,customIdDict):
if day == 0:
return '<td class="%s"> </td>' % self.cssclass_noday
else:
thisDay = datetime.date(yr,mo,day)
thisDayStr = thisDay.strftime('%Y-%m-%d')
if thisDay == self.dtToday:
dayCssClass = self.cssclass_today
elif thisDay < self.dtToday:
dayCssClass = self.cssclasses[weekday] + " crossed"
else:
dayCssClass = self.cssclasses[weekday]
if (thisDayStr in customIdDict) and (customIdDict[thisDayStr] != ""):
dayCssClass = dayCssClass + " " + customIdDict[thisDayStr]
if thisDayStr in mdList:
dayContents = mdList[thisDayStr]
else:
dayContents = ''
if thisDayStr in rrList:
dayContents = dayContents + "" + rrList[thisDayStr]
return ('<td height="100px" width="14%%" class="%s">%d<br/>'+
dayContents +
'</td>') % (dayCssClass,day)