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