gws.base.model.scalar_field

Base class for scalar fields.

Source code: gws.base.model.scalar_field

Module Contents

class gws.base.model.scalar_field.Config(*args, **kwargs)

Bases: gws.base.model.field.Config

Configuration for the scalar field.

isVirtual: bool | None

The field is not read from or written to the database.

class gws.base.model.scalar_field.Object

Bases: gws.base.model.field.Object

Base scalar field.

Maps the field to the source column with the same name. Provides reading the column and writing it to the record, and the transfer of the value between record, feature and props, applying value objects and field permissions.

isVirtual: bool

The field is not read from or written to the database.

after_select(features, mc)

Called after features are selected, sets the field value in the features.

Parameters:
  • features – The selected features.

  • mc – The model context.

before_create(feature, mc)

Called before a feature is inserted, writes the field value to feature.record.

Parameters:
  • feature – The feature.

  • mc – The model context.

before_select(mc)

Called before features are selected, adds columns and conditions to mc.dbSelect.

Parameters:

mc – The model context.

before_update(feature, mc)

Called before a feature is updated, writes the field value to feature.record.

Parameters:
  • feature – The feature.

  • mc – The model context.

configure()

Configuration hook.

Called when the node is initialized. Raising an exception here aborts the creation of the node.

do_init(feature, mc)

Set the initial field value of a new feature.

Parameters:
  • feature – The feature.

  • mc – The model context.

from_props(feature, mc)

Set the field value from feature.props.

Parameters:
  • feature – The feature.

  • mc – The model context.

from_record(feature, mc)

Set the field value from feature.record.

Parameters:
  • feature – The feature.

  • mc – The model context.

get_value(feature: gws.Feature, source: dict, has_access: bool, convert_fn: Callable, mc: gws.ModelContext)

Compute the field value for the current operation.

A value object that is not a default value provides the value. Otherwise the value is taken from source and converted, if the user has access and the value is not None. Otherwise a default value object provides the value.

Parameters:
  • feature – The feature.

  • source – A dict of attributes to read the value from.

  • has_access – Whether the user may access the field.

  • convert_fn – Function (feature, value, mc) that converts the source value.

  • mc – The model context.

Returns:

The value, or None if there is none.

model_value(mc: gws.ModelContext)

Return the first value object for the current operation that the user can use.

Parameters:

mc – The model context.

Returns:

The value object, or None if there is none.

to_props(feature, mc)

Write the field value to feature.props.

Parameters:
  • feature – The feature.

  • mc – The model context.

to_record(feature, mc)

Write the field value to feature.record.

Parameters:
  • feature – The feature.

  • mc – The model context.

class gws.base.model.scalar_field.Props(*args, **kwargs)

Bases: gws.base.model.field.Props

Object properties.