Session can store only basic Python data types like strings, integers, floats. It can not store custom class data (SQLFORM). You can serialize SQL FORM object with pickle and store a resulting string in the session, and then use pickle.loads(string) do deserialize the object. No sure it is more economical than re-creating form object directly.
On Aug 26, 11:36 am, Alastair Medford <alastairmedf...@gmail.com> wrote: > After my previous question of trying to submit an SQLFORM brought in > by ajax, I've done a bit of poking around and I think I've figured out > the next step. What I'm trying to do is each time I generate an > SQLForm, I would like to be able to store it into a list in the users > session, or any sort of somewhat temporary storage really, so that if > the user returns to the same page (controller), any forms that have > not been submitted can be taken from the list and placed back into the > page. However, when I try to append anything to a session variable I > get a strange error. The code and error are below. > > #code in controller > if not session.userForms: > session.userForms = [] > session.userForms.append(form) > #where form is an SQLFORM > > Error traceback > > Traceback (most recent call last): > File "C:\Development\web2py\gluon\main.py", line 359, in wsgibase > session._try_store_on_disk(request, response) > File "C:\Development\web2py\gluon\globals.py", line 361, in > _try_store_on_disk > cPickle.dump(dict(self), response.session_file) > File "C:\Development\Python\lib\copy_reg.py", line 73, in _reduce_ex > getstate = self.__getstate__ > File "C:\Development\web2py\gluon\sql.py", line 1173, in __getattr__ > return self[key] > File "C:\Development\web2py\gluon\sql.py", line 1156, in __getitem__ > return dict.__getitem__(self, str(key)) > KeyError: '__getstate__' > > I've also noticed warnings in the console that pickling SQLObjects is > experimental. Is storing them in a session not possible? And if not, > any ideas for what would be the best alternative? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---