Find or create an API model object by name
764411
def find(cls, api_name):
        
        if api_name in cls.apis_by_name:
            return cls.apis_by_name[api_name]
        api = cls(api_name)
        api._fetch_from_aws()
        if api.exists_in_aws:
            api._fetch_resources()
        cls.apis_by_name[api_name] = api
        return api
1182255
def instance(cls, name):
        
        if not cls._instance.get(name):
            model_name = name.split('.')
            ins_name = '.'.join(
                ['models', model_name[0], 'model', model_name[1]])
            cls._instance[name] = cls.import_model(ins_name)()

        return cls._instance[name]
1296894
def find_model_by_table_name(name):
    """"""

    for model in ModelBase._decl_class_registry.values():
        if hasattr(model, '__table__') and model.__table__.fullname == name:
            return model
    return None
693496
def api_model_exists(restApiId, modelName, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    r = describe_api_model(restApiId, modelName, region=region, key=key, keyid=keyid, profile=profile)

    return {'exists': bool(r.get('model'))}
725834
function(obj, name, callback, context, listening) {
    obj._events = eventsApi(onApi, obj._events || {}, name, callback, {
      context: context,
      ctx: obj,
      listening: listening
    });

    if (listening) {
      var listeners = obj._listeners || (obj._listeners = {});
      listeners[listening.id] = listening;
    }

    return obj;
  }
1091690
def find_model(config, obj, mods):
    """"""
    for mod in mods:
        if mod[0] != config:
            continue

        if len(mod) == 2:
            return mod[1]

        if len(mod) == 3 and mod[1] in obj:
            return mod[2]

    return None
1099578
def get_object(model, cid, engine_name=None, connection=None):
    
    from uliweb import settings
    
    if not id:
        return 
    
    if not check_enable():
        return
    
    redis = get_redis()
    if not redis: return

    tablename = model._alias or model.tablename
    
    info = settings.get_var('OBJCACHE_TABLES/%s' % tablename, {})
    if info is None:
        return
    
    _id = get_id(engine_name or model.get_engine_name(), tablename, cid)
    try:
        log.debug("Try to find objcache:get:table=%s:id=[%s]" % (tablename, _id))
        if redis.exists(_id):
            v = redis.hgetall(_id)
            o = model.load(v, from_='dump')
            log.debug("Found!")
            return o
        else:
            log.debug("Not Found!")
    except Exception as e:
        log.exception(e)
479626
def get_model(name):
    

    model = MODELS.get(name.lower(), None)

    assert model, "Could not locate model by name '%s'" % name

    return model
791575
def find_or_create(self, constructor, props, *, comp=None):
    
    model = self.find_model(constructor, comp or props)
    if model is None:
      model = constructor(**props)
      self.insert_model(model)
    return model
195154
def get_object_example(self, def_name):
        '''
        
        '''
        def_model = self.definitions[def_name]
        example = dict()
        for opt_name, opt_value in def_model.get('properties', dict()).items():
            var_type = opt_value.get('format', None) or opt_value.get('type', None)
            example[opt_name] = self.get_response_example(opt_name, var_type, opt_value)
            if var_type == 'string':
                example[opt_name] = example[opt_name].format(opt_name)
        return example
590981
def get_object(self, name, obj):
        
        return self[name](obj, **self.opts(name))
423772
def lookup_object(model, object_id, slug, slug_field):
    
    lookup_kwargs = {}
    if object_id:
        lookup_kwargs['%s__exact' % model._meta.pk.name] = object_id
    elif slug and slug_field:
        lookup_kwargs['%s__exact' % slug_field] = slug
    else:
        raise GenericViewError(
            "Generic view must be called with either an object_id or a"
            " slug/slug_field.")
    try:
        return model.objects.get(**lookup_kwargs)
    except ObjectDoesNotExist:
        raise Http404("No %s found for %s"
                      % (model._meta.verbose_name, lookup_kwargs))
1311200
function ModelClassFactory(name, options) {
        if (!isUndef(options)) {
          return config(name, options);
        }
        return registry[name] || undefined;
      }
780410
def get_api_services_by_name(self):
        """"""
        if not self.services_by_name:
            self.services_by_name = dict({s.get('name'): s for s in self.conf
                                          .get("api")
                                          .get("services")})
        return self.services_by_name
793050
def _get_django_objects(model):
    '''
    
    '''
    model_name = model.__class__.__name__
    model_objects = [i for i in model.objects.all()]
    logger.debug('Found {} {} objects in DB'.format(len(model_objects), model_name))
    return model_objects
557977
def get_model_from_key(key):
    """"""
    _known_models = {}
    model_name = key.split(':', 2)[0]
    # populate
    for klass in Model.__subclasses__():
        _known_models[klass.__name__] = klass
    return _known_models.get(model_name, None)
466145
def create_object_model(module_name, object_name, **kwargs):
    '''
    
    '''
    object_kwargs = {}

    try:
        model_module = importlib.import_module('azure.mgmt.{0}.models'.format(module_name))
        # pylint: disable=invalid-name
        Model = getattr(model_module, object_name)
    except ImportError:
        raise sys.exit(
            'The {0} model in the {1} Azure module is not available.'.format(object_name, module_name)
        )

    if '_attribute_map' in dir(Model):
        for attr, items in Model._attribute_map.items():
            param = kwargs.get(attr)
            if param:
                if items['type'][0].isupper() and isinstance(param, dict):
                    object_kwargs[attr] = create_object_model(module_name, items['type'], **param)
                elif items['type'][0] == '{' and isinstance(param, dict):
                    object_kwargs[attr] = param
                elif items['type'][0] == '[' and isinstance(param, list):
                    obj_list = []
                    for list_item in param:
                        if items['type'][1].isupper() and isinstance(list_item, dict):
                            obj_list.append(
                                create_object_model(
                                    module_name,
                                    items['type'][items['type'].index('[')+1:items['type'].rindex(']')],
                                    **list_item
                                )
                            )
                        elif items['type'][1] == '{' and isinstance(list_item, dict):
                            obj_list.append(list_item)
                        elif not items['type'][1].isupper() and items['type'][1] != '{':
                            obj_list.append(list_item)
                    object_kwargs[attr] = obj_list
                else:
                    object_kwargs[attr] = param

    # wrap calls to this function to catch TypeError exceptions
    return Model(**object_kwargs)