Question

I have a ton of code that is editing a database, but what I want to do is load all of the data I need to edit or add into a session, return a webpage and once the user has looked over the data, then commit to the database. Something like this:

def index(self):
    empsTbl = meta.Session.query(model.Person).all();
    newEmp = model.Person()
    newEmp.userid = row[0].strip()
    meta.Session.add(newEmp)
    return render("/update.html")

def commitSession(self):
    meta.Session.commit()

If I try to press a web page button to call the commitSession def, the Session seems to be empty. I have tried some stuff on the model such as:

Session.configure(autoflush=False, autocommit = False, bind=engine)

and I have also changed the basecontroller. I removed the code:

meta.Session.remove()

So that it would not remove the session after each call.

I have also tried using merge, to see if that would store the session in the persistant database Session:

meta.Session.merge(newEmp)

But I still cant seem to get it to work.

Edit:

If anybody could give advise on the best way to pickle a Python Session that would be very helpful

Was it helpful?

Solution

i hope it isn't so, but it seems that you not yet understand the lifecycles in what your web-app lives. in your case you have 2 lifecycles, because you have 2 actions. 2 request/response-scenarios. you have to understand, that (mostly) all the stuff you do in an action, it stays in there. your database-session of the action "index" is another as the one in "commitSession", because of that, that session in "commitSession" is empty. Why? Because you just commit a newly created session.

what you have to do is to find a working way for you and your cause to transport the information from action "index" to the action "commitSession". the mostly used way is to serialize the information, put it into your websession, deserialize it in the "commitSession"-action, write it to the database and invalidate your informations in the websession. or you put all the information out of "index" in some hidden fields, and post them again against "commitSession".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top