def __init__(self, api_key): self.__http = Http(api_key) self.__interfaces = {} for model_name in allmodels: model_cls = ModelRegistry.get_model(model_name) namespace = {"session": self} mymodel = type(model_name, (model_cls, ), namespace) setattr(self, model_name, mymodel) self.__interfaces[model_name] = mymodel
def all_entities(self): """Generator that retrieves all entities in the folder.""" entity_models = ModelRegistry.filter_models_by_base_classes( InventoryEntityMixin ) for model in entity_models: interface = self.session.interface(model.__name__) for m in interface.all(folder_id=self.id): yield m
def __init__(self, api_key, home=""): self.__http = Http(api_key) if home: self.__http.HOME = f"https://{home}.benchling.com/api/v2" self.__interfaces = {} for model_name in allmodels: model_cls = ModelRegistry.get_model(model_name) namespace = {"session": self} mymodel = type(model_name, (model_cls, ), namespace) setattr(self, model_name, mymodel) self.__interfaces[model_name] = mymodel
def clean_up_folder(folder): # clean up trash fol der print("Cleaning trash folder") entity_models = ModelRegistry.filter_models_by_base_classes( [mixins.InventoryEntityMixin] ) for model in entity_models: interface = folder.session.interface(model.__name__) print('Archiving "{}" models...'.format(model.__name__)) for m in interface.all(folder_id=folder.id): print("Archiving {}".format(m)) try: m.archive(m.ARCHIVE_REASONS.OTHER) except Exception as e: print(e)
def batches(self) -> ModelBase: """Get an entities batches.""" result = self.session.http.get( self._url_build("entities", self.id, "batches")) return ModelRegistry.get_model("Batch").load_many(result["batches"])