Attachment 'autosub.py'

Download

   1 """
   2    MoinMoin - autosub-Macro
   3 
   4    Copyright (c) 2003 by Daniela Nicklas <nicklas@informatik.uni-stuttgart.de>
   5    All rights reserved.
   6 
   7    Subscribe another user to a wiki page. Syntax:
   8    [[autosub(username1,User Name2,UserName3)]]
   9    Do not use spaces after the ,!
  10 
  11    for German i18n: Add to de.py:
  12 
  13    '''
  14 <b>This wiki is not enabled for mail processing.<br>
  15 Contact the owner of the wiki, who can either enable email,
  16 or do not use the autosub macro.</b>
  17 ''':
  18 '''
  19 <b>Dieses Wiki unterstützt keine E-Mail Verarbeitung.<br>
  20 Kontaktieren sie den Adminstrator dieses Wikis, der die E-Mail-Unterstützung
  21 aktivieren kann, oder verwenden sie das autosub-Macro nicht.
  22 ''',
  23 'Not a user:':
  24 'Kein Benutzer:'
  25 
  26    
  27 """
  28 
  29 from MoinMoin import config, user
  30 from MoinMoin.Page import Page
  31 from MoinMoin.i18n import _
  32 
  33 def subscribe_users(request, usernamelist, pagename):
  34     result = ''
  35     # icon in front of username, if subscribe succeeds:
  36     subicon='<img src="%s/img/moin-email.gif" width="14" height="10" border="0" alt="Subscribed">'%config.url_prefix
  37     # icon, if not:
  38     nosubicon='<img src="%s/img/moin-email-x.gif" width="14" height="10" border="0" alt="Subscribed">'%config.url_prefix
  39 
  40     # check config
  41     if not config.mail_smarthost:
  42         return _('''
  43 <b>This wiki is not enabled for mail processing.<br>
  44 Contact the owner of the wiki, who can either enable email,
  45 or do not use the autosub macro.</b>
  46 ''')
  47 
  48     realusers = []              # usernames that are really wiki-users
  49     success = 0                 # did the subscription succeed?
  50 
  51     # get user object - only with IDs!
  52     useridlist = user.getUserList();
  53     for userid in useridlist:
  54         success = 0
  55         userobj = user.User(request, userid)
  56 
  57         if userobj.name in usernamelist:   # found a user
  58             realusers.append(userobj.name)
  59             # check if user is already subscribed:
  60             if userobj.isSubscribedTo([pagename]):
  61                 success = 1
  62             # check whether the user has an email address
  63             elif not userobj.email:
  64                 success = 0
  65             # subscribe user
  66             elif userobj.subscribePage(pagename):
  67                 userobj.save()
  68                 success = 1
  69             # append user to result
  70             if success == 1:
  71                 result += subicon
  72             else:
  73                 result += nosubicon
  74             userpage = Page(userobj.name)
  75             result += userpage.link_to()
  76             result += " "
  77 
  78     # check for args that are not users        
  79     for un in usernamelist: 
  80         if un not in realusers:
  81             result += nosubicon
  82             result += _("Not a user:")
  83             # check if un is a page
  84             unpage = Page(un)
  85             if unpage.exists():
  86                 result += unpage.link_to()
  87             else:
  88                 result += un
  89     return result
  90 
  91 def execute(macro, args):
  92     # parse args
  93     usernamelist = []           # users to be subscribed
  94     usernamelist = args.split(",")
  95 
  96     pagename = macro.formatter.page.page_name # this page
  97     
  98     # result of the macro
  99     result = subscribe_users(macro.request, usernamelist, pagename)
 100 
 101 
 102     return 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.
  • [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.