Attachment 'MonthCalendarTopListMulti.py'

Download

   1 #format python
   2 
   3 """
   4 
   5     --------------------------
   6     Modified MonthCalendar Top List MACRO to allow for multiple MonthCalendars
   7     to be included in the 'Top List'.
   8 
   9     example  [[MonthCalendarTopListMulti(30, /MyCalendar, /OtherCalendar/Calendar1)]]
  10 
  11     modified by ScottSheffield
  12     --------------------------
  13 
  14 
  15 
  16     MoinMoin - MonthCalendar Top List MACRO
  17 		
  18 		by Mark Stier
  19 		
  20 		May be used to create a Blog off of a MonthCalendar data structure.
  21 		(You'd need the MonthCalendar macro and the MonthCalendarRSS action
  22 		for that.)
  23 		
  24 		Based on:
  25 		    MonthCalendar macro from MoinMoin 1.5.2
  26 
  27     Call this macro on a base page for a MonthCalendar.
  28 		It will pack the contents of all tips you get when moving a mouse
  29 		over some day entry into a simple, clickable list.
  30 
  31     This is an addition to the MonthCalendar macro, so you should make
  32 		yourself familiar with THAT one before trying to understand what this action
  33 	  can do for you.
  34 """
  35 
  36 Dependencies = ['namespace','time']
  37 
  38 import re, calendar, time, StringIO, os
  39 from datetime import date, timedelta
  40 from MoinMoin import config, wikiutil, util
  41 from MoinMoin.Page import Page
  42 
  43 def execute(macro, text):
  44     request = macro.request
  45     formatter = macro.formatter
  46     thispage = formatter.page.page_name
  47 
  48     max_days = 365
  49     n_max_def = 10
  50     
  51     now = date.today()
  52     result = []
  53     n_cnt = 0
  54     
  55     if text:
  56         arguments = text.split(',')
  57         arguments = [argument.strip() for argument in arguments]
  58         if len(arguments) == 1:
  59                 try:
  60                         n_max = int(arguments)
  61                 except ValueError:
  62                         n_max = n_max_def
  63                         cals = arguments
  64         else:
  65                 try:
  66                         n_max = int(arguments[0])
  67                         cals = arguments[1:]
  68                 except ValueError:
  69                         n_max = n_max_def
  70                         cals = arguments
  71     else:
  72         n_max = n_max_def
  73         cals = [formatter.page.page_name]
  74         
  75     for i in range(-1,max_days): # include next day because of different timezones
  76             dte = now - timedelta(i)
  77             datestr = "%4d-%02d-%02d" % (dte.year, dte.month, dte.day)
  78             for cal in cals:
  79                     link = "%s/%s" % (cal, datestr)
  80                     daypage = Page(request, link)
  81                                     
  82                     if daypage.exists() and request.user.may.read(daypage.page_name):
  83                             daycontent = daypage.get_raw_body()
  84                             header1_re = re.compile(r'^\s*=\s(.*)\s=$', re.MULTILINE) # re.UNICODE
  85                             for match in header1_re.finditer(daycontent):
  86                                     if match:
  87                                             title = match.group(1)
  88                                             result.append("<a href=\"%s/%s\">%s (%s)</a>" % (request.getBaseURL(),link,title,datestr))
  89                                             n_cnt = n_cnt + 1
  90                                             if n_cnt == n_max:
  91                                                     break
  92                             if n_cnt == n_max:
  93                                     break
  94                     if n_cnt == n_max:
  95                         break
  96     if len(result) == 0:
  97         result = ["sorry, there are no entries within the last %d days." % max_days]
  98     return formatter.rawHTML('<br>'.join(result))

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007-06-23 04:41:25, 3.4 KB) [[attachment:MonthCalendarTopListMulti.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.