gws.base.model.field

Base model field.

Source code: gws.base.model.field

Module Contents

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

Bases: gws.ConfigWithAccess

Configuration for the model field.

isAuto: bool | None

The value is set by the database and never written.

isHidden: bool | None

The field is not automatically displayed in the UI.

isPrimaryKey: bool | None

The field is a primary key.

isRequired: bool | None

The field must not be empty.

isUnique: bool | None

The field is unique.

name: str

Field name, matching the column or attribute name in the source.

title: str | None

Field title shown in the client.

validators: list[gws.ext.config.modelValidator] | None

Additional validators for the field value.

values: list[gws.ext.config.modelValue] | None

Value sources that compute the field value on read, create or update.

widget: gws.ext.config.modelWidget | None

Widget that displays and edits the field in the client.

class gws.base.model.field.Object

Bases: gws.ModelField

Base model field.

Provides the field flags, value objects, validators, widget, props and validation. Subclasses implement reading and writing the field value and the conversion between record, feature and props values.

formatValidator: gws.ModelValidator

Validator that checks the format of the value.

notEmptyValidator: gws.ModelValidator

Validator that checks that the value is not empty.

configure()

Configuration hook.

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

configure_flags()

Set the field flags from the configuration or the source column.

isPrimaryKey, isRequired and isAuto default to the properties of the source column with the field name. isUnique and isHidden default to False.

configure_validators()

Create the configured validators.

Configured notEmpty and format validators replace the shared default ones, which apply to create and update.

Returns:

Always True.

configure_values()

Create the configured value objects.

Returns:

True if values are configured, None otherwise.

configure_widget()

Create the configured widget.

Returns:

True if a widget is configured, None otherwise.

create_validator(cfg)

Create a validator as a child of this field.

Parameters:

cfg – The validator configuration.

Returns:

The validator object.

describe()

Return the description of the source column of this field.

Returns:

The column description, or None if the source has no such column.

do_validate(feature, mc)

Validate the field value and append errors to feature.errors.

Parameters:
  • feature – The feature.

  • mc – The model context.

find_relatable_features(search, mc)

Find features that can be linked by this field.

Parameters:
  • search – The search query.

  • mc – The model context.

Returns:

The features found in the related models.

prop_to_python(feature, value, mc)

Convert a client props value to a python value.

Parameters:
  • feature – The feature.

  • value – The value to convert.

  • mc – The model context.

Returns:

The converted value.

props(user)

Generate a Props struct for this object.

Do not call this method directly, use gws.props_of instead, which also checks permissions.

Parameters:

user – The user for which the props should be generated.

Returns:

A Props object or a dict. Nested objects are converted to props as well.

python_to_prop(feature, value, mc)

Convert a python value to a client props value.

Parameters:
  • feature – The feature.

  • value – The value to convert.

  • mc – The model context.

Returns:

The converted value.

python_to_raw(feature, value, mc)

Convert a python value to a raw source value.

Parameters:
  • feature – The feature.

  • value – The value to convert.

  • mc – The model context.

Returns:

The converted value.

raw_to_python(feature, value, mc)

Convert a raw source value to a python value.

Parameters:
  • feature – The feature.

  • value – The value to convert.

  • mc – The model context.

Returns:

The converted value.

related_models()

Return the models related to this field.

Returns:

A list of models, empty for fields that are not related fields.

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

Bases: gws.Props

Object properties.

attributeType: gws.AttributeType
geometryType: gws.GeometryType
name: str
relatedModelUids: list[str]
title: str
type: str
uid: str

Unique ID.

widget: gws.ext.props.modelWidget