Simple Calendar

Here is a simple calendar that utilizes the Python calendar module and prints out an HTML table to display the output.

All of the code is in the template, with the intention that the "calendar" macro could be included in any page of the module without needing to initialize its values. The cal.py page module is just a dummy module to run the template for this example.

Purpose

Demonstrates:

Source Code

cal.py

{{{def page_process(ctx):

def page_display(ctx):

}}}

cal.html

{{{<al-macro name="calendar"> <al-exec expr="import calendar import time now = time.localtime() thisyear, thismonth, thisdate = (now[0], now[1], now[2]) calendar.setfirstweekday(6) monthcal = calendar.monthcalendar(thisyear, thismonth) daynames = calendar.weekheader(2).split() calheader = time.strftime('%B %Y', now) " />

<table width="49px" bgcolor="#000000" cellspacing="1" cellpadding="4"> <tr bgcolor="#999999">

</tr>

<tr bgcolor="#CCCCCC" > <al-for iter="dayname" expr="daynames">

</al-for> </tr>

<al-for iter="weekrow" expr="monthcal"> <tr bgcolor="#FFFFFF">

</tr> </al-for> </al-macro>

<html> <head><title>Calendar</title></head> <body> <al-expand name="calendar" /> </body> </html> }}}

None: SimpleCalendar (last edited 2011-02-15 06:05:17 by localhost)