Exemplo n.º 1
0
Arquivo: model.py Projeto: sylane/feat
def _validate_model_factory(factory):
    if (factory is None
        or isinstance(factory, str)
        or IModelFactory.providedBy(factory)):
        return factory
    if callable(factory):
        return staticmethod(factory)
    return IModelFactory(factory)
Exemplo n.º 2
0
Arquivo: model.py Projeto: sylane/feat
 def _got_model_factory(self, model_factory, source, view):
     model = source
     factory = None
     if IModelFactory.providedBy(model_factory):
         factory = IModelFactory(model_factory)
     elif isinstance(model_factory, str):
         factory = get_factory(model_factory)
     if factory is not None:
         model = factory(source)
     return self._init_model(model, view)
Exemplo n.º 3
0
Arquivo: model.py Projeto: sylane/feat
    def _wrap_source(self, source, view, model_factory):
        if source is None:
            return source

        if IReference.providedBy(source):
            return source

        if IModel.providedBy(source):
            return self._init_model(source, view)

        if not IModelFactory.providedBy(model_factory):
            if callable(model_factory):
                ctx = self.model.make_context(key=self.name, view=view)
                d = model_factory(source, ctx)
                d.addCallback(self._got_model_factory, source, view)
                return d

        return self._got_model_factory(model_factory, source, view)