14 May 17:36
Re: Log changes to rows
From: Jim Steil <jim <at> qlf.com>
Subject: Re: Log changes to rows
Newsgroups: gmane.comp.python.sqlobject
Date: 2008-05-14 15:37:52 GMT
Subject: Re: Log changes to rows
Newsgroups: gmane.comp.python.sqlobject
Date: 2008-05-14 15:37:52 GMT
Oleg Broytmann wrote:
When I changed the event from RowCreatedSignal to RowCreateSignal, everything worked as expected, with the kwargs argument giving me the values of the new record. Ex: {'changedOn': datetime.datetime(2008, 5, 13, 16, 44, 57, 73000), 'county': '', 'distributor': None, 'city': '', 'district': 58, 'title': '', 'state': '', 'address1': '', 'email': '', 'fax': None, 'mobilePhone': None, 'companyName': '', 'phone2': None, 'phone3': None, 'address2': '', 'phone1': None, 'zipCode': '', 'hardcopyPriceLists': False, 'createdOn': datetime.datetime(2008, 5, 13, 16, 44, 57, 73000), 'pager': None, 'homePhone': None, 'firstName': u'Lou', 'lastName': u'Reichers', 'notes': None, 'customerNumber': None, 'coopId': None, 'emailPriceLists': False}
I was expecting these two events to function the same. Is this a bug in the code, or something that I'm not understanding correctly?
-Jim
On Tue, May 13, 2008 at 10:48:24AM -0500, Jim Steil wrote:I've been trying to get my logging working now for the RowCreatedSignal. I was having some issues with the kwargs parm. Instead of returning a dict with the values of my table, it is returning a dict with the class, and the keyfield value of the new record. Ex: {'class': <class 'motion.model.Contact'>, 'id': 11L}Ok, I've gotten my events to work, but now have another newb question that I can't seem to find the answer to. In the update listener I get the kwargs sent in to find which columns have been changed. I can reference them as a dictionary. I want to compare the fields sent in to see if they've changed and to get the previous value of them, but cannot find how to reference the specific column using a variable. What I'd like to do is the following: def updateListener(currentValues, newValues): for columnName in newValues: newValue = newValues[columnName] currentValue = currentValues[columnName] ----- This is what doesn't work # log changes here The currentValues[columnName] doesn't work. How can I get the old value of the changed column?I believe 'currentValues' is the object (SQLObject) to be changed, not a dictionary. Get the values by calling getattr(currentValues, columnName). Oleg.
When I changed the event from RowCreatedSignal to RowCreateSignal, everything worked as expected, with the kwargs argument giving me the values of the new record. Ex: {'changedOn': datetime.datetime(2008, 5, 13, 16, 44, 57, 73000), 'county': '', 'distributor': None, 'city': '', 'district': 58, 'title': '', 'state': '', 'address1': '', 'email': '', 'fax': None, 'mobilePhone': None, 'companyName': '', 'phone2': None, 'phone3': None, 'address2': '', 'phone1': None, 'zipCode': '', 'hardcopyPriceLists': False, 'createdOn': datetime.datetime(2008, 5, 13, 16, 44, 57, 73000), 'pager': None, 'homePhone': None, 'firstName': u'Lou', 'lastName': u'Reichers', 'notes': None, 'customerNumber': None, 'coopId': None, 'emailPriceLists': False}
I was expecting these two events to function the same. Is this a bug in the code, or something that I'm not understanding correctly?
-Jim
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ sqlobject-discuss mailing list sqlobject-discuss <at> lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
RSS Feed