def _load_models(app_settings): """ Database Model. """ logging.info('loading database model') for app_name in app_settings.apps: _models = __import__('apps.%s' % app_name, globals(), locals(), ['models'], -1) try: models = _models.models except AttributeError: # this app simply doesn't have a models.py file continue logging.info(models) model_ids = [] for name in [x for x in dir(models) if re.findall('[A-Z]\w+', x)]: thing = getattr(models, name) logging.info(thing) try: if issubclass(thing, BaseModel): """ models.User.ops.Add, models.User.ops.Update """ if thing.model_id>0 and thing.model_id in model_ids: raise Exception("%s model_id must be unique") model_ids.append(thing.model_id) thing.ops = make_storage(thing.model_ops, base=thing.model_id*100) model_manager.add(thing) except TypeError: # most likely a builtin class or something pass setattr(app_global, 'models', model_manager)
def _load_mq_handlers(app_settings): logging.info('loading mq handlers') for app_name in app_settings.apps: _models = __import__('apps.%s' % app_name, globals(), locals(), ['mq'], -1) try: models = _models.mq except AttributeError: # this app simply doesn't have a models.py file continue logging.debug(models) for name in [x for x in dir(models) if re.findall('[A-Z]\w+', x)]: thing = getattr(models, name) logging.debug(thing) try: if issubclass(thing, mq.Message): model_manager.add(thing) except TypeError: # most likely a builtin class or something pass