X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fstorage%2Frecord.py;h=9fcab19f8b81e03f7532e9a3684728a20cab740d;hb=be71b8d7c957590aecb593e5c9be315aa189729f;hp=0ac188f1f818af0f4927cacb853684e5379de7f0;hpb=bc77b3e1ce73d7f748d9cc978472dba246034d74;p=sfa.git diff --git a/sfa/storage/record.py b/sfa/storage/record.py index 0ac188f1..9fcab19f 100644 --- a/sfa/storage/record.py +++ b/sfa/storage/record.py @@ -33,9 +33,18 @@ class Record: # fallback return "** undef_datetime **" - def todict (self): + # it may be important to exclude relationships, which fortunately + # + def todict (self, exclude_types=None): + if exclude_types is None: exclude_types=[] d=self.__dict__ - keys=[k for k in d.keys() if not k.startswith('_')] + def exclude (k,v): + if k.startswith('_'): return True + if exclude_types: + for exclude_type in exclude_types: + if isinstance (v,exclude_type): return True + return False + keys=[k for (k,v) in d.items() if not exclude(k,v)] return dict ( [ (k,d[k]) for k in keys ] ) def toxml(self):