gws.base.edit.helper

Edit helper.

Source code: gws.base.edit.helper

Module Contents

gws.base.edit.helper.DEFAULT_TOLERANCE

Search tolerance for feature searches.

gws.base.edit.helper.LIST_VIEWS = ['title', 'label']

Feature views rendered for feature lists.

class gws.base.edit.helper.Object

Bases: gws.Node

Edit helper.

Implements the edit API. For each command there is a method that does the work and returns models or features, and a method that converts the result into the API response. Other actions can call or override these methods separately.

delete_feature(req: gws.WebRequester, p: gws.base.edit.api.DeleteFeatureRequest) → gws.Feature | None

Delete a feature.

Parameters:
  • req – Web request.

  • p – Request parameters.

Returns:

The deleted feature.

Raises:
delete_feature_response(req: gws.WebRequester, p: gws.base.edit.api.DeleteFeatureRequest, feature: gws.Feature | None) → gws.base.edit.api.DeleteFeatureResponse

Create the response for editDeleteFeature.

Parameters:
  • req – Web request.

  • p – Request parameters.

  • feature – Deleted feature.

Returns:

An empty response.

feature_from_props(props: gws.FeatureProps, access: gws.Access, mc: gws.ModelContext) → gws.Feature

Create a feature from props sent by the client.

Parameters:
  • props – Feature props, with modelUid set.

  • access – Required access to the model.

  • mc – Model context.

Returns:

The feature.

Raises:
feature_list_to_props(features: list[gws.Feature], mc: gws.ModelContext) → list[gws.FeatureProps]

Convert features to props for the client.

Renders the list views (title, label) of the features and their related features and transforms them to the project map CRS.

Parameters:
  • features – Features to convert.

  • mc – Model context.

Returns:

A list of feature props.

feature_to_props(feature: gws.Feature, mc: gws.ModelContext) → gws.FeatureProps

Convert a single feature to props for the client.

Parameters:
  • feature – Feature to convert.

  • mc – Model context.

Returns:

The feature props.

get_feature(req: gws.WebRequester, p: gws.base.edit.api.GetFeatureRequest) → gws.Feature | None

Return a single feature for the edit form.

Parameters:
  • req – Web request.

  • p – Request parameters.

Returns:

The feature, or None if it does not exist.

Raises:

gws.ForbiddenError – If the model is not accessible or not editable.

get_feature_response(req: gws.WebRequester, p: gws.Request, feature: gws.Feature | None) → gws.base.edit.api.GetFeatureResponse

Create the response for editGetFeature.

Parameters:
  • req – Web request.

  • p – Request parameters, used for the project uid.

  • feature – Feature to return.

Returns:

The response with the feature props.

Raises:

gws.NotFoundError – If feature is None.

get_features(req: gws.WebRequester, p: gws.base.edit.api.GetFeaturesRequest) → list[gws.Feature]

Search features in the requested models.

The search is filtered by the extent, shapes, keyword and feature uids in the request.

Parameters:
  • req – Web request.

  • p – Request parameters.

Returns:

The found features, or an empty list if an extent is given without a CRS and the project has no map.

Raises:

gws.ForbiddenError – If a model is not accessible or not editable.

get_features_response(req: gws.WebRequester, p: gws.Request, features: list[gws.Feature]) → gws.base.edit.api.GetFeaturesResponse

Create the response for editGetFeatures.

Parameters:
  • req – Web request.

  • p – Request parameters, used for the project uid.

  • features – Features to return.

Returns:

The response with the feature props.

get_models(req: gws.WebRequester, p: gws.base.edit.api.GetModelsRequest) → list[gws.Model]

Return the editable models of the requested project.

Parameters:
  • req – Web request.

  • p – Request parameters.

Returns:

Models the user can edit, sorted by title.

Raises:
get_models_response(req: gws.WebRequester, p: gws.Request, models: list[gws.Model]) → gws.base.edit.api.GetModelsResponse

Create the response for editGetModels.

Parameters:
  • req – Web request.

  • p – Request parameters, used for the project uid.

  • models – Models to return.

Returns:

The response with the model props.

get_relatable_features(req: gws.WebRequester, p: gws.base.edit.api.GetRelatableFeaturesRequest) → list[gws.Feature]

Return features that can be linked in a related field.

Parameters:
  • req – Web request.

  • p – Request parameters.

Returns:

Features found by the field for the request keyword.

Raises:

gws.ForbiddenError – If the model or the field is not accessible.

get_relatable_features_response(req: gws.WebRequester, p: gws.Request, features: list[gws.Feature]) → gws.base.edit.api.GetRelatableFeaturesResponse

Create the response for editGetRelatableFeatures.

Parameters:
  • req – Web request.

  • p – Request parameters, used for the project uid.

  • features – Features to return.

Returns:

The response with the feature props.

init_feature(req: gws.WebRequester, p: gws.base.edit.api.InitFeatureRequest) → gws.Feature

Create a new feature with initial values, without saving it.

The related features in createWithFeatures are attached to the new feature.

Parameters:
  • req – Web request.

  • p – Request parameters.

Returns:

The new feature.

Raises:
init_feature_response(req: gws.WebRequester, p: gws.Request, feature: gws.Feature | None) → gws.base.edit.api.InitFeatureResponse

Create the response for editInitFeature.

Parameters:
  • req – Web request.

  • p – Request parameters, used for the project uid.

  • feature – Feature to return.

Returns:

The response with the feature props.

Raises:

gws.NotFoundError – If feature is None.

model_context(req: gws.WebRequester, p: gws.Request, op, target: gws.ModelReadTarget | None = None, max_depth=1)

Create a model context for a request.

Parameters:
  • req – Web request.

  • p – Request parameters, used for the project uid.

  • op – Model operation.

  • target – Read target.

  • max_depth – Maximum depth of related features to process.

Returns:

The model context.

Raises:
require_field(model: gws.Model, field_name: str, user: gws.User, access: gws.Access) → gws.ModelField

Return a model field the user can access.

Parameters:
  • model – Model.

  • field_name – Field name.

  • user – User.

  • access – Required access.

Returns:

The field.

Raises:

gws.ForbiddenError – If the field does not exist or is not accessible.

require_model(model_uid, user: gws.User, access: gws.Access) → gws.Model

Return an editable model the user can access.

Parameters:
  • model_uid – Model uid.

  • user – User.

  • access – Required access.

Returns:

The model.

Raises:

gws.ForbiddenError – If the model does not exist, is not accessible or is not editable.

write_feature(req: gws.WebRequester, p: gws.base.edit.api.WriteFeatureRequest) → gws.Feature | None

Validate and save a new or existing feature.

New features (isNew) are created, others are updated. After saving, the feature is read back from the model.

Parameters:
  • req – Web request.

  • p – Request parameters.

Returns:

The saved feature as read back, the unsaved feature with errors set if the validation fails, or None if the saved feature cannot be read back.

Raises:
write_feature_response(req: gws.WebRequester, p: gws.base.edit.api.WriteFeatureRequest, feature: gws.Feature | None) → gws.base.edit.api.WriteFeatureResponse

Create the response for editWriteFeature.

Parameters:
  • req – Web request.

  • p – Request parameters, used for the project uid.

  • feature – Saved feature, or a feature with validation errors.

Returns:

The response with the feature props, or with the validation errors only.

Raises:

gws.NotFoundError – If feature is None.