Contents
Include Calendar Page macro
The Problem
I am using the MonthCalendar macro to help me organise stuff. A diary! As well having the information on separate pages I wanted to view the contents on my frontpage as well.
A solution
This simple macro allows the contents of a calendar page created using the MonthCalendar macro to be displayed on the current page. The page chosen is relative to today's date.
Download & Release Notes
Download |
Release Version |
Moin Version |
Release Notes |
|
1.2 |
Updated for Moin 1.2. |
Installation
Install the MacroMarket/MonthCalendar and the MacroMarket/IncludePages macros. (See the MacroMarket.)
- Save this macro in your macros directory.
Usage
[[IncludeCalendarPage(pagepattern,level,0)]] - include today's page
[[IncludeCalendarPage(pagepattern,level,-1)]] - include yesterday's page
[[IncludeCalendarPage(pagepattern,level,1)]] - include tomorrow's page
[[IncludeCalendarPage(pagepattern,level,365)]] - include next year's page
- pagepattern: a page pattern to which a date will be appended
level: has the same meaning as in macro/IncludePages.py macro.
- pagepattern: a page pattern to which a date will be appended
Imagine that today's date is 2003-03-16. So the macro
[[IncludeCalendarPage(Calendar,2,0)]]
includes the contents of page Calendar/2003-03-16 down to level 2 headings.
The macro
[[IncludeCalendarPage(CharlieDiary,2,-1)]]
includes the contents of CharlieDiary/2003-03-15
The Code
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
11 The date code is modified from code in MonthCalendar.py by Thomas Waldmann
12 Thanks! :-)
13
14 The argument matching code is modified from IncludePages.py by Michael Reinsch
15 Cheers!
16
17 I spotted the name Richard Jones in Include.py on which this ultimately relies.
18 Thankyou.
19
20 Obviously credit should also go to Jürgen Hermann for making this all possible!
21
22 ----
23
24 This simple macro allows the contents of a calendar page created
25 using the MonthCalendar.py macro. To be displayed on the current page.
26
27 I use it to display a week of calendar entries on my front page.
28
29 To install:
30 * Install the MonthCalendar.py and the IncludePages.py macros
31 * Save this macro in your macros directory
32
33 To use:
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 $Id$
54 """
55
56 import calendar, cgi, time, re, string
57 from MoinMoin import config
58 from MoinMoin import wikiutil
59 import MoinMoin.macro.Include
60
61 _arg_dayoffset = r',\s*(?P<dayoffset>-?\d+)'
62 _arg_level = r',\s*(?P<level>\d+)'
63 _args_re_pattern = r'^(?P<pattern>[^,]+)(%s)(%s)$' % (_arg_level, _arg_dayoffset)
64 #_args_re_pattern = '^(?P<pattern>[^,]+)$'
65
66 def execute(macro, text, args_re=re.compile(_args_re_pattern)):
67 # parse and check arguments
68 args = args_re.match(text)
69 #return ('<p><string class="error">%s</string></p>') % (_args_re_pattern,)
70 if not args:
71 return ('<p><strong class="error">%s</strong></p>' %
72 ('Invalid include calendar page arguments "%s"!')) % (text,)
73
74 # get the arguments
75 pattern = args.group('pattern')
76 dayoffset = int(args.group('dayoffset'))
77
78 # There are 86400 seconds in a day.
79 datetofind = time.time() + dayoffset * 86400
80 (year,month,day,h,m,s,wd,yd,ds) = time.localtime(datetofind)
81
82 params = '%s/%d-%02d-%02d' % (pattern, year, month, day)
83
84 return MoinMoin.macro.Include.execute(macro,params)
Copyright
License
Support area
If you have questions, problems, bug reports, wishes, comments - put them here:
Hey, nice work!
My first thought was that it might be even greater if there are a start_offset and an end_offset and you do something like
for day in range(start_offset, end_offset): ...
end_offset of course should default to start_offset if omitted.
-- ThomasWaldmann 2003-03-16 22:05:26
This is a great idea, I'm working on a WikiLog at AdamShand and am trying to find a clean way to display the last week/months entries. -- AdamShand
Important this macro will not work if the non-standard macro/IncludePages.py macro is not in the proper location! If you only have the macro/IncludePages.py macro in the wiki instance's macros directory and not in the site-packages/MoinMoin/macro directory, you will encounter and inscrutible error traceback. So, make sure to {{{ cp IncludePages.py /usr/lib/python2.2/site-packages/MoinMoin/macro }}} or equivalent!
-- JohnWCocula
# There are 86400 seconds in a day. Not ALWAYS! Think daylight saving's... some days have fewer seconds, others more.
-- ChrisNilsson
Really nice macro. But to get it working for my installation (on verion 1.2.1), I had to alter the import statements to avoid exceptions popping up (also needed to do this in the IncludePages macro). This is what I changed it to:
import re import calendar, cgi, time, re, string #from MoinMoin import user from MoinMoin import config from MoinMoin import wikiutil #from MoinMoin.i18n import _ import MoinMoin.macro.IncludePages