Skip to content

Commit

Permalink
chg: entities.update optional label and data params, update readme
Browse files Browse the repository at this point in the history
- chg: label or data (or both/neither) are allowed for entities.update
- add: readme section on default identifiers
  • Loading branch information
lindsay-stevens committed May 4, 2024
1 parent 321d0f4 commit c1bac20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ The `Client` is not specific to a project, but a default `project_id` can be set
- An init argument: `Client(project_id=1)`.
- A property on the client: `client.project_id = 1`.

*Default Identifiers*

For each endpoint, a default can be set for key identifiers, so these identifiers are optional in most methods. When the identifier is required, validation ensures that either a default value is set, or a value is specified. E.g.

```python
client.projects.default_project_id = 1
client.forms.default_form_id = "my_form"
client.submissions.default_form_id = "my_form"
client.entities.default_entity_list_name = "my_list"
client.entities.default_project_id = 1
```

### Session cache file

The session cache file uses the TOML format. The default file name is `.pyodk_cache.toml`, and the default location is the user home directory. The file name and location can be customised by setting the environment variable `PYODK_CACHE_FILE` to some other file path, or by passing the path at init with `Client(config_path="my_cache.toml")`. This file should not be pre-created as it is used to store a session token after login.
Expand Down
19 changes: 10 additions & 9 deletions pyodk/_endpoints/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,20 @@ def create(

def update(
self,
label: str,
data: dict,
uuid: str,
force: bool | None = None,
base_version: int | None = None,
entity_list_name: str | None = None,
project_id: int | None = None,
label: str | None = None,
data: dict | None = None,
force: bool | None = None,
base_version: int | None = None,
) -> Entity:
"""
Update an Entity.
:param uuid: The unique identifier for the Entity.
:param label: Label of the Entity.
:param data: Data to store for the Entity.
:param uuid: The unique identifier for the Entity.
:param force: If True, update an Entity regardless of its current state. If
`base_version` is not specified, then `force` must be True.
:param base_version: The expected current version of the Entity on the server. If
Expand All @@ -181,10 +181,11 @@ def update(
params["baseVersion"] = pv.validate_int(base_version, key="base_version")
if len([i for i in (force, base_version) if i is not None]) != 1:
raise PyODKError("Must specify one of 'force' or 'base_version'.") # noqa: TRY301
req_data = {
"label": pv.validate_str(label, key="label"),
"data": pv.validate_dict(data, key="data"),
}
req_data = {}
if label is not None:
req_data["label"] = pv.validate_str(label, key="label")
if data is not None:
req_data["data"] = pv.validate_dict(data, key="data")
except PyODKError as err:
log.error(err, exc_info=True)
raise
Expand Down

0 comments on commit c1bac20

Please sign in to comment.