Attachment 'IncludeCalendarPage.py'
Download 1 """
2 MoinMoin - IncludeCalendarPage macro
3
4 version 1.0
5
6 (c) 2003 Charles Crichton, Oxford University Computing Laboratory
7 Charles.Crichton (in the domain) comlab.ox.ac.uk
8 Licensed under GNU GPL - see COPYING for details.
9
10 The date code is modified from code in MonthCalendar.py by Thomas Waldmann
11 Thanks! :-)
12
13 The argument matching code is modified from IncludePages.py by Michael Reinsch
14 Cheers!
15
16 I spotted the name Richard Jones in Include.py on which this ultimately relies.
17 Thankyou.
18
19 Obviously credit should also go to Jürgen Hermann for making this all possible!
20
21 ----
22
23 This simple macro allows the contents of a calendar page created
24 using the MonthCalendar.py macro. To be displayed on the current page.
25
26 I use it to display a week of calendar entries on my front page.
27
28 To install:
29 * Install the MonthCalendar.py and the IncludePages.py macros
30 * Save this macro in your macros directory
31
32 To use:
33
34
35 [[IncludeCalendarPage(pagepattern,level,0)]] - include todays page
36 [[IncludeCalendarPage(pagepattern,level,-1)]] - include yesterdays page
37 [[IncludeCalendarPage(pagepattern,level,1)]] - include tomorrows page
38 [[IncludeCalendarPage(pagepattern,level,365)]] - include next years page
39
40 * pagepattern: (A page pattern to which a date will be appended
41 * level: has the same meaning as in IncludePages.py macro.
42
43 Todays date is 2003-03-16. So the macro
44
45 [[IncludeCalendarPage(Calendar,2,0)]]
46
47 includes the contents of page Calendar/2003-03-16 down to level 2 headings.
48
49 [[IncludeCalendarPage(CharlieDiary,2,-1)]] - include CharlieDiary/2003-03-15
50
51 You get the idea!
52
53 Now supports anniversary calendars!
54
55 Now includes a new optional parameter, anniversary.
56 if the 4th paramater is set to 1, the year is left off of the
57 pattern of pages to get... so
58
59 [[IncludeCalendarPage(Calendar,2,0,1)]]
60
61 includes the contents of page Calendar/03-16 down to level 2 headings.
62
63 if the 4th parameter is set to 2, the year becomes optional
64 meaning if you had an anniversary calendar called Yearly and
65 a normal day calendar called myCalendar you could roll them both up with
66 the following.
67
68 [[IncludeCalendarPage(^(myCalendar|Yearly),2,0,2)]]
69
70 includes the contents of page myCalendar/2003-03-16 AND Yearly/03-16 down to level 2 headings.
71
72 $Id$
73 """
74
75 import re
76 import calendar, cgi, time, re, string
77 #from MoinMoin import user
78 from MoinMoin import config
79 from MoinMoin import wikiutil
80 #from MoinMoin.i18n import _
81 import MoinMoin.macro.IncludePages
82
83 _arg_dayoffset = r',\s*(?P<dayoffset>-?\d+)'
84 _arg_level = r',\s*(?P<level>\d+)'
85 _arg_anniversary = r'(,\s*(?P<anniversary>\d+))?'
86 _args_re_pattern = r'^(?P<pattern>[^,]+)(%s)(%s)(%s)$' % (_arg_level, _arg_dayoffset, _arg_anniversary)
87
88 def execute(macro, text, args_re=re.compile(_args_re_pattern)):
89
90 # parse and check arguments
91 args = args_re.match(text)
92 if not args:
93 return ('<p><strong class="error">%s</strong></p>' %
94 _('Invalid include calendar page arguments "%s"!')) % (text,)
95
96 # get the arguments
97 pattern = args.group('pattern')
98 level = int(args.group('level'))
99 dayoffset = int(args.group('dayoffset'))
100
101 # There are 86400 seconds in a day.
102 datetofind = time.time() + dayoffset * 86400
103 (year,month,day,h,m,s,wd,yd,ds) = time.localtime(datetofind)
104
105
106 if args.group('anniversary') is None:
107 params = '%s/%d-%02d-%02d, %d' % (pattern, year, month, day, level)
108 else:
109 if int(args.group('anniversary')) == 1:
110 params = '%s/%02d-%02d, %d' % (pattern, month, day, level)
111 elif int(args.group('anniversary')) == 2:
112 params = '%s/(%d-)?%02d-%02d, %d' % (pattern, year, month, day, level)
113 else:
114 params = '%s/%d-%02d-%02d, %d' % (pattern, year, month, day, level)
115 return MoinMoin.macro.IncludePages.execute(macro, params)
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.