Пример #1
0
 def register_models_for_app_name(self, app_name):
     models_module = importlib.import_module("%s.%s" % (app_name, 'models'))
     from elasticosm.models import ElasticModel
     if ElasticModel.__get_elastic_type_name__() in self.inheritance_registry:
         all_inherited_types = self.inheritance_registry[ElasticModel.__get_elastic_type_name__()]
     else:
         all_inherited_types = set()
     for k, v in models_module.__dict__.items():
         if inspect.isclass(v):
             if is_elastic_model(v):
                 self.register_model(v())
                 all_inherited_types.add(v.__get_elastic_type_name__())
                 bases = get_all_base_classes(v)
                 for base in bases:
                     if is_elastic_model(base):
                         if base is not ElasticModel:
                             all_inherited_types.add(
                                             base.__get_elastic_type_name__()
                                             )
                             if base.__get_elastic_type_name__() in self.inheritance_registry:
                                 inherited_types = self.inheritance_registry[base.__get_elastic_type_name__()]
                             else:
                                 inherited_types = set()
                             inherited_types.add(v.__get_elastic_type_name__())
                             self.inheritance_registry[base.__get_elastic_type_name__()] = inherited_types
     self.inheritance_registry[ElasticModel.__get_elastic_type_name__()] = all_inherited_types
Пример #2
0
 def get(cls, *args, **kwargs):
     type_name = cls.__get_elastic_type_name__()
     from elasticosm.models import ElasticModel
     base_model_type = ElasticModel.__get_elastic_type_name__()
     if type_name == base_model_type:
         type_name = None
     r = ElasticOSMConnection.get(type_name, kwargs)
     if r.count() < 1:
         return None
     if r.count() > 1:
         raise MultipleObjectsReturned(
                 'Multiple objects returned for query %s' % kwargs
                 )
     return r[0]
Пример #3
0
 def get_instance(self):
     if self.instance is None:
         from elasticosm.models import ElasticModel
         self.instance = ElasticModel.get(id=self.instance_id)
     return self.instance
Пример #4
0
 def get_by_id(obj_id, type_name=None):
     from elasticosm.models import ElasticModel
     return ElasticModel.filter(id=obj_id)[0]