Nevow guard with other than 'root' resource

This is the first time I post to this list and my question follows: I've tried to use Nevow's guard with non-root resource (Else than NevowSite). The problem that raises upon is following: exceptions.AttributeError: 'SessionWrapper' object has no attribute 'renderHTTP' The code I use goes like this: <SNIP /> def __init__(self): realm=MyRealm() self.fooportal=portal.Portal(realm) myChecker=DatabaseChecker() self.fooportal.registerChecker(checkers.AllowAnonymousAccess(), credentials.IAnonymous) self.fooportal.registerChecker(myChecker) def getDynamicChild(self, name, request): if(name=='foo'): return guard.SessionWrapper(self.fooportal) <SNIP /> So are there good ways to get it working like this, or do i have to use some trick to do it, or (worst of all) is it even possible? Nevow rules, thank you. =) Janne Junnila

On Mar 7, 2004, at 1:28 PM, Janne Junnila wrote:
This is the first time I post to this list and my question follows:
I've tried to use Nevow's guard with non-root resource (Else than NevowSite). The problem that raises upon is following: exceptions.AttributeError: 'SessionWrapper' object has no attribute 'renderHTTP'
Janne mentioned on IRC that the actual goal is to be able to ask for username/password login for some children but not others. Thus, I suspect a solution where the SessionWrapper is on the root, but is configured somehow to not require login except for certain resources would work. I dunno how to do that but it looks probably possible from the API? James

James Y Knight wrote:
Janne mentioned on IRC that the actual goal is to be able to ask for username/password login for some children but not others. Thus, I suspect a solution where the SessionWrapper is on the root, but is configured somehow to not require login except for certain resources would work.
I dunno how to do that but it looks probably possible from the API?
It was certainly possible with woven.guard; you could pass in two separate resources, one for anon and one for loggedin. Of course those resources could also look at the session to see if the user is logged in, then redirect to the login screen if necessary. No idea how nevow.guard works. -- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com/

On Sun, 2004-03-07 at 15:04, Christopher Armstrong wrote:
James Y Knight wrote:
Janne mentioned on IRC that the actual goal is to be able to ask for username/password login for some children but not others. Thus, I suspect a solution where the SessionWrapper is on the root, but is configured somehow to not require login except for certain resources would work.
I dunno how to do that but it looks probably possible from the API?
It was certainly possible with woven.guard; you could pass in two separate resources, one for anon and one for loggedin. Of course those resources could also look at the session to see if the user is logged in, then redirect to the login screen if necessary. No idea how nevow.guard works.
Here's what I've been doing: --snip-- from twisted.cred import checkers from nevow import compy from nevow import inevow from nevow import rend class ICurrentUser(compy.Interface): pass class User: pass ANONYMOUS = User() class SimpleRealm: def requestAvatar(self, avatar_id, mind, *interfaces): if inevow.IResource in interfaces: if avatar_id is checkers.ANONYMOUS: user = ANONYMOUS else: user = createSomeUser(avatar_id) resc = createRootResource() resc.realm = self # The resource will remember this into its context, or # keep it around until it has one. resc.remember(user, ICurrentUser) return (inevow.IResource, resc, lambda:None) class MyResource(rend.Page): def getCurrentUser(self, ctx=None): if ctx is None: ctx = self.context if ctx is None: print "Hey, why can't I find a context?" return ANONYMOUS return ctx.locate(ICurrentUser) def isLoggedIn(self, ctx=None): return self.getCurrentUser(ctx) is not ANONYMOUS --snip-- ...then you can make render_* functions that display or hide parts of the web page based on the user. You can also make a LoggedInOnlyResource class that redirects to guard.LOGIN_AVATAR whenever it sees that the user isn't logged in. I'd be interested, though, in hearing what other ways people might have for accomplishing stuff like this. -- Alex Levy WWW: http://mesozoic.geecs.org "Never let your sense of morals prevent you from doing what is right." -- Salvor Hardin, Isaac Asimov's _Foundation_

Alex Levy wrote:
Here's what I've been doing:
Speaking of what you've been doing... is polynode ready to use yet? ;) BTW, it'd be nice if it didn't require anonymous users to have a session when I don't have a site customized per-user. I hacked plonk to allow that, it wasn't too hard. Maybe I'll add that to Polynode when I switch to it :) - Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com/

On Sun, 2004-03-07 at 15:57, Christopher Armstrong wrote:
Alex Levy wrote:
Here's what I've been doing:
Speaking of what you've been doing... is polynode ready to use yet? ;)
Nope. There's no rational way of storing page data on the system -- it's all in-memory right now. There's also a few other places where it still reeks of "code I wrote a year ago". Of course, _my_ site will be "customized" per-user, although that's mainly "either you're admin or you're nobody". How quickly I get all this sorted out will depend largely on my school schedule. :) -- Alex Levy WWW: http://mesozoic.geecs.org "Never let your sense of morals prevent you from doing what is right." -- Salvor Hardin, Isaac Asimov's _Foundation_

Alex Levy wrote:
On Sun, 2004-03-07 at 15:57, Christopher Armstrong wrote:
Speaking of what you've been doing... is polynode ready to use yet? ;)
Nope. There's no rational way of storing page data on the system -- it's all in-memory right now. There's also a few other places where it still reeks of "code I wrote a year ago".
Just store it on the FS, in nested directories, maybe using rfc822 files if you need metadata. That's what Plonk does, anyway.
Of course, _my_ site will be "customized" per-user, although that's mainly "either you're admin or you're nobody".
Yeah, same with mine. Nobodies don't need a session.
How quickly I get all this sorted out will depend largely on my school schedule. :)
-- Twisted | Christopher Armstrong: International Man of Twistery Radix | Release Manager, Twisted Project ---------+ http://radix.twistedmatrix.com/
participants (4)
-
Alex Levy
-
Christopher Armstrong
-
James Y Knight
-
Janne Junnila