def to_dict(self, export=False, relation_names_only=False, exclude=None, include=None): properties = self.get_properties(export, exclude=exclude) no_migrate = dont_migrate.get(self.type, dont_migrate["service"]) for property, relation in relationships[self.type].items(): if include and property not in include or exclude and property in exclude: continue if export and property in no_migrate: continue value = getattr(self, property) if relation["list"]: properties[property] = [ obj.name if export or relation_names_only else obj.get_properties(exclude=exclude) for obj in value ] else: if not value: continue properties[property] = (value.name if export or relation_names_only else value.get_properties(exclude=exclude)) return properties
def get_properties(self, export=False, exclude=None, include=None): result = {} no_migrate = dont_migrate.get(self.type, dont_migrate["service"]) properties = list(model_properties[self.type]) if not export: properties.extend(getattr(self, "model_properties", [])) for property in properties: if not hasattr(self, property): continue if property in dont_serialize.get(self.type, []): continue if property in private_properties: continue if include and property not in include or exclude and property in exclude: continue if export and property in no_migrate: continue value = getattr(self, property) if export: if isinstance(value, MutableList): value = list(value) if isinstance(value, MutableDict): value = dict(value) if value is None: continue result[property] = value return result
def get_properties( self, export: bool = False, exclude: Optional[list] = None, include: Optional[list] = None, ) -> dict: result = {} no_migrate = dont_migrate.get(self.type, dont_migrate["Service"]) for property in model_properties[self.type]: if property in private_properties or property in dont_serialize: continue if include and property not in include or exclude and property in exclude: continue if export and property in no_migrate: continue value = getattr(self, property) if export: if isinstance(value, MutableList): value = list(value) if isinstance(value, MutableDict): value = dict(value) if value is None: continue result[property] = value return result
def to_dict(self, export: bool = False) -> dict: properties = self.get_properties(export) no_migrate = dont_migrate.get(self.type, dont_migrate["Service"]) for property, relation in relationships[self.type].items(): value = getattr(self, property) if export and property in no_migrate: continue if relation["list"]: properties[property] = [ obj.name if export else obj.get_properties() for obj in value ] else: properties[property] = value.name if export else value.get_properties() if export: for property in no_migrate: properties.pop(property, None) return properties