gws.base.model.core

Base model class.

Source code: gws.base.model.core

Module Contents

class gws.base.model.core.ClientOptions(*args, **kwargs)

Bases: gws.Data

Client-side options for editing features of the model.

keepFormOpen: bool = False

Keep the edit form open after saving.

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

Bases: gws.ConfigWithAccess

Model configuration

clientOptions: ClientOptions | None

Client-side options for the model.

excludeColumns: list[str] | None

Source columns to skip when creating fields automatically.

exportStrategy: gws.FeatureExportStrategy | None

How features are obtained for export.

fields: list[gws.ext.config.modelField] | None

Model fields.

isEditable: bool = False

Features of this model can be edited.

loadingStrategy: gws.FeatureLoadingStrategy | None

How the client loads features.

sort: list[gws.SortOptions] | None

Default sort order of features.

tableViewColumns: list[TableViewColumn] | None

Columns of the table view.

templates: list[gws.ext.config.template] | None

Templates for rendering features of this model.

title: str = ''

Model title.

withAutoFields: bool = False

Add fields for unconfigured source columns in addition to the configured ones.

withTableView: bool = True

Enable the table view of features in the client.

gws.base.model.core.DEFAULT_GEOMETRY_NAME = 'geometry'
gws.base.model.core.DEFAULT_UID_NAME = 'uid'
class gws.base.model.core.Object

Bases: gws.Model

Base model.

Provides the model configuration, with fields, uid, geometry, sort order and templates, and the props, table view columns, validation and conversion between features and props, delegated to the fields. Subclasses call configure_model from their configure, override the configure_* steps they need and implement access to the source.

configure()

Configuration hook.

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

configure_auto_fields()

Create fields for the source columns.

Creates a field for each column returned by describe, except columns listed in excludeColumns, columns that already have a field, and columns of a type without a default field type.

Returns:

True if the source could be described, False otherwise.

configure_fields()

Create the model fields.

Creates the configured fields. If there are none, or withAutoFields is set, also creates fields for the source columns with configure_auto_fields.

Returns:

True if any fields were created.

configure_geometry()

Set the geometry name, type and CRS from the first geometry field.

Returns:

True if a geometry field was found, None otherwise.

configure_model()

Run the model configuration steps.

Calls the provider, sources, fields, uid, geometry, sort and templates configuration methods in this order.

configure_provider()

Configure the data provider of the model.

The base implementation does nothing.

Returns:

True if a provider was configured.

configure_sort()

Set the default sort order.

Uses the configured sort, otherwise sorts by the uid field, if any.

Returns:

True if a sort order was configured, False otherwise.

configure_sources()

Configure the data sources of the model.

The base implementation does nothing.

Returns:

True if sources were configured.

configure_templates()

Create the configured templates.

Returns:

True if any templates were created.

configure_uid()

Set uidName to the name of the primary key field.

Keeps an already set uidName. Otherwise a name is set only if exactly one field is a primary key.

Returns:

True if uidName is set, None otherwise.

feature_from_props(props, mc)

Create a feature from client props.

Parameters:
  • props – The feature props.

  • mc – The model context.

Returns:

A new feature.

feature_to_props(feature, mc)

Convert a feature to client props and store them in feature.props.

Parameters:
  • feature – The feature.

  • mc – The model context.

Returns:

The feature props.

feature_to_view_props(feature, mc)

Convert a feature to client props for viewing, with a reduced set of attributes.

Parameters:
  • feature – The feature.

  • mc – The model context.

Returns:

The feature props.

field(name)

Return a field by name.

Parameters:

name – The field name.

Returns:

The field, or None if it is not found.

find_features(search, mc)

Find features matching a search query.

Parameters:
  • search – The search query.

  • mc – The model context.

Returns:

The features found.

get_feature(uid, mc)

Return a feature by uid.

Parameters:
  • uid – The feature uid.

  • mc – The model context.

Returns:

The feature, or None if it is not found.

get_features(uids, mc)

Return features by uid.

Parameters:
  • uids – Feature uids.

  • mc – The model context.

Returns:

The features found, empty if no uids are given.

post_configure()

Post-configuration hook.

Called after the whole object tree has been created.

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.

related_models()

Return the models related to the fields of this model.

Returns:

A list of models without duplicates.

table_view_columns(user)

Return the columns of the table view for a user.

Uses the configured tableViewColumns, or all fields otherwise. Fields the user cannot use and fields without a widget that supports the table view are skipped.

Parameters:

user – The user.

Returns:

A list of columns, empty if the table view is disabled.

validate_feature(feature, mc)

Validate a feature and store validation errors in feature.errors.

Parameters:
  • feature – The feature.

  • mc – The model context.

Returns:

True if the feature has no errors.

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

Bases: gws.Props

Object properties.

canCreate: bool
canDelete: bool
canRead: bool
canWrite: bool
clientOptions: gws.ModelClientOptions
fields: list[gws.ext.props.modelField]
geometryCrs: str | None
geometryName: str | None
geometryType: gws.GeometryType | None
isEditable: bool
layerUid: str | None
loadingStrategy: gws.FeatureLoadingStrategy
supportsGeometrySearch: bool
supportsKeywordSearch: bool
tableViewColumns: list[TableViewColumn]
title: str
uid: str

Unique ID.

uidName: str | None
class gws.base.model.core.TableViewColumn(*args, **kwargs)

Bases: gws.Data

Column of the feature table view.

name: str

Name of the model field shown in the column.

width: int | None

Column width in pixels.