[Zope] Re: losing random session data

Norbert Marrale norbert at vsmpro.com
Mon Mar 19 15:08:48 EDT 2007


Tres Seaver wrote:
> 
> Note as well that using "mutable" Python primitives (dicts, lists) is
> tricky, as they don't notify *their* container (the persistent
> SessionDataObject) when they are mutatated.  If you are using them,
> rather than some persistent variant, then you need to rebind them into
> the container.  E.g.:
> 
>   mapping = SESSION.get('mapping')
>   if mapping is None:
>       mapping = {}
>   mapping['foo'] = REQUEST.form('foo')
>   SESSION['mapping'] = mapping  # triggers persistence
> 

Thanks Tres & Maciej!

This does the trick:

     order = []
     new_order={}
     prev_order=req.SESSION.get('order')

     if prev_order != None:
      for orders in prev_order:
        for item in orders.keys():
         new_order[item]=orders[item]
        order.append(new_order)
        new_order ={}

     for val in req.form.keys():
       new_order[val]=req.form[val]
     order.append(new_order)

     req.SESSION['order'] = order

With the expected output:

order [{'foo': '1', 'bar': 'a'}, {'foo': '2', 'bar': 'b'},
{'foo': '7', 'bar': 'e'}, {'foo': '6', 'bar': 'z'}, {'foo': '1', 'bar': 
'a'}]



More information about the Zope mailing list