On Jul 8, 2008, at 12:01 PM, Christian Boos wrote: > Christian Boos wrote: >> Erik Bray wrote: >> >>> ... >>> Much, much nicer than having to write: >>> def _foo(self, env, db=None): >>> ... >>> def foo(self, env, db=None): >>> transaction(env, db, self._foo) >>> >>> over and over and over again... >>> >>> >> >> Not really. If you look carefully at the changeset, you'll see that >> the >> _foo and foo methods aren't the same. >> The foo (like "delete") does a transaction, then notifies the >> listeners >> (and that needs to be outside the transaction). >> >> However, this is not the final form, it can be simplified further. >> I only used a secondary foo_ method in order to minimize the >> changes to >> model.py, something wise to do for branches... >> >> The final form will look something like: >> > > Well, after some actual testing: > > def delete(self, version=None, db=None): > assert self.exists, 'Cannot delete non-existent page' > def do_delete(db): > cursor = db.cursor() > ... > transaction(self.env, db, do_delete) > > # Let change listeners know about the deletion > if not self.exists: > ... > > That's as clean as it can get, IMO.
I will write up an example of the decorator/generator method later today. --Noah --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Trac Development" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/trac-dev?hl=en -~----------~----~----~----~------~----~------~--~---
