Пример #1
0
def field_repr(request, head, obj, appmodel):
    '''Retrive the value of field specified in *head* from an object *obj*.'''
    val = None
    attrname = head.attrname
    if hasattr(obj, attrname):
        try:
            val = getattr(obj, attrname)
            if not isclass(val) and hasattr(val, '__call__'):
                val = val()
        except Exception as e:
            val = str(e)
            logger.error('Unhadled exception in field representation',
                         exc_info=True)
    elif hasattr(obj, '__getitem__') and field_name in obj:
        val = obj[field_name]
    if appmodel:
        obj = orms.orm_instance(obj)
        val = appmodel.instance_field_value(request, obj, head.code, val)
    return nicerepr(val, settings=request.settings)
Пример #2
0
def make_request(environ, node, instance=None, cache=True):
    '''Internal method for creating a :class:`Request` instance.'''
    instance = orms.orm_instance(instance)
    if not node.error:
        view = node.view
        model = view.model
        if isclass(model):
            if not isinstance(instance, model):
                try:
                    # get the instance of model if any
                    instance = view.instance_from_variables(environ,
                                                            node.urlargs)
                    if is_async(instance):
                        callback = partial(build_request, environ, node, cache)
                        return instance.addBoth(
                                partial(build_request, environ, node, cache))
                except Exception as e:
                    instance = as_failure(e)
        else:
            instance = None
    return build_request(environ, node, cache, instance)
Пример #3
0
def make_request(environ, node, instance=None, cache=True):
    '''Internal method for creating a :class:`Request` instance.'''
    instance = orms.orm_instance(instance)
    if not node.error:
        view = node.view
        model = view.model
        if isclass(model):
            if not isinstance(instance, model):
                try:
                    # get the instance of model if any
                    instance = view.instance_from_variables(
                        environ, node.urlargs)
                    if is_async(instance):
                        callback = partial(build_request, environ, node, cache)
                        return instance.addBoth(
                            partial(build_request, environ, node, cache))
                except Exception as e:
                    instance = as_failure(e)
        else:
            instance = None
    return build_request(environ, node, cache, instance)