else:
raise Exception, "Invalid format %s" % format
+ # xxx fixme
+ # turns out the date_created field is received by the client as a 'created' int
+ # (and 'last_updated' does not make it at all)
+ # let's be flexible
+ def date_repr (self,fields):
+ if not isinstance(fields,list): fields=[fields]
+ for field in fields:
+ value=getattr(self,field,None)
+ if isinstance (value,datetime):
+ return datetime_to_string (value)
+ elif isinstance (value,(int,float)):
+ return datetime_to_string(utcparse(value))
+ # fallback
+ return "** undef_datetime **"
+
def dump_text(self, dump_parents=False):
# print core fields in this order
- core_fields = [ 'hrn', 'type', 'authority', 'date_created', 'last_updated', 'gid', ]
+ core_fields = [ 'hrn', 'type', 'authority', 'date_created', 'created', 'last_updated', 'gid', ]
print "".join(['=' for i in range(40)])
print "RECORD"
print " hrn:", self.hrn
print " type:", self.type
print " authority:", self.authority
- date_created = utcparse(datetime_to_string(self.date_created))
- print " date created:", date_created
- last_updated = utcparse(datetime_to_string(self.last_updated))
- print " last updated:", last_updated
+ print " date created:", self.date_repr( ['date_created','created'] )
+ print " last updated:", self.date_repr('last_updated')
print " gid:"
- print "\t\t", self.get_gid_object().dump_string(8, dump_parents)
+ print self.get_gid_object().dump_string(8, dump_parents)
# print remaining fields
for attrib_name in dir(self):
- # skip core fields
- if attrib_name in core_fields:
- continue
- # skik callables
attrib = getattr(self, attrib_name)
- if callable(attrib):
- continue
+ # skip internals
+ if attrib_name.startswith('_'): continue
+ # skip core fields
+ if attrib_name in core_fields: continue
+ # skip callables
+ if callable (attrib): continue
print " %s: %s" % (attrib_name, attrib)
def dump_simple(self):
- return "Record(record_id=%s, hrn=%s, type=%s, authority=%s, pointer=%s)" % \
- (self.record_id, self.hrn, self.type, self.authority, self.pointer)
+ return "%s"%self
# # only intended for debugging
# def inspect (self, logger, message=""):