File size: 689 Bytes
f7a6add
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from .utils import public_names
class ObjectService:
    def __init__(self, collections): self._collections=collections
    @staticmethod
    def to_record(obj):
        r={}
        for n in public_names(obj):
            try: v=getattr(obj,n)
            except Exception: continue
            if callable(v): continue
            try: r[n]=v if isinstance(v,(str,int,float,bool)) or v is None else str(v)
            except Exception: r[n]=None
        return r
    def collection_records(self,name):
        out=[]
        for key,obj in self._collections.items(name):
            row={"Name":key,"ObjectType":name}; row.update(self.to_record(obj)); out.append(row)
        return out