gws.plugin.qfieldcloud.action_handler

QField Cloud API request handler.

Source code: gws.plugin.qfieldcloud.action_handler

Module Contents

class gws.plugin.qfieldcloud.action_handler.Handler(action: gws.plugin.qfieldcloud.action_base.BaseAction)

Handler for a single QFieldCloud API request.

Finds the route for the request, authenticates the user and calls the route method. The handler holds the state of the request only, persistent data is accessed via action.

action: gws.plugin.qfieldcloud.action_base.BaseAction

The action that received the request.

apiRoute: str

Request method and path.

auth: Handler.auth

user, session and token.

Type:

Authentication result

params: gws.Request

Command request.

parts: dict

Variables from the path.

post: dict

POST payload.

project: gws.Project | None

GWS Project context.

qfcProject: gws.plugin.qfieldcloud.core.QfcProject

QField Cloud Project context.

qs: dict

Query string parameters.

req: gws.WebRequester

The original web request.

create_package_job() → gws.Job

Create and schedule a packaging job for the QField project of the request.

Returns:

The scheduled job.

delta_db() → gws.lib.sqlitex.Object

Return the delta database of the request’s QField project.

Returns:

Database wrapper.

handle(req: gws.WebRequester, params: gws.Request) → gws.ContentResponse

Find the route method for a request and call it.

The path can start with projectUid/<uid> to set the GWS project. If the action belongs to a project, that project is used instead.

Parameters:
  • req – Web requester.

  • params – Command request.

Returns:

The response.

Raises:
on_get_auth_providers() → list[gws.plugin.qfieldcloud.api.AuthProvider]

Return the authentication providers.

Returns:

A single username and password provider.

on_get_auth_user() → gws.plugin.qfieldcloud.api.CompleteUser

Return the authenticated user.

Returns:

User information.

on_get_deltas() → gws.ContentResponse

Return the deltas the user has sent for a QField project, newest first.

The list is paged by the limit and offset query parameters. If there are more deltas, the response has an X-Next-Page header. The ordering parameter is ignored.

Returns:

Delta statuses as JSON.

Raises:
on_get_deltas_in_payload() → list[gws.plugin.qfieldcloud.core.DeltaStatus]

Return the status of the deltas of a payload.

Returns:

Delta statuses.

Raises:
on_get_files() → list[gws.plugin.qfieldcloud.api.PackageFile]

Return the files of the latest package.

Returns:

Package files.

Raises:

gws.NotFoundError – If the QField project is not found.

on_get_jobs()

List jobs. Not supported.

Raises:

gws.BadRequestError – Always.

on_get_jobs_id() → gws.plugin.qfieldcloud.api.Job

Return a job.

Returns:

Job.

Raises:

gws.NotFoundError – If the job is not found.

on_get_package() → gws.plugin.qfieldcloud.api.Package

Return the latest package of a QField project.

Returns:

Package with its files. The package version is ignored.

Raises:

gws.NotFoundError – If the QField project is not found.

on_get_package_file() → gws.ContentResponse

Return a file from the latest package.

Returns:

File content. A request with a Range header gets status 416, so that QField downloads the full file.

Raises:
on_get_projects() → list[gws.plugin.qfieldcloud.api.Project]

Return the QField projects the user can use.

Returns:

Projects, paged by the limit and offset query parameters.

on_get_projects_id() → gws.plugin.qfieldcloud.api.Project

Return a QField project.

Returns:

Project.

Raises:

gws.NotFoundError – If the QField project is not found.

on_get_server_info() → gws.plugin.qfieldcloud.api.ServerInfo

Return the server information.

Returns:

Server information.

on_get_status() → gws.plugin.qfieldcloud.api.Status

Return the server status.

Returns:

Server status, always ok.

on_get_subscription() → gws.plugin.qfieldcloud.api.Subscription

Return the subscription of a user.

Returns:

A dummy active subscription.

on_get_thumbnail() → gws.ContentResponse

Return the thumbnail of a QField project.

Returns:

Thumbnail image.

Raises:
on_get_user_organizations() → list

Return the organizations of a user.

Returns:

An empty list, organizations are not supported.

on_post_auth_logout()

Log out, deleting the session.

on_post_auth_token() → gws.plugin.qfieldcloud.api.AuthToken

Log in with username and password and create a session.

Returns:

Session token and user information.

Raises:

gws.AuthenticationError – If the credentials are invalid.

on_post_deltas()

Store a delta payload and apply its changes.

The payload is uploaded as a multipart file. Deltas are identified by their content, so a delta pushed again unchanged, also under another payload id, is not applied again. The deltas that are new, or failed before, or have been pending for longer than delta.PENDING_TIMEOUT, are applied all together or not at all.

Raises:
on_post_file() → gws.ContentResponse

Apply a file upload.

Returns:

An empty response with status 201.

Raises:
on_post_jobs() → gws.plugin.qfieldcloud.api.Job

Create a job. Only package jobs are supported.

Returns:

The scheduled job.

Raises:
on_post_projects()

Create a project. Not supported.

Raises:

gws.BadRequestError – Always.

set_qfc_project(uid: str)

Set the QField project of the request.

Parameters:

uid – QField project uid.

Raises:

gws.NotFoundError – If the project is not found or the user cannot use it.

set_qfc_project_from_parts()

Set the QField project of the request from the project_id path variable.

Raises:

gws.NotFoundError – If the project is not found or the user cannot use it.

gws.plugin.qfieldcloud.action_handler.route(pattern: str)

Decorator that marks a method as an API route handler.

Parameters:

pattern – Regular expression matched against "<METHOD> <path>". Named groups are passed to the handler in Handler.parts.

Returns:

The decorator.