In my node driven application I have amongst others the following stored in 
session:

session.id
session.site_menu
session.hero
session.theme
session.sitenav etc.

I am looking for a way to distinguish between session variables belonging 
to a node, something like:

session.nodeID.id
session.nodeID.site
session.nodeID.hero
session.nodeID.theme
session.nodeID.sitenav etc

This would provide me with the possibility to check whether 
session[request.args(0)].site exists if so render the view if not run the 
code to set session.nodeID.site.

I coded my router function to implement this:

def router():
    if not len(request.args):
        session.flash='Aan de URL ontbreken argumenten. Formuleer een 
zoekopdracht. ' + response.flash_form
        redirect(URL('addressbook','index'))
    else:
        session[request.args(0)].id=request.args(0)
        generateContact(session[request.args(0)].id)
        
account=db(db.NodeAccount.nodeID==session[request.args(0)].id).select(db.NodeAccount.ALL).first()
        if account:
            if account.statusID!=1: # in that case the account is blocked 
or under maintenance
                redirect(URL('card',args=session[request.args(0)].id))
            elif account.accountID==BASICACCOUNTID:
                redirect(URL('vcard',args=session[request.args(0)].id))
            elif account.accountID==ADVANCEDACCOUNTID:
                
redirect(URL('site','index',args=session[request.args(0)].id))
            elif account.accountID==BASICCONNECTORACCOUNTID:
                redirect(URL('vconnector',args=session[request.args(0)].id))
            elif account.accountID==ADVANCEDCONNECTORACCOUNTID:
                
redirect(URL('connector','index',args=session[request.args(0)].id))
        else:
            redirect(URL('card',args=session[request.args(0)].id))
        return None

Running this code result in the following error:

Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 
205, in restricted
    exec ccode in environment
  File 
"/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/addressbook.py"
 
<http://127.0.0.1:8000/admin/default/edit/bootstrap/controllers/addressbook.py>,
 line 288, in <module>
  File "/Library/Python/2.5/site-packages/web2py/gluon/globals.py", line 173, 
in <lambda>
    self._caller = lambda f: f()
  File 
"/Library/Python/2.5/site-packages/web2py/applications/bootstrap/controllers/addressbook.py"
 
<http://127.0.0.1:8000/admin/default/edit/bootstrap/controllers/addressbook.py>,
 line 65, in router
    session[request.args(0)].id=request.args(0)
AttributeError: 'NoneType' object has no attribute 'id'


Is there a way to get this to work?

Kind regards,

Annet



-- 



Reply via email to