Importing the code won't give you access to the req (request) instance.
The request object is not available from the macro body.
The authname is also available from the hdf instance.
Michael, you could try something this:
#----- Link.py ---
from trac.wiki.formatter import Formatter
import string
def execute(hdf, args, env):
(url, name) = map(string.strip, args.split(','))
return '<a href="%s?user=%s">%s</a>' % (url, hdf['trac.authname'], name)
#-----
Example:
[[Link(http://example.com, Example)]]
Of course, you probably need to deal with error cases (authname not
defined when user is not logged in, etc.)
Cheers,
Manu
On 8/17/06, Günter Dannoritzer <[EMAIL PROTECTED]> wrote:
Michael Bösendorfer wrote:
> Sorry guys that I'm that stupid but I'm such a newbie so I am not able to get
the macro run the way I want.
> Thanks Noah for your help and I'm sure everybody else would know how to get
the current user name with req.authname but I played a bit arround and always got
some error messages.
>
> I tried the following macro and copied it into the wiki-macros folder:
>
> # bla.py -- The world's simplest macro
> def execute(hdf, args, env):
> muh = req.authname
> return "Hello Michi: called with args: %s" % muh
>
> When I call [[bla]] on the wiki page I get the following error message:
>
> Error: Macro bla(None) failed
> global name 'req' is not defined
>
Just looking at the error message from the python code -- without
knowing about macro development for trac -- the instance req is not
defined. You need to import it from somewhere, probably the trac module.
Try adding:
from trac.core import *
at the top of your file.
I got that from some code snip I found by following the help link of a
trac webpage.
Cheers,
Guenter
_______________________________________________
Trac mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac
--
Manu
_______________________________________________
Trac mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac