def type_from_name(name, as_mongo_obj=False): """ Given a type name ('standard_pin', 'shipping_dewar'), return the name of it's base type ('sample', 'container'). """ if isinstance(name, str): name = unicode(name) try: if as_mongo_obj: return Types.objects(__raw__={'name': name})[0] return Types.objects(__raw__={'name': name})[0].parent_type except IndexError: return None
def _find_types(object_type, as_mongo_obj=False): types = {} for t in Types.objects(__raw__={'$or': [{'name': object_type}, {'parent_type': object_type}]}): if as_mongo_obj: types[t.id] = t else: types[t.id] = t.to_mongo() return types
def getContainersByType(type_name, group_name, as_mongo_obj=False): if isinstance(type_name, unicode) or isinstance(type_name, str): type_obj = type_from_name(type_name, as_mongo_obj=True) else: type_obj = type_name # go one level deaper for now? maybe we should have another field to search on # "class" or something? :( container_types = Types.objects(__raw__={'$or': [{'name': type_name}, {'parent_type': type_name}]}) #c = Container.objects(container_type=type_obj) #c = Container.objects(__raw__={'container_type': {'$in': container_types}}) c = Container.objects(container_type__in=container_types) return _ret_list(c, as_mongo_obj=as_mongo_obj)