开发者

Getting logged on user name at any Trac wiki page (Trac 0.11)

开发者 https://www.devze.com 2022-12-26 04:19 出处:网络
When I create a report I can filter the results based on the logged on user name using the $USER magic variable. Is there any equivalent way to get the logged on user name at any Trac开发者_如何学运维

When I create a report I can filter the results based on the logged on user name using the $USER magic variable. Is there any equivalent way to get the logged on user name at any Trac开发者_如何学运维 wiki page?

E.g.: The logged on user is [[User]].


Looks like you need a plugin to do it. Nothing complex; just throw this:

from trac.wiki.macros import WikiMacroBase

class UserMacro(WikiMacroBase):
    def expand_macro(self, formatter, name, args):
        return formatter.req.authname;

Into a file like <trac_env>/plugins/username.py and add [[User]] to a wiki page. For non-logged in users, it'll show anonymous.

0

精彩评论

暂无评论...
验证码 换一张
取 消