Re: Using an extension in a detector
"John P. Rouillard" <[email protected]>
| Newsgroups | gmane.comp.bug-tracking.roundup.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Tom:
In message <SN6PR08MB478462BA54ADFE1FB9364270CAF90@SN6PR08MB4784.namprd08.prod.
outlook.com>,
Tom Ekberg writes:
>I wrote simple function in an extension that I normally use in files
>like html/page.html. I'd also like to call that function in a
>detector. The error I get is that the utils package isn't defined. I
>also tried 'import utils' but it didn't work either. Removing the
>package from the function call also didn't work.
I think the utils class/variable whatever... is defined only in the
templates.
I have two solutions. I am not sure if this will work, but try:
Create a lib directory in the tracker home.
Put the function:
>def user_in_group(db, group):
> return sorted([str(u.username) for u in db['user'].list() if group in str(u.organisation).split(',')])
in the file lib/library_func.py
Then in extension_file.py add:
from library_func import user_in_group
def init(instance):
instance.registerUtil('user_in_group', user_in_group)
For use in the detector add:
from library_func import user_in_group
and your call to:
> nosy_people = utils.user_in_group(db, 'nosy')
should work.
>What import do I need to be able to call an extension function from a
>detector?
I am not sure if TRACKER_HOME/extensions is in the load path like
TRACKER_HOME/lib. If it is you should be able to add:
from extension_file import user_in_group
to the detector and gain access to the user_in_group() function.
You could also experiment with:
from extensions.extension_file import user_in_group
Let us know what works.
Have a great day.
--
-- rouilj
John Rouillard
===========================================================================
My employers don't acknowledge my existence much less my opinions.