In my application lots of nodes use the same controllers and views. I store
some settings in session[id] where id is the id of the node. Based on
whether a user has access to a function or not I build a menu and set
session[id].functionname=True. This is part of the code:
if a.nav.id==ABOUTNAVID:
session[id].site_menu.append([T(a.nav.name),False,'#'])
elif a.nav.id==WHOWEARENAVID:
aboutDropdown(id,a)
session[id].whoWeAre=True
elif a.nav.id==WHATWEDONAVID:
aboutDropdown(id,a)
session[id].whatWeDo=True
elif a.nav.id==HOWWEWORKNAVID:
aboutDropdown(id,a)
session[id].howWeWork=True
elif a.nav.id==WHEREWEARENAVID:
aboutDropdown(id,a)
session[id].whereWeAre=True
Now when a visitor request a function, I want the function to first check
session[request.args(0)].functionname.
def whoWeAre():
if has_access(request.function):
....
This is the has_access function:
def has_access(function):
if not len(request.args):
redirect(URL('addressbook','router'))
elif not session[request.args(0)]:
redirect(URL('addressbook','router',args=request.args(0)))
elif session[request.args(0)].function:
return True
else:
redirect(URL('addressbook','router',args=request.args(0)))
I wonder whether the has_access function has been written correctly, for
the result doesn't seem to be consistent.
Kind regards,
Annet
--