[web2py] Re: session[id]=Storage(id=id) between controllers

2012-11-01 Thread Annet
Hi,

Thanks for providing me with a solution. 
 

 request.args(0,default=0, cast=int, otherwise=URL(...))


 

 PS: if it's recurrent I wonder why you aren't normalizing it already as 
 with
 try:
   arg0 = int(request.args(0))
 except:
   redirect()


Because there are exceptions, at the moment your solution solves the 
problem, in a next iteration I'll probably solve it differently.


Kind regards,

Annet. 

-- 





[web2py] Re: session[id]=Storage(id=id) between controllers

2012-11-01 Thread Niphlod



 Because there are exceptions, at the moment your solution solves the 
 problem, in a next iteration I'll probably solve it differently.

 
What exceptions ?

request.args(0, default=0, cast=int, otherwise=something)

does exactly the same thing I described

try:
  int(request.args(0))
except:
   something
 
It's just a nicer shortcut to use

-- 





[web2py] Re: session[id]=Storage(id=id) between controllers

2012-10-31 Thread Massimo Di Pierro
Somewhere else in your logic you are changing this.

On Wednesday, 31 October 2012 05:53:46 UTC-5, Annet wrote:

 In my node based app I create the following object 
 session[id]=Storage(id=id) in which I store some data and menus the first 
 time the index page of a site is loaded. After that session[id].node, 
 session[id].navbar etc. evaluate to True and the data and menus are not set 
 again. When the user edits these data and menus, the data and menus in 
 session[id] should be reset.

 I expected this would solve the problem:

 @auth.requires_login()
 def onaccept_functions(form):
 id=get_ID(auth,session)
 if session[id]:
 del session[id]

 However, in case id=5 in the cms.py controller session[5] is None, whereas 
 in site.py session[5]  contains data and menus:

 Storage {'node': Row {'computedName': 'ClubWest', 'computedSubClass': 1, 
 'id': 5}, 'navbarfixedtop': False, 'hero': Row {'url': 'nodeID5.jpg', 
 'isImage': True, 'isLogo': False, 'nodeID': 5},, 'homepage': True, 
 'accountID': 2} 

 Why is that?

 Kind regards,

 Annet




-- 





[web2py] Re: session[id]=Storage(id=id) between controllers

2012-10-31 Thread Annet
Hi Massimo,

Thanks for your reply.

Somewhere else in your logic you are changing this.


I've gone through my applications logic, session[id] is being created in a 
router function:

def router():
if not len(request.args):
redirect(URL('addressbook','index'))
else:
id=request.args(0)

account=db(db.nodeAccount.nodeID==id).select(db.nodeAccount.ALL).first()
if account:
if account.accountID==BASICACCOUNTID:
redirect(URL('vcard',args=id))
elif account.accountID==ADVANCEDACCOUNTID:
if not session[id]:
session[id]=Storage(id=id)
session[id].accountID=ADVANCEDACCOUNTID
session[id].pluralID=account.pluralID
redirect(URL('site','index',args=id))
elif account.accountID==BASICHUBACCOUNTID:
redirect(URL('vhub',args=id))
elif account.accountID==ADVANCEDHUBACCOUNTID:
if not session[id]:
session[id]=Storage(id=id)
session[id].accountID=ADVANCEDHUBACCOUNTID
session[id].pluralID=account.pluralID
redirect(URL('hub','index',args=id))
else:
redirect(URL('card',args=id))
return None
 
It''s attributes are given a value in site.py's index function:

def index():
if not session[request.args(0)]:
redirect(URL('addressbook','router',args=request.args(0)))
elif not session[request.args(0)].accountID==ADVANCEDACCOUNTID:
redirect(URL('addressbook','router',args=request.args(0)))
else:
if not session[id].node:
session[id].node=retrieve_node(id,db)
if not session[id].sitenav:
session[id].site_menu=[]

sitenav=db((db.nodeNav.nodeID==id)(db.nodeNav.frontend==True)(db.nodeNav.navID==db.nav.id)\

(db.nav.navbarID==SITENAVBARID)).select(db.nav.ALL,db.nodeNav.ALL,orderby=db.nav.insequence)
if sitenav:

