[CalendarServer-changes] [10270] CalendarServer/branches/users/glyph/queue-locking-and-timing
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jan 4 16:39:36 PST 2013
Revision: 10270
http://trac.calendarserver.org//changeset/10270
Author: glyph at apple.com
Date: 2013-01-04 16:39:36 -0800 (Fri, 04 Jan 2013)
Log Message:
-----------
Refactor attribute updates to make the test pass.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/dal/record.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/queue-locking-and-timing/
Modified: CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/dal/record.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/dal/record.py 2013-01-05 00:39:35 UTC (rev 10269)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/dal/record.py 2013-01-05 00:39:36 UTC (rev 10270)
@@ -230,16 +230,26 @@
result = yield (Insert(colmap, Return=needsCols if needsCols else None)
.on(transaction))
if needsCols:
- for neededAttr, neededValue, neededColumn in zip(needsAttrs,
- result[0],
- needsCols):
- if neededColumn.model.type.name == "timestamp":
- neededValue = parseSQLTimestamp(neededValue)
- setattr(self, neededAttr, neededValue)
+ self._attributesFromRow(zip(needsAttrs, result[0]))
self.transaction = transaction
returnValue(self)
+ def _attributesFromRow(self, attributeList):
+ """
+ Take some data loaded from a row and apply it to this instance,
+ converting types as necessary.
+
+ @param attributeList: a C{list} of 2-C{tuples} of C{(attributeName,
+ attributeValue)}.
+ """
+ for setAttribute, setValue in attributeList:
+ setColumn = self.__attrmap__[setAttribute]
+ if setColumn.model.type.name == "timestamp":
+ setValue = parseSQLTimestamp(setValue)
+ setattr(self, setAttribute, setValue)
+
+
def delete(self):
"""
Delete this row from the database.
@@ -349,11 +359,10 @@
"""
rows = yield qry.on(transaction, raiseOnZeroRowCount=rozrc)
selves = []
+ names = [cls.__colmap__[column] for column in list(cls.table)]
for row in rows:
self = cls()
- for (column, value) in zip(list(cls.table), row):
- name = cls.__colmap__[column]
- setattr(self, name, value)
+ self._attributesFromRow(zip(names, row))
self.transaction = transaction
selves.append(self)
returnValue(selves)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130104/558b5bab/attachment.html>
More information about the calendarserver-changes
mailing list