- def get (self, field, default):
- return getattr(self,field,default)
-
- @validates ('gid')
- def validate_gid (self, key, gid):
- if gid is None: return
- elif isinstance(gid, StringTypes): return gid
- else: return gid.save_to_string(save_parents=True)
-
- def validate_datetime (self, key, incoming):
- if isinstance (incoming, datetime): return incoming
- elif isinstance (incoming, (int,float)):return datetime.fromtimestamp (incoming)
- else: logger.info("Cannot validate datetime for key %s with input %s"%\
- (key,incoming))
-
- @validates ('date_created')
- def validate_date_created (self, key, incoming): return self.validate_datetime (key, incoming)
-
- @validates ('last_updated')
- def validate_last_updated (self, key, incoming): return self.validate_datetime (key, incoming)
-
- # xxx - there might be smarter ways to handle get/set'ing gid using validation hooks
- def get_gid_object (self):
- if not self.gid: return None
- else: return GID(string=self.gid)
-
- def just_created (self):
- now=datetime.utcnow()
- self.date_created=now
- self.last_updated=now
-
- def just_updated (self):
- now=datetime.utcnow()
- self.last_updated=now
-
-#################### cross-relations tables
+ def get(self, field, default):
+ return getattr(self, field, default)
+
+ @validates('gid')
+ def validate_gid(self, key, gid):
+ if gid is None:
+ return
+ elif isinstance(gid, StringType):
+ return gid
+ else:
+ return gid.save_to_string(save_parents=True)
+
+ def validate_datetime(self, key, incoming):
+ if isinstance(incoming, datetime):
+ return incoming
+ elif isinstance(incoming, (int, float)):
+ return datetime.fromtimestamp(incoming)
+ else:
+ logger.info("Cannot validate datetime for key %s with input %s" %
+ (key, incoming))
+
+ @validates('date_created')
+ def validate_date_created(self, key, incoming):
+ return self.validate_datetime(key, incoming)
+
+ @validates('last_updated')
+ def validate_last_updated(self, key, incoming):
+ return self.validate_datetime(key, incoming)
+
+ # xxx - there might be smarter ways to handle get/set'ing gid using
+ # validation hooks
+ def get_gid_object(self):
+ if not self.gid:
+ return None
+ else:
+ return GID(string=self.gid)
+
+ def just_created(self):
+ now = datetime.utcnow()
+ self.date_created = now
+ self.last_updated = now
+
+ def just_updated(self):
+ now = datetime.utcnow()
+ self.last_updated = now
+
+# cross-relations tables