Back to index

plone3  3.1.7
session_restore_value.py
Go to the documentation of this file.
00001 ## Script (Python) "session_save_form"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##parameters=fieldName,default
00008 ##title=Return field value previously stored on session by session_save_form
00009 ##
00010 
00011 from Products.CMFCore.utils import getToolByName
00012 
00013 # Avoid implicitly creating a session if one doesn't exists
00014 session = None
00015 sdm = getToolByName(context, 'session_data_manager', None)
00016 
00017 if sdm is not None:
00018     session = sdm.getSessionData(create=0)
00019 
00020 if session is None:
00021     return default
00022 
00023 id = context.getId()
00024 session_data = None
00025 
00026 if session.has_key(id):
00027     session_dic = session.get(id)
00028     if session_dic.has_key(fieldName):
00029         session_data = session_dic.get(fieldName)
00030 
00031 return session_data or default