Hello web.py list,

I have a decorator which I apply to the methods that I want to
restrict access to (aka 'admin only sections'). It basically checks to
see if the user is logged in, and if so, it will continue running the
request. If not, it will redirect to the main page:

class restrict(object):
        """
        Decorator for admin section of the website that need restriction.
        """
        def __init__(self, request):
                self.__request = request

        def __call__(self, *args, **kwargs):
                if session.auth != 1:
                        web.seeother(config.general.base_url)
                else:
                        return self.__request(*args, **kwargs)

When I apply this to, say, Index.GET, like this:

class Index:
        @restrict
        def POST(self):
                i = web.input()
                ....

I get this error message upon running Index.POST while logged in:

[Wed Jun 09 17:45:18 2010] [error] [client 127.0.0.1]   File "/var/www/
me/alecwh/index.py", line 64, in __call__, referer: http://localhost/me/alecwh/
[Wed Jun 09 17:45:18 2010] [error] [client 127.0.0.1]     return
self.__request(*args, **kwargs), referer: http://localhost/me/alecwh/
[Wed Jun 09 17:45:18 2010] [error] [client 127.0.0.1] TypeError:
POST() takes exactly 1 argument (0 given), referer: http://localhost/me/alecwh/

I don't know what's wrong, as my __call__ decorator method passes
along  *args, **kwargs. Can someone point me in the right direction
for solving this problem? To my knowledge, this should work perfectly.

Thanks for your help!

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to