Attachment 'User.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - User macro
   4     
   5     Syntax:
   6         [[User]]
   7         Displays the name of the current user
   8 
   9         [[User(homepage)]]
  10         Displays a link to the user's homepage
  11 
  12         [[User(homepage=Your link text)]]
  13         Displays a renamed link to the user's homepage
  14 
  15         [[User(preferences)]]
  16         Display the user's preferences 
  17         
  18     @copyright: 2007 by Oliver Siemoneit
  19     @license: GNU GPL, see COPYING for details.
  20 """
  21 
  22 from MoinMoin import user, wikiutil
  23 
  24 def _getArgs(given_arguments, allowed_arguments):
  25     if not given_arguments:
  26         return {}
  27 
  28     args = {}
  29     for s in given_arguments.split(','):
  30         if s and s.find('=') > 0:
  31             key, value = s.split('=', 1)
  32             key = key.strip()
  33             if key and value:
  34                 if key in allowed_arguments:
  35                     args[key] = wikiutil.escape(value.strip())
  36             else:
  37                 if key in allowed_arguments:
  38                     args[key] = None    
  39         else:
  40             key = s.strip()
  41             if key in allowed_arguments:
  42                 args[key] = None
  43             
  44     return args
  45 
  46 def _displayUserName(request):
  47     _ = request.getText
  48 
  49     if request.user.isCurrentUser():
  50         name = request.user.name
  51         aliasname = request.user.aliasname
  52         if not aliasname:
  53             aliasname = name
  54         if aliasname == "":
  55             return _('<unknown>')
  56         return aliasname
  57 
  58     return _('<unknown>')
  59 
  60 def _displayHomepageLink(request, linktext):
  61     _ = request.getText
  62     
  63     if request.user.valid and request.user.name:
  64         interwiki = wikiutil.getInterwikiHomePage(request)
  65         name = request.user.name
  66         aliasname = request.user.aliasname
  67         if not aliasname:
  68             aliasname = name
  69         title = "%s @ %s" % (aliasname, interwiki[0])
  70         # link to (interwiki) user homepage
  71         if linktext is None:
  72             homelink = "%s%s%s" % (request.formatter.interwikilink(1, title=title, id="userhome", generated=True, *interwiki),
  73                         request.formatter.text(name),
  74                         request.formatter.interwikilink(0, title=title, id="userhome", *interwiki))
  75             return homelink
  76         else:
  77             homelink = "%s%s%s" % (request.formatter.interwikilink(1, title=title, id="userhome", generated=True, *interwiki),
  78                         request.formatter.text(linktext),
  79                         request.formatter.interwikilink(0, title=title, id="userhome", *interwiki))
  80             return homelink
  81     else:
  82         if linktext is None:
  83             return _('<unknown>')
  84         else:
  85             return linktext 
  86 
  87 def _displayUserPreferences(request):
  88     from MoinMoin import userform
  89 
  90     return request.formatter.rawHTML(userform.getUserForm(request, create_only=False))
  91 
  92 
  93 def execute(macro, given_args):
  94     request = macro.request
  95     
  96     allowed_args = ['homepage', 'preferences']
  97     args = _getArgs(given_args, allowed_args)
  98 
  99     if not args:
 100         return _displayUserName(request)
 101 
 102     elif args.has_key('homepage'):
 103         return _displayHomepageLink(request, args['homepage'])
 104 
 105     elif args.has_key('preferences'):
 106         return _displayUserPreferences(request)
 107 
 108     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] (2006-12-10 21:02:59, 1.9 KB) [[attachment:CreateUserHomepage.py]]
  • [get | view] (2006-12-10 16:08:04, 0.6 KB) [[attachment:CurrentUser.py]]
  • [get | view] (2006-12-10 16:09:19, 1.1 KB) [[attachment:MissingHomePage.txt]]
  • [get | view] (2007-01-18 20:32:31, 1.5 KB) [[attachment:ToggleWelcome.py]]
  • [get | view] (2007-01-08 16:09:44, 3.3 KB) [[attachment:User.py]]
  • [get | view] (2007-01-18 20:32:07, 2.1 KB) [[attachment:WelcomeUser.txt]]
  • [get | view] (2006-12-10 16:07:27, 0.8 KB) [[attachment:action__init__.diff]]
  • [get | view] (2006-12-10 16:07:10, 0.5 KB) [[attachment:multiconfig.diff]]
  • [get | view] (2007-01-18 20:31:25, 1.3 KB) [[attachment:request_init_.diff]]
  • [get | view] (2007-01-20 22:14:41, 1.2 KB) [[attachment:togglewelcome.py]]
  • [get | view] (2007-01-18 20:31:07, 0.7 KB) [[attachment:user.diff]]
 All files | Selected Files: delete move to page copy to page

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