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.DataClient-side options for editing features of the model.
- class gws.base.model.core.Config(*args, **kwargs)¶
Bases:
gws.ConfigWithAccessModel configuration
- clientOptions: ClientOptions | None¶
Client-side options for the model.
- exportStrategy: gws.FeatureExportStrategy | None¶
How features are obtained for export.
- fields: list[gws.ext.config.modelField] | None¶
Model fields.
- 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.
- gws.base.model.core.DEFAULT_GEOMETRY_NAME = 'geometry'¶
- gws.base.model.core.DEFAULT_UID_NAME = 'uid'¶
- class gws.base.model.core.Object¶
Bases:
gws.ModelBase 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_modelfrom theirconfigure, override theconfigure_*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 inexcludeColumns, 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, orwithAutoFieldsis set, also creates fields for the source columns withconfigure_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
uidNameto 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
uidNameis 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
Propsstruct for this object.Do not call this method directly, use
gws.props_ofinstead, which also checks permissions.- Parameters:
user – The user for which the props should be generated.
- Returns:
A
Propsobject or a dict. Nested objects are converted to props as well.
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.PropsObject properties.
- clientOptions: gws.ModelClientOptions¶
- fields: list[gws.ext.props.modelField]¶
- geometryType: gws.GeometryType | None¶
- loadingStrategy: gws.FeatureLoadingStrategy¶
- tableViewColumns: list[TableViewColumn]¶