session[id].herotext=session[id].hero=session[id].theme=session[id].customtheme=None

session[id].homepage=session[id].promounit=session[id].relatednames=session[id].socialmedia=\

session[id].googlemaps=session[id].container=session[id].navbarfixedtop=False
session[id].sitenav=True
for s in sitenav:
if s.nav.id==HOMENAVID:

session[id].site_menu.append([T(s.nav.name),False,URL(s.nav.frontendcontroller,s.nav.function,args=id)])
elif s.nav.id==HEROTEXTNAVID:

session[id].herotext=db(db.heroUnitText.nodeID==id).select(db.heroUnitText.nodeID,db.heroUnitText.h1,\

db.heroUnitText.h1,db.heroUnitText.p,db.heroUnitText.pColor,db.heroUnitText.btn,\

db.heroUnitText.btnUrl,db.heroUnitText.btnColor).first()
elif s.nav.id==HEROFILENAVID:

session[id].hero=db(db.heroUnit.nodeID==id).select(db.heroUnit.nodeID,db.heroUnit.url,db.heroUnit.isLogo,\
db.heroUnit.isImage).first()
elif s.nav.id==HOMEPAGENAVID:
session[id].homepage=True
elif s.nav.id==PROMOUNITNAVID:
session[id].promounit=True
elif s.nav.id==RELATEDNAMESNAVID:
session[id].relatednames=True
elif s.nav.id==SOCIALMEDIANAVID:
session[id].socialmedia=True
elif s.nav.id==GOOGLEMAPSNAVID:
session[id].googlemaps=True
elif s.nav.id==THEMENAVID:

theme=db((db.nodeTheme.nodeID==id)(db.nodeTheme.themeID==db.theme.id)).select(db.theme.ALL).first()
if theme:
session[id].container=theme.container
session[id].navbarfixedtop=theme.navbarFixedTop
session[id].theme=theme
elif s.nav.id==CUSTOMTHEMENAVID:

customtheme=db(db.customTheme.nodeID==id).select(db.customTheme.ALL).first()
if customtheme:
session[id].container=customtheme.container

session[id].navbarfixedtop=customtheme.navbarFixedTop
session[id].customtheme=customtheme
...
if session[id].homepage:

homepage=db((db.aboutText.nodeID==id)(db.aboutText.aboutID==HOMEABOUTID)).select(db.aboutText.ALL).first()
if not homepage:
response.flash='Geen home page tekst beschikbaar'
session.alert='alert-info'
if session[id].promounit:
promorows=retrieve_promoUnits(id,db,HOMEPAGEPROMOID)
if session[id].node:

[web2py] Re: session[id]=Storage(id=id) between controllers

2012-10-31 Thread Annet
Hi Massimo,

Thanks for your reply, the cause of the problem is that in the router 
function session[id] is based on request.args(0), whereas in 
id=get_ID(auth,session) if session[id]: it is based on nodeID which is of 
type int. Since my whole app is node driven, the issue of request.args(0) 
being of type string and nodeID being of type int and having to compare 
them is a recurring one. What is the best way to solve it?


Kind regards,

Annet

-- 





[web2py] Re: session[id]=Storage(id=id) between controllers

2012-10-31 Thread Niphlod
request.args(0,default=0, cast=int, otherwise=URL(...))

PS: if it's recurrent I wonder why you aren't normalizing it already as with
try:
  arg0 = int(request.args(0))
except:
  redirect()

:P

On Wednesday, October 31, 2012 6:26:44 PM UTC+1, Annet wrote:

 Hi Massimo,

 Thanks for your reply, the cause of the problem is that in the router 
 function session[id] is based on request.args(0), whereas in 
 id=get_ID(auth,session) if session[id]: it is based on nodeID which is of 
 type int. Since my whole app is node driven, the issue of request.args(0) 
 being of type string and nodeID being of type int and having to compare 
 them is a recurring one. What is the best way to solve it?


 Kind regards,

 Annet


--