The login and logout controllers remain in controllers.py while the
otherControllers.py uses identity.require quite happily. So what's the
problem? I have another package called forms in which I declare my form
schema's. This works fine until I try to use identity in there:
import turbogears
from turbogears import identity, widgets
from myProject import model
then for a SingleSelectField I want to output a list of groups the
current user is in
options=[(group.id, group.displayName) for group in
identity.current.groups]
sadly this results in
turbogears.identity.exceptions.IdentityManagementNotEnabledException:
An attempt was made to use a facility of the TurboGears Identity
Management framework but identity management hasn't been enabled in the
config file [via identity.on].
It is and I have been using it successfully what is different about
using it in this package? is it a name space issue? I don't know. I
hope I'm not doing something stupid but if this is something other may
run into as well it's good to talk about it.
What does your config file look like? I ask because I want to be sure
that identity.on = True for the path in question. (Remember that
CherryPy allows config values to vary by path...)
Kevin
I have literally just turned on the commented items in config.py
visit.on=True
(...)
identity.on=True
(...)
identity.failure_url="/login"
And as I say it does work, correctly protects the methods even of the
mounted controller. It is only when I try to access it from
"project/forms/my_forms.py" that it raises an exception. If you want
the entire config I can send it but the only other thing that I did was
turn on tg.mochikit_all (which didn't seem to do anything incidentally)
thank you!
On 3/21/06, Richard (koorb) <richard.s...@googlemail.com> wrote:
> then for a SingleSelectField I want to output a list of groups the
> current user is in
>
> options=[(group.id, group.displayName) for group in
> identity.current.groups]
And *there's* the problem. identity.current is only going to work in
the context of a request, not when you're initially setting up your
widgets. (The thing to remember about widgets is that they generally
outlive requests.)
I believe options can be a callable. Try something like:
options = lambda: [(group.id, group.displayName) for group in
identity.current.groups]
Kevin
options=[(group.id, group.displayName) for group in
identity.current.groups]
Hi Jeff,
As soon as commit access works again I will add to turbogears.util a
request_available function that you could use for this.
Ciao
Michele
Kevin Dangoor wrote:
> options = lambda: [(group.id, group.displayName) for group in
> identity.current.groups]
I tried that, only got the same error. Also tried specially defining a
function:
def current_group_list():
return [(group.id, group.displayName) for group in
identity.current.user.groups]
(...)
group = widgets.SingleSelectField(name="group", label="Assign to
group",
options=current_group_list,
help_text=_("..."))
just results in IdentityManagementNotEnabledException
It's strange if you're really passing current_group_list and not
current_group_list() this function will be called only at display time
(when the request is available), when are you receiving this exception?
when you click that page or before?
Ciao
Michele
actually I cant even start the server! It raises the exception when I
do ./start-project.py