Attachment 'MonthCalendarTopList_1.1.py'
Download 1 """
2 MoinMoin - MonthCalendar Top List MACRO
3
4 Original Author : Mark Stier
5 Mantained 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 raw_str = r"""
45 ^\s* # line start
46
47 (
48 '''\s*(.*)\s*'''
49 |
50 =\s+(.*)\s+=
51 )
52
53 \s*$ # end of line
54 """
55
56 compile_obj = re.compile(raw_str, re.MULTILINE|re.VERBOSE)
57
58 result = []
59 n_cnt = 0
60 for i in range(-1,n_max): # include next day because of different timezones
61 dte = now - timedelta(i)
62 datestr = "%4d-%02d-%02d" % (dte.year, dte.month, dte.day)
63 link = "%s/%s" % (thispage, datestr)
64 daypage = Page(request, link)
65 if daypage.exists() and request.user.may.read(daypage.page_name):
66 daycontent = daypage.get_raw_body()
67
68 m = compile_obj.search(daycontent)
69
70 if m:
71 if m.group(2) == None:
72 x = m.group(3)
73 else:
74 x = m.group(2)
75 result.append("<a href=\"%s/%s\">%s (%s)</a>" % (request.getBaseURL(),link,x,datestr))
76 else:
77 result.append("<a href=\"%s/%s\">%s (%s)</a>" % (request.getBaseURL(),link,"Untitled",datestr))
78 if n_cnt == n_max:
79 break
80
81 if len(result) == 0:
82 result = ["Sorry, there are no entries within the last %d days." % n_max]
83 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.