1.13.2 Calendar Tools

The web.util.calendarTools module provides two functions month() to display an HTML calendar for the specified month and calendar() to display a range of months in HTML.

#!/usr/bin/env python

# show python where the modules are
import sys; sys.path.append('../'); sys.path.append('../../../') 
import web.error; web.error.enable()
import web.util.calendarTools

print web.header()

calendars = [
'web.util.calendarTools.month(year=2004,month=12)',
"""web.util.calendarTools.month(
    year=2004,
    month=12,
    dayNameLength=0,
    firstDay=5
)""",
"""web.util.calendarTools.month(
    year=2004,
    month=12,
    dayNameLength=3,
    monthURL = 'month.py?month=%(month)s&year=%(year)s',
    previousURL = 'previous.py?month=%(month)s&year=%(year)s',
    nextURL = 'next.py?month=%(month)s&year=%(year)s',
    previousHTML = 'prev',
    nextHTML = 'next',
)""",
"""web.util.calendarTools.month(
    year=2004,
    month=12,
    daysURL = 'day.py?day=%(day)s&month=%(month)s&year=%(year)s',
    days = {
        12:['day.py?day=12', 'twelve', 'style="background: #eee"']
    }
)""",
"""web.util.calendarTools.month(
    year=2004,
    month=12,
    tableColor = '#eeeecc',
    barColor = '#eeeeee',
    cellPadding = 16,
)""",

]

fullCal="""web.util.calendarTools.calendar(
    startYear=2004, 
    startMonth=9, 
    months=12, 
    cols=3, 
    dayNameLength=1, 
    barColor="#eeeeee"
)
"""
output = ''
for cal in calendars:
    output += """<hr><table border="0" cellPadding=10 width="100%%">
    <tr><td width="1%%">%s</td><td width="99%%"><pre>%s</pre></td>
    </tr></table>"""%(eval(cal), web.encode(cal, mode='form'))
print """
<html>
<style>
.calendarTools-month-header{
    font-family: sans-serif;
    font-weight: bold;
}
</style>
<body>
<h1>Example Calendars</h1>
<p>This page demonstrates the parameters used to generate HTML 
calendars. They can also be styled using CSS stylesheets. For 
example the following is uses in this HTML page to make all the
calendar headings a sans serif font:</p>
<pre>
&lt;style&gt;
.calendarTools-month-header{
    font-family: sans-serif;
    font-weight: bold;
}
&lt;/style&gt;
</pre>

%s

<hr>
<p>The next calendar is generated using the following code:
<pre>
%s
</pre>

%s
</body>
</html>"""%(output, fullCal, eval(fullCal))

You can test this example by starting the test webserver in scripts/webserver.py and visiting http://localhost:8080/doc/src/lib/webserver-web-util-calendar.py on your local machine.

XXX Full function reference