Quite possible that you have a form with something like this:
<input name="user.age:record" value="50" />
<input name="user.name:record" value="Dee" />
In python, if you do this::
def saveUser(self, user, REQUEST):
print user # will print {'age':'50', 'name':'Dee'}
REQUEST.SESSION.set('user_data', user) # will fail!
So you have to do this::
def saveUser(self, user, REQUEST):
user = dict(user)
print user # will print {'age':'50', 'name':'Dee'}
REQUEST.SESSION.set('user_data', user) # will work!
Dennis Schulz wrote:
According to the zope book it should be possible to store dicts in session.
When I try to assign a dictionary to a ordinary zope 2 session, with
lists there is no problem. why?:
requestlist = {}
for i in self.request.form:
key = i
value = self.request.form[i]
requestlist[i] = self.request.form[i]
sess = self.context.REQUEST.SESSION
sess['pr_reqlist'] = requestlist
I get the following error:
Traceback (innermost last):
* Module ZPublisher.Publish, line 196, in publish_module_standard
* Module Products.PlacelessTranslationService.PatchStringIO, line
34, in new_publish
* Module ZPublisher.Publish, line 146, in publish
* Module Zope2.App.startup, line 222, in zpublisher_exception_hook
* Module ZPublisher.Publish, line 121, in publish
* Module Zope2.App.startup, line 240, in commit
* Module transaction._manager, line 96, in commit
* Module transaction._transaction, line 380, in commit
* Module transaction._transaction, line 378, in commit
* Module transaction._transaction, line 433, in _commitResources
* Module ZODB.Connection, line 484, in commit
* Module ZODB.Connection, line 526, in _commit
* Module ZODB.Connection, line 553, in _store_objects
* Module ZODB.serialize, line 407, in serialize
* Module ZODB.serialize, line 416, in _dump
* Module copy_reg, line 69, in _reduce_ex
TypeError: can't pickle instancemethod objects (Also, the following
error occurred while attempting to render the standard error message,
please see the event log for full details: An operation previously
failed, with traceback: File
"C:\Python\Zope\Zope\lib\python\ZServer\PubCore\ZServerPublisher.py",
line 23, in __init__ response=response) File
"C:\Python\Zope\Zope\lib\python\ZPublisher\Publish.py", line
395, in publish_module environ, debug, request, response) File
"C:\Python\Zope\Zope\lib\python\ZPublisher\Publish.py", line
196, in publish_module_standard response = publish(request, module_name,
after_list, debug=debug) File
"C:\Python\Zope\Instance\Products\PlacelessTranslationService\PatchStringIO.py",
line 34, in new_publish x = Publish.old_publish(request, module_name,
after_list, debug) File
"C:\Python\Zope\Zope\lib\python\ZPublisher\Publish.py", line
121, in publish transactions_manager.commit() File
"C:\Python\Zope\Zope\lib\python\Zope2\App\startup.py", line
240, in commit transaction.commit() File
"C:\Python\Zope\Zope\lib\python\transaction\_manager.py", line
96, in commit return self.get().commit(sub, deprecation_wng=False) File
"C:\Python\Zope\Zope\lib\python\transaction\_transaction.py",
line 380, in commit self._saveCommitishError() # This raises! File
"C:\Python\Zope\Zope\lib\python\transaction\_transaction.py",
line 378, in commit self._commitResources() File
"C:\Python\Zope\Zope\lib\python\transaction\_transaction.py",
line 433, in _commitResources rm.commit(self) File
"C:\Python\Zope\Zope\lib\python\ZODB\Connection.py", line 484,
in commit self._commit(transaction) File
"C:\Python\Zope\Zope\lib\python\ZODB\Connection.py", line 526,
in _commit self._store_objects(ObjectWriter(obj), transaction) File
"C:\Python\Zope\Zope\lib\python\ZODB\Connection.py", line 553,
in _store_objects p = writer.serialize(obj) # This calls __getstate__ of
obj File "C:\Python\Zope\Zope\lib\python\ZODB\serialize.py",
line 407, in serialize return self._dump(meta, obj.__getstate__()) File
"C:\Python\Zope\Zope\lib\python\ZODB\serialize.py", line 416,
in _dump self._p.dump(state) File
"C:\Python\Zope\Python\lib\copy_reg.py", line 69, in
_reduce_ex raise TypeError, "can't pickle %s objects" %
base.__name__ TypeError: can't pickle instancemethod objects )
_______________________________________________
Zope maillist - [email protected]
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
_______________________________________________
Zope maillist - [email protected]
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )