I haven't quite wrapped my head around how mapping/objectstore.py
works yet, and its documentation is still unfinished, so I think my
best bet is to ask here.
I'm writing a toy application to get used to using SQLAlchemy in
"real" work. I have a GUI dialog that presents data to the user, and I
want him to be able to fill it out and click either OK to save the
data or Cancel to cancel his changes and leave the database untouched.
The text fields in the dialog all have event handlers that catch a
lose-focus event (such as tabbing away from the control), check
whether they've been modified, and if so, update the mapped-table
object (by doing "setattr(self.data_record, column.name,
ctrl.GetValue())"). The dialog's event handlers for the OK and Cancel
buttons look like this:
def OnOK(self, event):
log.info("Saving...")
objectstore.commit()
engine.commit()
event.Skip() # Let the event propagate up to the standard handler
def OnCancel(self, event):
log.info("Reverting...")
objectstore.commit()
engine.rollback()
event.Skip() # Let the event propagate up to the standard handler
(I call engine.begin() when the dialog is first presented to the user).
That seems to work, but the OnCancel handler is bugging me. Doing
objectstore.commit() followed immediately by engine.rollback() seems
wrong. I'd like to have an objectstore.rollback() method, but I don't
see one. Should I call objectstore.uow().rollback()? Would that do
what I'm looking for?
This is probably really simple, but I just don't have my head wrapped
around the unit of work system yet.
--
Robin Munn
[EMAIL PROTECTED]
GPG key 0xD6497014