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