X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fstorage%2Frecord.py;h=593176513e9bb4dee64688cf87604b940b4c607f;hb=c7c7ed1178348445dc4ae70ea0fd905625e95421;hp=f3aa8ee9b620f668e0e5939f9f76845f09092cb2;hpb=cedf37c8661ec0b05349274962bf2db9cfa6a24d;p=sfa.git diff --git a/sfa/storage/record.py b/sfa/storage/record.py index f3aa8ee9..59317651 100644 --- a/sfa/storage/record.py +++ b/sfa/storage/record.py @@ -4,14 +4,16 @@ from datetime import datetime from sfa.util.xml import XML from sfa.trust.gid import GID +from sfa.util.sfalogging import logger + class Record: - def __init__(self, dict=None, xml=None): + def __init__(self, dict=None, xml_str=None): if dict: self.load_from_dict(dict) - elif xml: - xml_record = XML(xml) - xml_dict = xml_record.todict() + elif xml_str: + xml = XML(xml_str) + xml_dict = xml.todict() self.load_from_dict(xml_dict) @@ -33,10 +35,18 @@ class Record: # fallback return "** undef_datetime **" - def todict (self): - d=self.__dict__ - keys=[k for k in d.keys() if not k.startswith('_')] - return dict ( [ (k,d[k]) for k in keys ] ) + # + # need to filter out results, esp. wrt relationships + # exclude_types must be a tuple so we can use isinstance + # + def record_to_dict (self, exclude_types=None): + if exclude_types is None: + exclude_types = () + d = self.__dict__ + def exclude (k, v): + return k.startswith('_') or isinstance (v, exclude_types) + keys = [ k for k, v in d.items() if not exclude(k, v) ] + return { k : d[k] for k in keys } def toxml(self): return self.save_as_xml() @@ -91,7 +101,7 @@ class Record: # handle gid if attrib_name == 'gid': print " gid:" - print GID(attrib).dump_string(8, dump_parents) + print GID(string=attrib).dump_string(8, dump_parents) elif attrib_name in ['date created', 'last updated']: print " %s: %s" % (attrib_name, self.date_repr(attrib_name)) else: