Can I stop processing while saving data?
Hi guys, Problem: In our site, there are some pages that require that a user be logged in. We implemented a login mechanism using sessions, and we do not use Zope authentication. Now, in order to make the maintenance of this manageable, we used a property, called "LoginRequired", which is checked by our standard_html_header. If a user tries to access a document which has this property set, without being logged in, we redirect her to the login page. The thing is, it is very convenient to assume, while developing, that if you set the "LoginRequired" property, a user executing your code is logged in; thus, the code in many places assumes things like a user_id in the session data. This, in turn, means that if the redirection is done with RESPONSE.redirect, a Zope Error will occur in the processing of the page. What we really want to do at this point is just stop the processing -- and we can do that by a <dtml-raise Redirect>. The tricky part is, that an intelligent site, once the user has logged in, takes her to the page she asked to see in the first place. For this, we need to keep some data -- like, where she was going, so we can redirect her there after she logs in; and the natural place for such info is in the session. But raising an exception (like a Redirect) causes all data changes to be rolled back, so we have a problem. Up to now, we have been using SQLSession; there, we could force a database commit before raising the Redirect exception. This is an ugly kludge, but it worked. Now we want to switch to CoreSessionTracking, and I see no nice or kludgey way to do it there. Any ideas? Thanks, Shai.
Stupid me. Of course I can. get_transaction().commit(). Thanks for your help, Shai.
Chris Withers wrote:
Shai Berger wrote:
Stupid me. Of course I can.
get_transaction().commit().
You may want to look at subtransactions too...
I did. And as far as I could see, they wouldn't help for the problem I described -- au contraire, they are only useful if you continue processing. And if you save your data in subtransactions, but never commit the master transaction, they _will_ be rolled back and forgotten when you raise an exception (at least according to the docs -- haven't tried it). Thanks, Shai.
Shai Berger wrote:
never commit the master transaction, they _will_ be rolled back and forgotten when you raise an exception (at least according to the docs -- haven't tried it).
Sorry, I must have misread your original post :-S cheers, Chris
participants (2)
-
Chris Withers -
Shai Berger