Attachment 'UserIncludePage.py'

Download

   1 """
   2     MoinMoin - UserIncludePage macro
   3 
   4     version 1.0
   5     JonathanDietrich
   6 
   7     Allows for dynamic additions based on UserName
   8     [[UserIncludePage(page, "heading", level, force)]]
   9     
  10 	page will be added to the end of the the current user's name
  11         heading is the standard include heading
  12         level is the standard include level
  13         force if set to force or 1 will force the page to show, even if it doesn't currently exist 
  14 
  15     [[UserIncludePage(/Notes,'Personal Notes',2, 1)]]
  16    
  17        this will include UserName/Notes with the heading of Personal Notes down to level 2
  18        with the force set to 1, this page will be included even if it doesn't exist
  19     
  20 
  21     $Id$ 
  22 """
  23 
  24 import re
  25 from MoinMoin import config
  26 from MoinMoin import wikiutil
  27 import MoinMoin.macro.IncludePages
  28 from MoinMoin.Page import Page
  29 
  30 _arg_level = r',\s*(?P<level>\d+)'
  31 _arg_force  = r',\s*(?P<force>.+?)'
  32 _arg_heading = r'(?P<heading>,)\s*(|(?P<hquote>[\'"])(?P<htext>.+?)(?P=hquote))' 
  33 _args_re_pattern = r'^(?P<pattern>[^,]+)?(%s)?(%s)?(%s)?$' % (_arg_heading, _arg_level, _arg_force )
  34 
  35 
  36 def execute(macro, text, args_re=re.compile(_args_re_pattern)):
  37 
  38     # parse and check arguments
  39     args = args_re.match(text)
  40     if not args:
  41         return ('<p><strong class="error">%s</strong></p>' %
  42             _('Invalid include calendar page arguments "%s"!')) % (text,)
  43 
  44     # get the arguments
  45     username = macro.request.user.name
  46     if args.group('pattern') is None:
  47         pattern = username
  48     else:
  49     	pattern = username + args.group('pattern')
  50     if args.group('level') is None:
  51         level = 1
  52     else: 
  53     	level = int(args.group('level'))
  54     if  args.group('htext') is None:
  55 	 heading = ""
  56     else:
  57          heading =   args.group('htext')    
  58     params = '%s, "%s", %d' % (pattern, heading, level)
  59     targetpage = Page(pattern)
  60     if args.group('force') is None:
  61 	force = 0
  62     elif args.group('force') == '1' or args.group('force') == 'force'  :
  63         force = 1
  64     else:
  65 	force = 0 
  66     if  (targetpage.exists() or force )  and macro.request.user.valid :  
  67      return MoinMoin.macro.Include.execute(macro, params) 
  68     else:
  69      return ''

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] (2004-03-26 05:03:51, 2.1 KB) [[attachment:UserIncludePage.py]]
 All files | Selected Files: delete move to page copy to page

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