## CALENDAR WIDGET ## Render a month calendar as a HTML table. ## ## It takes tree optional params: ## current_date ## a date object (datetime.date) with the date to show, defaults to today's date if nothing is given ## calendar_class ## class attribute for the calendar table, defaults to "calendar" if nothing is given ## calendar_id ## id attribute for the calendar table ## ## When a day is clicked, the link points back to the original page with a ## additional "date" param, which is an date in the ISO format YYYY-MM-DD. ## TODO: maybe use /yyyy/mm/dd format instead? is it possible? #from datetime import date #import calendar ## save today's date #attr $today_date = date.today() #set $current_date = $getVar('current_date', date.today()) ## Figure out week day names #set $week_days = calendar.weekheader(2).split() ## calendar for $current_date month #set $month = $calendar.monthcalendar($current_date.year, $current_date.month) #from datetime import timedelta #set $prev_month = $current_date - $timedelta(days=31) #set $prev_month = $date($prev_month.year, $prev_month.month, 1) #set $next_month = $current_date + $timedelta(days=31) #set $next_month = $date($next_month.year, $next_month.month, 1) #def is_today(current_date) #if $current_date == $today_date #return 'today' #end if #return '' #end def #for $day in $week_days #end for #for $row in $month #for $day in $row #if $day #set $d = $date($current_date.year, $current_date.month, $day) #else #end if #end for #end for
 $current_date.strftime('%B %Y') 
$day
$day  
Today