gws.plugin.qfieldcloud.patcher¶
Applies changes and file uploads from QField to the database.
Source code: gws.plugin.qfieldcloud.patcher
Module Contents¶
- class gws.plugin.qfieldcloud.patcher.Args¶
Bases:
gws.DataArguments for the patcher.
- caps: gws.plugin.qfieldcloud.caps.Caps¶
Capabilities of the QField project.
- db: gws.DatabaseProvider¶
Database provider of the models, used for the transaction.
- project: gws.Project | None¶
GWS project context.
- qfcProject: gws.plugin.qfieldcloud.core.QfcProject¶
QField project.
- class gws.plugin.qfieldcloud.patcher.Change¶
Bases:
gws.DataA single change, extracted from a QField delta.
- newAtts: dict¶
New attribute values.
- oldAtts: dict¶
Old attribute values, used to find the primary key of updated and deleted features.
- type: ChangeType¶
Change type.
- class gws.plugin.qfieldcloud.patcher.ChangeType¶
Bases:
gws.EnumType of a change, as in the delta
method.- create = 'create'¶
Create a new feature.
- delete = 'delete'¶
Delete a feature.
- patch = 'patch'¶
Update an existing feature.
- class gws.plugin.qfieldcloud.patcher.Object¶
Patcher, applies changes and file uploads from QField.
Changes are converted to model operations, grouped by model, and passed to the model methods
create_feature,update_featureanddelete_feature. All changes are applied in one transaction: if any change fails, including changes for unknown or non-editable layers and updates or deletions of features that do not exist, nothing is written.- caps: gws.plugin.qfieldcloud.caps.Caps¶
Capabilities of the QField project.
- project: gws.Project | None¶
GWS project context.
- qfcProject: gws.plugin.qfieldcloud.core.QfcProject¶
QField project.
- apply_changes(root: gws.Root, args: Args) bool¶
Apply the changes in
args.changes.The changes are applied in one transaction, which is rolled back if any change fails. All models must use the database provider
args.db.- Parameters:
root – Root object.
args – Patcher arguments.
- Returns:
Trueif any operations were committed,Falseif there was nothing to apply.- Raises:
gws.Error – If a change refers to an unknown layer or a missing feature. Database errors are raised as is.
- apply_upload(root: gws.Root, args: Args) bool¶
Apply the file upload in
args.filePathandargs.fileContent.- Parameters:
root – Root object.
args – Patcher arguments.
- Returns:
Trueif a feature for the file was found and updated.
- commit_upload(path: str, content: bytes) bool¶
Write uploaded file content into the first feature that refers to the file.
- Parameters:
path – File path, as sent by QField.
content – File content.
- Returns:
Trueif a feature was found and updated.
- commit_upload_for_model(me: gws.plugin.qfieldcloud.caps.ModelEntry, path: str, content: bytes) bool¶
Write uploaded file content into a feature of a model.
Looks for a file field with a
nameColumnwhose value equals the path, and writes the content into the field’scontentColumn.- Parameters:
me – Model entry.
path – File path, as sent by QField.
content – File content.
- Returns:
Trueif a feature was found and updated.
- find_uid_for_path(me: gws.plugin.qfieldcloud.caps.ModelEntry, ff: gws.plugin.model_field.file.Object, path: str, mc: gws.ModelContext) str | None¶
Find the feature whose file name column equals the path.
- Parameters:
me – Model entry.
ff – File field.
path – File path, as sent by QField.
mc – Model context.
- Returns:
Primary key of the feature, or
Noneif not found.
- get_feature(me: gws.plugin.qfieldcloud.caps.ModelEntry, pk: str) gws.Feature | None¶
Read a feature by its primary key.
- Parameters:
me – Model entry.
pk – Primary key.
- Returns:
The feature, or
Noneif not found.
- perform_operations_for_model(me: gws.plugin.qfieldcloud.caps.ModelEntry, ops: list[Operation])¶
Perform operations for a model, in the transaction opened by
apply_changes.- Parameters:
me – Model entry.
ops – Operations to perform.
- prepare_change(cc: Change)¶
Convert a change to an operation and add it to
ops_by_model.The
fid_gwsattribute is renamed back tofid(see the packager). For creations, an automatic primary key is removed from the attributes.- Parameters:
cc – Change.
- Raises:
gws.Error – If the layer is not found or not editable, the geometry field is not found, or the feature to update or delete does not exist.
- class gws.plugin.qfieldcloud.patcher.Operation¶
Bases:
gws.DataA model operation to be committed.
- feature: gws.Feature¶
Feature to create, update or delete.
- type: gws.ModelOperation¶
Operation type.