Attachment 'MonthCalendarTopList_original.py'

Download

   1 """
   2     MoinMoin - MonthCalendar Top List MACRO
   3                 
   4                 by Mark Stier
   5                 
   6                 May be used to create a Blog off of a MonthCalendar data structure.
   7                 (You'd need the MonthCalendar macro and the MonthCalendarRSS action
   8                 for that.)
   9                 
  10                 Based on:
  11                     MonthCalendar macro from MoinMoin 1.5.2
  12 
  13     Call this macro on a base page for a MonthCalendar.
  14                 It will pack the contents of all tips you get when moving a mouse
  15                 over some day entry into a simple, clickable list.
  16 
  17     This is an addition to the MonthCalendar macro, so you should make
  18                 yourself familiar with THAT one before trying to understand what this action
  19           can do for you.
  20 """
  21 
  22 Dependencies = ['namespace','time']
  23 
  24 import re, calendar, time, StringIO, os
  25 from datetime import date, timedelta
  26 from MoinMoin import config, wikiutil, util
  27 from MoinMoin.Page import Page
  28 
  29 def execute(macro, text):
  30         request = macro.request
  31         formatter = macro.formatter
  32         thispage = formatter.page.page_name
  33 
  34         max_days = 365
  35         n_max_def = 10
  36         if text is not None:
  37                 try:
  38                         n_max = int(text) # max entries to display
  39                 except ValueError:
  40                         n_max = n_max_def
  41         else:
  42                 n_max = n_max_def
  43         now = date.today()
  44 
  45         result = []
  46         n_cnt = 0
  47         for i in range(-1,max_days): # include next day because of different timezones
  48                 dte = now - timedelta(i)
  49                 datestr = "%4d-%02d-%02d" % (dte.year, dte.month, dte.day)
  50                 link = "%s/%s" % (thispage, datestr)
  51                 daypage = Page(request, link)
  52                 if daypage.exists() and request.user.may.read(daypage.page_name):
  53                         daycontent = daypage.get_raw_body()
  54                         header1_re = re.compile(r'^\s*=\s(.*)\s=$', re.MULTILINE) # re.UNICODE
  55                         for match in header1_re.finditer(daycontent):
  56                                 if match:
  57                                         title = match.group(1)
  58                                         result.append("<a href=\"%s/%s\">%s (%s)</a>" % (request.getBaseURL(),link,title,datestr))
  59                                         n_cnt = n_cnt + 1
  60                                         if n_cnt == n_max:
  61                                                 break
  62                         if n_cnt == n_max:
  63                                 break
  64         if len(result) == 0:
  65                 result = ["Sorry, there are no entries within the last %d days." % max_days]
  66         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-09-13 15:15:42, 2.5 KB) [[attachment:MonthCalendarTopList_1.0.py]]
  • [get | view] (2007-09-13 15:25:32, 2.7 KB) [[attachment:MonthCalendarTopList_1.1.py]]
  • [get | view] (2009-02-13 10:36:26, 3.3 KB) [[attachment:MonthCalendarTopList_1.2.1.py]]
  • [get | view] (2007-10-04 12:40:58, 3.2 KB) [[attachment:MonthCalendarTopList_1.2.py]]
  • [get | view] (2007-10-04 12:40:40, 2.7 KB) [[attachment:MonthCalendarTopList_original.py]]
 All files | Selected Files: delete move to page copy to page

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