gws.base.storage.core

Storage object.

Source code: gws.base.storage.core

Module Contents

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

Bases: gws.ConfigWithAccess

Storage for entries saved by users.

categoryName: str | None

Category under which entries are stored in the provider.

providerUid: str | None

UID of the storage provider.

class gws.base.storage.core.Object

Bases: gws.Node

Storage object, gives users access to entries of one category in a storage provider.

categoryName: str

Category under which entries are stored.

storageProvider: gws.StorageProvider

Storage provider.

configure()

Configuration hook.

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

configure_provider()

Find the storage provider by providerUid, or use the first provider.

Returns:

True.

Raises:

gws.Error – If no provider is found.

get_state_for(user)

Return the storage state for a user.

Parameters:

user – The user.

Returns:

The entry names, if the user can read them, and the user’s permissions.

handle_request(req: gws.WebRequester, p: Request) → Response

Handle a storage request from the client.

Writing an existing entry requires the write permission, writing a new one requires create. Entry data is stored as JSON.

Parameters:
  • req – Web requester.

  • p – Storage request.

Returns:

The entry data for a read request, and the new storage state.

Raises:

gws.ForbiddenError – If the user lacks the permission or the entry name or data is missing.

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.

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

Bases: gws.Props

Object properties.

state: State
class gws.base.storage.core.Request(*args, **kwargs)

Bases: gws.Request

Storage request.

entryData: dict | None

Entry data to write.

entryName: str | None

Entry name, required for read, write and delete.

verb: Verb

Action to perform.

class gws.base.storage.core.Response(*args, **kwargs)

Bases: gws.Response

Storage response.

data: dict | None

Entry data for a read request.

state: State

Storage state after the request.

class gws.base.storage.core.State(*args, **kwargs)

Bases: gws.Data

Storage state.

canCreate: bool

User can create entries.

canDelete: bool

User can delete entries.

canRead: bool

User can read entries.

canWrite: bool

User can write entries.

names: list[str]

List of entry names.

class gws.base.storage.core.Verb

Bases: gws.Enum

Storage action verbs.

delete = 'delete'

Delete an entry.

list = 'list'

List entries.

read = 'read'

Read an entry.

write = 'write'

Write an entry.