gws.plugin.model_value.expression¶
Expression value.
Computes the value by evaluating a Python expression. The expression is compiled at configuration time; a syntax error is a configuration error.
The following variables are available in the expression:
app: the Application object,user: the current user,project: the current project,feature: the feature the value is computed for,mc: thegws.ModelContextobject,date: thegws.lib.datetimexmodule.
Additional modules can be made available with the imports option, a list
of module names, e.g. ["math", "os.path"]. Each module is available under
its top-level package name, so os.path is used as os.path.join(...).
If a module cannot be imported or the evaluation fails, the error is logged
and the value is None.
Example:
fields+ {
name "area_ha"
type "float"
values+ {
type "expression"
expression "round(feature.get('area_m2', 0) / 10000, 2)"
}
}
Source code: gws.plugin.model_value.expression
Package Contents¶
- class gws.plugin.model_value.expression.Config¶
Bases:
gws.base.model.value.ConfigValue computed by a Python expression.