Get a reference to the latest transaction
Is it possible? If so, how do I get a reference to the last/current transaction that just happened within a method? Pseudo code: class MyFolder(Folder): def manage_afterAdd(self): self.image_count = 0 def addImage(self, imgdata, REQUEST): self.manage_addImage('someid', file=imgdata) self.image_count = self.image_count + 1 url = self.absolute_url() + '?transactionid=%s' % get_transaction().getId() REQUEST.RESPONSE.redirect(url) If I had that, I could then do the following in my template: <div tal:condition="request/transactionid|nothing"> Image uploaded. <a tal:attributes="href string:undoTransaction?transactionid=${request/transactionid}"
Undo</a> </div>
Is it possible? -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
----- Original Message ----- From: "Peter Bengtsson" <peter@fry-it.com> To: "Zope Generic List" <zope@zope.org> Sent: Tuesday, December 12, 2006 9:51 AM Subject: [Zope] Get a reference to the latest transaction
Is it possible? If so, how do I get a reference to the last/current transaction that just happened within a method? Pseudo code:
class MyFolder(Folder): def manage_afterAdd(self): self.image_count = 0 def addImage(self, imgdata, REQUEST): self.manage_addImage('someid', file=imgdata) self.image_count = self.image_count + 1 url = self.absolute_url() + '?transactionid=%s' % get_transaction().getId() REQUEST.RESPONSE.redirect(url)
If I had that, I could then do the following in my template:
<div tal:condition="request/transactionid|nothing"> Image uploaded. <a tal:attributes="href string:undoTransaction?transactionid=${request/transactionid}"
Undo</a> </div>
Is it possible?
You could have a look at manage_UndoForm and see how it gets the transaction information. Jonathan
that doesn't get a particular transaction, it gets all the latest ones. If I use that approach, how do I know that I get my particular transaction and not some other concurrent one? On 12/12/06, Jonathan <dev101@magma.ca> wrote:
----- Original Message ----- From: "Peter Bengtsson" <peter@fry-it.com> To: "Zope Generic List" <zope@zope.org> Sent: Tuesday, December 12, 2006 9:51 AM Subject: [Zope] Get a reference to the latest transaction
Is it possible? If so, how do I get a reference to the last/current transaction that just happened within a method? Pseudo code:
class MyFolder(Folder): def manage_afterAdd(self): self.image_count = 0 def addImage(self, imgdata, REQUEST): self.manage_addImage('someid', file=imgdata) self.image_count = self.image_count + 1 url = self.absolute_url() + '?transactionid=%s' % get_transaction().getId() REQUEST.RESPONSE.redirect(url)
If I had that, I could then do the following in my template:
<div tal:condition="request/transactionid|nothing"> Image uploaded. <a tal:attributes="href string:undoTransaction?transactionid=${request/transactionid}"
Undo</a> </div>
Is it possible?
You could have a look at manage_UndoForm and see how it gets the transaction information.
Jonathan
_______________________________________________ Zope maillist - Zope@zope.org 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
----- Original Message ----- From: "Peter Bengtsson" <peter@fry-it.com> To: "Jonathan" <dev101@magma.ca> Cc: "Zope Generic List" <zope@zope.org> Sent: Tuesday, December 12, 2006 10:11 AM Subject: Re: [Zope] Get a reference to the latest transaction
that doesn't get a particular transaction, it gets all the latest ones. If I use that approach, how do I know that I get my particular transaction and not some other concurrent one?
If you want a specific user to be able to undo a specific transaction, then you may be able do this by getting a transaction id (does transaction_commit return a transaction id?) and then stuffing the transaction id into a SESSION variable. Jonathan
On 12/12/06, Jonathan <dev101@magma.ca> wrote:
----- Original Message ----- From: "Peter Bengtsson" <peter@fry-it.com> To: "Zope Generic List" <zope@zope.org> Sent: Tuesday, December 12, 2006 9:51 AM Subject: [Zope] Get a reference to the latest transaction
Is it possible? If so, how do I get a reference to the last/current transaction that just happened within a method? Pseudo code:
class MyFolder(Folder): def manage_afterAdd(self): self.image_count = 0 def addImage(self, imgdata, REQUEST): self.manage_addImage('someid', file=imgdata) self.image_count = self.image_count + 1 url = self.absolute_url() + '?transactionid=%s' % get_transaction().getId() REQUEST.RESPONSE.redirect(url)
If I had that, I could then do the following in my template:
<div tal:condition="request/transactionid|nothing"> Image uploaded. <a tal:attributes="href string:undoTransaction?transactionid=${request/transactionid}"
Undo</a> </div>
Is it possible?
You could have a look at manage_UndoForm and see how it gets the transaction information.
Jonathan
_______________________________________________ Zope maillist - Zope@zope.org 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
Jonathan wrote:
that doesn't get a particular transaction, it gets all the latest ones. If I use that approach, how do I know that I get my particular transaction and not some other concurrent one?
If you want a specific user to be able to undo a specific transaction, then you may be able do this by getting a transaction id (does transaction_commit return a transaction id?) and then stuffing the transaction id into a SESSION variable.
Here's what I did: import transaction def changeSomething(self): self.foo = 1 random_str = getRandomString() transaction.get().note(random_str) RESPONSE.redirect(self.absolute_url()+'?undonote=%s' %random_str) Later it wasn't difficult to write a custom undo function that searches all undoable transactions' description for this random string and use manage_undo_transactions() with that knowledge. Works really well now but need to test it on a larger scale.
Jonathan
On 12/12/06, Jonathan <dev101@magma.ca> wrote:
----- Original Message ----- From: "Peter Bengtsson" <peter@fry-it.com> To: "Zope Generic List" <zope@zope.org> Sent: Tuesday, December 12, 2006 9:51 AM Subject: [Zope] Get a reference to the latest transaction
Is it possible? If so, how do I get a reference to the last/current transaction that just happened within a method? Pseudo code:
class MyFolder(Folder): def manage_afterAdd(self): self.image_count = 0 def addImage(self, imgdata, REQUEST): self.manage_addImage('someid', file=imgdata) self.image_count = self.image_count + 1 url = self.absolute_url() + '?transactionid=%s' % get_transaction().getId() REQUEST.RESPONSE.redirect(url)
If I had that, I could then do the following in my template:
<div tal:condition="request/transactionid|nothing"> Image uploaded. <a tal:attributes="href string:undoTransaction?transactionid=${request/transactionid}"
Undo</a> </div>
Is it possible?
You could have a look at manage_UndoForm and see how it gets the transaction information.
Jonathan
_______________________________________________ Zope maillist - Zope@zope.org 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
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
participants (2)
-
Jonathan -
Peter Bengtsson