Attachment 'MonthCalendarTopList_1.2.py'

Download

   1 """
   2     MoinMoin - MonthCalendarTopList Macro
   3     
   4     You can use this macro to generate a list of recent entries from 
   5      a MonthCalendar data structure.
   6     This is an addition to the MonthCalendar macro, so you should make
   7       yourself familiar with THAT one before trying to understand what this action
   8       can do for you.          
   9 
  10     Call this macro on a base page for a MonthCalendar.
  11     It will pack the contents of all tips you get when moving a mouse
  12      over some day entry into a simple, clickable list.
  13 
  14 
  15      @copyright: ?-2006 Mark Stier
  16      @copyright: 2007 Eric Veiras Galisson 
  17      @license: GNU GPL v2 - see http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt for details. 
  18                     
  19     Revisions:
  20     * unnumbered: original version by Mark Stier. 
  21     
  22     * 1.0
  23       * modification to make it work with MoinMoin 1.5
  24     * 1.1
  25       * added support of titles in the form:
  26         * = title =
  27         or
  28         * '''title'''
  29       * if no title exists, the page still appears in the list named Untitled
  30       * only the first title appears
  31     * 1.2
  32       * back to the previous behaviour allowing several titles
  33     
  34     
  35     Usage:
  36       [[MonthCalendarTopList(X)]]
  37       
  38       will display the last X days entries.
  39 """
  40 
  41 Dependencies = ['namespace','time']
  42 
  43 import re, calendar, time, StringIO, os
  44 from datetime import date, timedelta
  45 from MoinMoin import config, wikiutil, util
  46 from MoinMoin.Page import Page
  47 
  48 def execute(macro, text):
  49         request = macro.request
  50         formatter = macro.formatter
  51         thispage = formatter.page.page_name
  52 
  53         max_days = 365
  54         n_max_def = 10
  55         if text is not None:
  56                 try:
  57                         n_max = int(text) # max entries to display
  58                 except ValueError:
  59                         n_max = n_max_def
  60         else:
  61                 n_max = n_max_def
  62         now = date.today()
  63 
  64     	raw_str = r"""
  65         	^\s*		# line start
  66 
  67         	(	
  68                 '''\s*(.*)\s*'''
  69        	    |
  70                 =\s+(.*)\s+=
  71             )
  72 
  73             \s*$        # end of line
  74             """		
  75 
  76 	compile_obj = re.compile(raw_str, re.MULTILINE|re.VERBOSE)
  77 
  78         result = []
  79         n_cnt = 0
  80         for i in range(-1,n_max): # include next day because of different timezones
  81             dte = now - timedelta(i)
  82             datestr = "%4d-%02d-%02d" % (dte.year, dte.month, dte.day)
  83             link = "%s/%s" % (thispage, datestr)
  84             daypage = Page(request, link)
  85 	    print daypage
  86             if daypage.exists() and request.user.may.read(daypage.page_name):
  87                 daycontent = daypage.get_raw_body()
  88 
  89 		pattern = compile_obj
  90 		for match in pattern.finditer(daycontent):
  91 			if match:
  92 				if match.group(2) == None:
  93 					title = match.group(3)
  94 				else:
  95 					title = match.group(2)
  96 				result.append("<a href=\"%s/%s\">%s (%s)</a>" % (request.getBaseURL(),link,title,datestr))
  97 			else:
  98 				result.append("<a href=\"%s/%s\">%s (%s)</a>" % (request.getBaseURL(),link,"pas de titre",datestr))
  99                 
 100         if len(result) == 0:
 101                 result = ["Sorry, there are no entries within the last %d days." % n_max]
 102         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.