Ejemplo n.º 1
0
Archivo: _field.py Proyecto: a25kk/stv2
    def get(self, instance, **kwargs):
        # Get the Expression
        expr = ObjectField.get(self, instance, **kwargs)

        # use a custom context if it has been passed in
        context = kwargs.get('expression_context')
        if context is None:
            context = getExprContext(instance, instance)

        # Expression's __call__ returns a context dictionary if the
        # expression's text is an empty string.  We return None instead.
        if expr.text.strip():
            # Return the evaluated expression
            value = expr(context)
            return encode(value, instance, **kwargs)
        else:
            return None
Ejemplo n.º 2
0
Archivo: _field.py Proyecto: a25kk/stv2
    def get(self, instance, **kwargs):
        # Get Expressions
        exprs = ObjectField.get(self, instance, **kwargs)

        # use a custom context if it has been passed in
        context = kwargs.get('expression_context')
        if context is None:
            context = getExprContext(instance, instance)

        # Return evaluated expressions, and check for empty expr texts.
        value = []
        for expr in exprs:
            if expr.text.strip():
                line = expr(context)
                value.append(encode(line, instance, **kwargs))
            else:
                value.append(None)
        return value