- log object_type
[plcapi.git] / PLC / Table.py
index 1229007..cb0eb6b 100644 (file)
@@ -51,20 +51,29 @@ class Row(dict):
                 validate = getattr(self, 'validate_' + key)
                 self[key] = validate(value)
 
-    time_format = "%Y-%m-%d %H:%M:%S"
-    def validate_timestamp (self, timestamp, check_future=False):
-       # in case we try to sync the same object twice
+    def validate_timestamp(self, timestamp, check_future = False):
+        """
+        Validates the specified GMT timestamp string (must be in
+        %Y-%m-%d %H:%M:%S format) or number (seconds since UNIX epoch,
+        i.e., 1970-01-01 00:00:00 GMT). If check_future is True,
+        raises an exception if timestamp is not in the future. Returns
+        a GMT timestamp string.
+        """
+
+        time_format = "%Y-%m-%d %H:%M:%S"
+
        if isinstance(timestamp, StringTypes):
-           # calendar.timegm is the inverse of time.gmtime, in that it computes in UTC
-           # surprisingly enough, no other method in the time module behaves this way
-            # this method is documented in the time module's documentation
-           timestamp = calendar.timegm (time.strptime (timestamp,Row.time_format))
-       human = time.strftime (Row.time_format, time.gmtime(timestamp))
-       if check_future and (timestamp < time.time()):
-            raise PLCInvalidArgument, "%s: date must be in the future"%human
+           # calendar.timegm() is the inverse of time.gmtime()
+           timestamp = calendar.timegm(time.strptime(timestamp, time_format))
+
+        # Human readable timestamp string
+       human = time.strftime(time_format, time.gmtime(timestamp))
+
+       if check_future and timestamp < time.time():
+            raise PLCInvalidArgument, "'%s' not in the future" % human
+
        return human
 
-    @classmethod
     def add_object(self, classobj, join_table, columns = None):
         """
         Returns a function that can be used to associate this object
@@ -103,8 +112,9 @@ class Row(dict):
                 self.api.db.commit()
     
         return add
-    
-    @classmethod
+
+    add_object = classmethod(add_object)
+
     def remove_object(self, classobj, join_table):
         """
         Returns a function that can be used to disassociate this
@@ -138,6 +148,8 @@ class Row(dict):
 
         return remove
 
+    remove_object = classmethod(remove_object)
+
     def db_fields(self, obj = None):
         """
         Return only those fields that can be set or updated directly