def update(self, **kwargs): serial = rel.get(self.__tablename__, rel['Service']) for property, value in kwargs.items(): property_type = property_types.get(property, None) if property in serial: value = fetch(serial[property], id=value) elif property[:-1] in serial: value = objectify(serial[property[:-1]], value) elif property in boolean_properties: value = kwargs[property] not in (None, False) elif 'regex' in property: value = property in kwargs elif property_type == 'dict' and type(value) == str: value = loads(value) if value else {} elif property_type in ['float', 'int']: default_value = getattr(self.__table__.c, property).default if default_value and not value: value = default_value.arg value = {'float': float, 'int': int}[property_type](value or 0) setattr(self, property, value)
def update(self, **kwargs: Any) -> None: serial = rel.get(self.__tablename__, rel["Service"]) for property, value in kwargs.items(): property_type = property_types.get(property, None) if property in serial: value = fetch(serial[property], id=value) elif property[:-1] in serial: value = objectify(serial[property[:-1]], value) elif property in boolean_properties: value = kwargs[property] not in (None, False) elif "regex" in property: value = property in kwargs elif property_type == "dict" and type(value) == str: value = loads(value) if value else {} elif property_type in ["float", "int"]: default_value = getattr(self.__table__.c, property).default if default_value and not value: value = default_value.arg value = {"float": float, "int": int}[property_type](value or 0) setattr(self, property, value)
def to_dict(self, export=False): properties = self.get_properties(export) no_migrate = dont_migrate.get(self.type, dont_migrate['Service']) for property in rel.get(self.type, rel['Service']): if export and property in no_migrate: continue if hasattr(self, property): if hasattr(getattr(self, property), 'get_properties'): properties[property] = (getattr( self, property).id if export else getattr( self, property).get_properties()) if hasattr(self, f'{property}s'): # a workflow has edges: we need to know not only the edge # properties, but also the properties of its source and # destination: we need the serialized edge. properties[f'{property}s'] = [ obj.id if export else obj.get_properties() for obj in getattr(self, f'{property}s') ] if export: for property in no_migrate: properties.pop(property, None) return properties