[CalendarServer-changes] [14422] twext/branches/users/cdaboo/pod2pod-migration/twext/enterprise/dal/ record.py

source_changes at macosforge.org source_changes at macosforge.org
Tue Feb 17 09:47:33 PST 2015


Revision: 14422
          http://trac.calendarserver.org//changeset/14422
Author:   cdaboo at apple.com
Date:     2015-02-17 09:47:33 -0800 (Tue, 17 Feb 2015)
Log Message:
-----------
Properly map complex types to/from str for serialization.

Modified Paths:
--------------
    twext/branches/users/cdaboo/pod2pod-migration/twext/enterprise/dal/record.py

Modified: twext/branches/users/cdaboo/pod2pod-migration/twext/enterprise/dal/record.py
===================================================================
--- twext/branches/users/cdaboo/pod2pod-migration/twext/enterprise/dal/record.py	2015-02-17 01:22:15 UTC (rev 14421)
+++ twext/branches/users/cdaboo/pod2pod-migration/twext/enterprise/dal/record.py	2015-02-17 17:47:33 UTC (rev 14422)
@@ -171,6 +171,10 @@
         return r
 
 
+    def __hash__(self):
+        return hash(tuple([getattr(self, attr) for attr in self.__attrmap__.keys()]))
+
+
     def __eq__(self, other):
         if type(self) != type(other):
             return False
@@ -668,7 +672,14 @@
         @rtype: L{dict} of L{str}:L{str}
         """
 
-        result = dict([(attr, getattr(self, attr),) for attr in self.__attrmap__])
+        # Certain values have to be mapped to str
+        result = {}
+        for attr in self.__attrmap__:
+            value = getattr(self, attr)
+            col = self.__attrmap__[attr]
+            if col.model.type.name == "timestamp" and value is not None:
+                value = str(value)
+            result[attr] = value
         return result
 
 
@@ -688,5 +699,14 @@
         @rtype: L{SerializableRecord}
         """
 
-        record = cls.make(**attrmap)
+        # Certain values have to be mapped to non-str types
+        mapped = {}
+        for attr in attrmap:
+            value = attrmap[attr]
+            col = cls.__attrmap__[attr]
+            if col.model.type.name == "timestamp" and value is not None:
+                value = parseSQLTimestamp(value)
+            mapped[attr] = value
+
+        record = cls.make(**mapped)
         return record
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150217/b0aac3c5/attachment.html>


More information about the calendarserver-changes mailing list