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      [[IncludeCalendarPage(pagepattern,level,0)]] - include todays page
  35      [[IncludeCalendarPage(pagepattern,level,-1)]] - include yesterdays page
  36      [[IncludeCalendarPage(pagepattern,level,1)]] - include tomorrows page
  37      [[IncludeCalendarPage(pagepattern,level,365)]] - include next years page
  38 
  39      * pagepattern: (A page pattern to which a date will be appended
  40      * level: has the same meaning as in IncludePages.py macro.
  41 
  42     Todays date is 2003-03-16. So the macro
  43 
  44      [[IncludeCalendarPage(Calendar,2,0)]]
  45 
  46     includes the contents of page Calendar/2003-03-16 down to level 2 headings.
  47 
  48      [[IncludeCalendarPage(CharlieDiary,2,-1)]] - include CharlieDiary/2003-03-15
  49 
  50     You get the idea!
  51 
  52     $Id$ 
  53 """
  54 
  55 import re
  56 import calendar, cgi, time, re, string
  57 from MoinMoin import user
  58 from MoinMoin import config
  59 from MoinMoin import wikiutil
  60 from MoinMoin.i18n import _
  61 import MoinMoin.macro.IncludePages
  62 
  63 _arg_dayoffset = r',\s*(?P<dayoffset>-?\d+)'
  64 _arg_level = r',\s*(?P<level>\d+)'
  65 _args_re_pattern = r'^(?P<pattern>[^,]+)(%s)(%s)$' % (_arg_level, _arg_dayoffset)
  66 
  67 def execute(macro, text, args_re=re.compile(_args_re_pattern)):
  68 
  69     # parse and check arguments
  70     args = args_re.match(text)
  71     if not args:
  72         return ('<p><strong class="error">%s</strong></p>' %
  73             _('Invalid include calendar page arguments "%s"!')) % (text,)
  74 
  75     # get the arguments
  76     pattern = args.group('pattern')
  77     level = int(args.group('level'))
  78     dayoffset = int(args.group('dayoffset'))
  79 
  80     # There are 86400 seconds in a day.
  81     datetofind = time.time() + dayoffset * 86400
  82     (year,month,day,h,m,s,wd,yd,ds) = time.localtime(datetofind)
  83 
  84     params = '%s/%d-%02d-%02d, %d' % (pattern, year, month, day, level)
  85     
  86     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.
  • [get | view] (2003-12-07 18:15:54, 6.8 KB) [[attachment:AttachmentLink.py]]
  • [get | view] (2003-12-07 18:15:54, 16.7 KB) [[attachment:Blog.py]]
  • [get | view] (2003-12-07 18:15:54, 2.8 KB) [[attachment:IncludeCalendarPage.py]]
  • [get | view] (2003-12-07 18:15:54, 3.0 KB) [[attachment:IncludePages.py]]
  • [get | view] (2005-03-14 22:41:00, 2.7 KB) [[attachment:LinkedFrom-1.3.py]]
  • [get | view] (2003-12-07 18:15:54, 2.9 KB) [[attachment:LinkedFrom.py]]
  • [get | view] (2003-12-07 18:15:54, 3.2 KB) [[attachment:PageLinks.py]]
  • [get | view] (2003-12-07 18:15:54, 3.1 KB) [[attachment:autosub.py]]
  • [get | view] (2003-12-07 18:15:54, 2.3 KB) [[attachment:cc-20030808.tgz]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.