Changeset 88

Show
Ignore:
Timestamp:
07/28/05 15:27:06 (3 years ago)
Author:
mgood
Message:

WikiCalendarMacro:

add contributed month/year navigation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wikicalendarmacro/stable/WikiCalendar.py

    r53 r88  
    1 # Copyright (C) 2005 Matthew Good <matt@matt-good.net> 
     1# Copyright (C) 2005 Matthew Good <trac@matt-good.net> 
     2# Copyright (C) 2005 Jan Finell <finell@cenix-bioscience.com>  
    23# 
    34# "THE BEER-WARE LICENSE" (Revision 42): 
    4 # <matt@matt-good.net> wrote this file.  As long as you retain this notice you 
     5# <trac@matt-good.net> wrote this file.  As long as you retain this notice you 
    56# can do whatever you want with this stuff.  If we meet some day, and you think 
    67# this stuff is worth it, you can buy me a beer in return.  Matthew Good 
     
    89#  http://people.freebsd.org/~phk/) 
    910# 
    10 # Author: Matthew Good <matt@matt-good.net> 
     11# Author: Matthew Good <trac@matt-good.net> 
     12# Month/Year navigation by: Jan Finell <finell@cenix-bioscience.com> 
    1113 
    1214import time 
     
    2931    cal = calendar.monthcalendar(year, month) 
    3032 
    31     buff = StringIO() 
    3233 
    3334    date = [year, month] + [1] * 7 
    3435 
     36    # url to the current page (used in the navigation links) 
     37    thispageURL = env.href.wiki(hdf.getValue('wiki.page_name', '')) 
     38    # for the prev/next navigation links 
     39    prevMonth = month-1 
     40    prevYear  = year 
     41    nextMonth = month+1 
     42    nextYear  = year 
     43    # check for year change (KISS version) 
     44    if prevMonth == 0: 
     45        prevMonth = 12 
     46        prevYear -= 1 
     47    if nextMonth == 13: 
     48        nextMonth = 1 
     49        nextYear += 1 
     50 
     51    # building the output 
     52    buff = StringIO() 
    3553    buff.write('<table><caption>') 
     54 
     55    # prev month link 
     56    prevMonthURL = thispageURL+'?month=%d&year=%d' % (prevMonth, prevYear) 
     57    buff.write('<a href="%s">&lt; </a>' % prevMonthURL) 
     58    # the caption 
    3659    buff.write(time.strftime('%B %Y', tuple(date))) 
     60    # next month link 
     61    nextMonthURL = thispageURL+'?month=%d&year=%d' % (nextMonth, nextYear) 
     62    buff.write('<a href="%s"> &gt;</a>' % nextMonthURL) 
    3763    buff.write('</caption>\n<thead><tr align="center">') 
     64     
    3865    for day in calendar.weekheader(2).split(): 
    3966        buff.write('<th scope="col">%s</th>' % day) 
     
    6693    buff.close() 
    6794    return table 
     95