Back to index

plone3  3.1.7
session_save_form.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=
00008 ##title=Introspect context schema and saves on session REQUESTs values
00009 ##
00010 REQUEST = context.REQUEST
00011 
00012 # hey, don't forget to increment object number for sessions
00013 form_data = {'HTTP_REFERER':REQUEST.get('last_referer', None)}
00014 to_store = [f for f in context.Schema().values() if f.type != 'computed']
00015 
00016 for field in to_store:
00017     fieldname = field.getName()
00018     if field.widget.getName() == 'KeywordWidget':
00019         fieldname = '%s_keywords' % field.getName()
00020         data = []
00021         if REQUEST.has_key(fieldname):
00022             data += REQUEST.get(fieldname)
00023         fieldname = '%s_existing_keywords' % field.getName()
00024         if REQUEST.has_key(fieldname):
00025             data += REQUEST.get(fieldname)
00026         form_data[field.getName()] = data
00027     else:
00028         if REQUEST.has_key(fieldname):
00029             form_data[fieldname] = REQUEST.get(fieldname)
00030 
00031 # XXX Implicitly creating a session for user.
00032 REQUEST.SESSION.set(context.getId(), form_data)