diff --git a/pyodk/_endpoints/bases.py b/pyodk/_endpoints/bases.py index 126debc..cbefc84 100644 --- a/pyodk/_endpoints/bases.py +++ b/pyodk/_endpoints/bases.py @@ -1,4 +1,4 @@ -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict from pyodk._utils.session import Session @@ -6,9 +6,16 @@ class Model(BaseModel): """Base configuration for data model classes.""" - class Config: - arbitrary_types_allowed = True - validate_assignment = True + model_config = ConfigDict(arbitrary_types_allowed=True, validate_assignment=True) + + +class FrozenModel(Model): + """Make the base configuration model faux-immutable. + + NOTE in pydantic v2 inherited model_config are *merged*. + """ + + model_config = ConfigDict(frozen=True) class Manager: diff --git a/pyodk/_endpoints/comments.py b/pyodk/_endpoints/comments.py index adada4a..4224a57 100644 --- a/pyodk/_endpoints/comments.py +++ b/pyodk/_endpoints/comments.py @@ -15,10 +15,7 @@ class Comment(bases.Model): createdAt: datetime -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): list: str = "projects/{project_id}/forms/{form_id}/submissions/{instance_id}/comments" post: str = "projects/{project_id}/forms/{form_id}/submissions/{instance_id}/comments" diff --git a/pyodk/_endpoints/entities.py b/pyodk/_endpoints/entities.py index 35b7640..cbe67cf 100644 --- a/pyodk/_endpoints/entities.py +++ b/pyodk/_endpoints/entities.py @@ -65,10 +65,7 @@ class Entity(bases.Model): deletedAt: datetime | None = None -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): _entity_name: str = "projects/{project_id}/datasets/{el_name}" _entities: str = f"{_entity_name}/entities" list: str = _entities diff --git a/pyodk/_endpoints/entity_list_properties.py b/pyodk/_endpoints/entity_list_properties.py index 09032fc..bfe65aa 100644 --- a/pyodk/_endpoints/entity_list_properties.py +++ b/pyodk/_endpoints/entity_list_properties.py @@ -16,10 +16,7 @@ class EntityListProperty(bases.Model): forms: list[str] -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): post: str = "projects/{project_id}/datasets/{entity_list_name}/properties" diff --git a/pyodk/_endpoints/entity_lists.py b/pyodk/_endpoints/entity_lists.py index ee478c9..9c58f7d 100644 --- a/pyodk/_endpoints/entity_lists.py +++ b/pyodk/_endpoints/entity_lists.py @@ -22,10 +22,7 @@ class EntityList(bases.Model): properties: list[EntityListProperty] | None = None -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): _entity_list = "projects/{project_id}/datasets" list: str = _entity_list post: str = _entity_list diff --git a/pyodk/_endpoints/form_assignments.py b/pyodk/_endpoints/form_assignments.py index 7bb802f..0ef0c59 100644 --- a/pyodk/_endpoints/form_assignments.py +++ b/pyodk/_endpoints/form_assignments.py @@ -8,10 +8,7 @@ log = logging.getLogger(__name__) -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): _form: str = "projects/{project_id}/forms/{form_id}" post: str = f"{_form}/assignments/{{role_id}}/{{user_id}}" diff --git a/pyodk/_endpoints/form_draft_attachments.py b/pyodk/_endpoints/form_draft_attachments.py index cc6ae9a..f6e650d 100644 --- a/pyodk/_endpoints/form_draft_attachments.py +++ b/pyodk/_endpoints/form_draft_attachments.py @@ -9,10 +9,7 @@ log = logging.getLogger(__name__) -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): _form: str = "projects/{project_id}/forms/{form_id}" post: str = f"{_form}/draft/attachments/{{fname}}" diff --git a/pyodk/_endpoints/form_drafts.py b/pyodk/_endpoints/form_drafts.py index 2d918dd..b1ddf46 100644 --- a/pyodk/_endpoints/form_drafts.py +++ b/pyodk/_endpoints/form_drafts.py @@ -81,10 +81,7 @@ def get_definition_data( return definition_data, content_type, file_path_stem -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): _form: str = "projects/{project_id}/forms/{form_id}" post: str = f"{_form}/draft" post_publish: str = f"{_form}/draft/publish" diff --git a/pyodk/_endpoints/forms.py b/pyodk/_endpoints/forms.py index 98eedb0..e351725 100644 --- a/pyodk/_endpoints/forms.py +++ b/pyodk/_endpoints/forms.py @@ -31,10 +31,7 @@ class Form(bases.Model): publishedAt: datetime | None -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): forms: str = "projects/{project_id}/forms" get: str = f"{forms}/{{form_id}}" diff --git a/pyodk/_endpoints/project_app_users.py b/pyodk/_endpoints/project_app_users.py index 025bbed..1e20ae4 100644 --- a/pyodk/_endpoints/project_app_users.py +++ b/pyodk/_endpoints/project_app_users.py @@ -20,10 +20,7 @@ class ProjectAppUser(bases.Model): deletedAt: datetime | None -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): list: str = "projects/{project_id}/app-users" post: str = "projects/{project_id}/app-users" diff --git a/pyodk/_endpoints/projects.py b/pyodk/_endpoints/projects.py index f390d2d..50f3a74 100644 --- a/pyodk/_endpoints/projects.py +++ b/pyodk/_endpoints/projects.py @@ -27,10 +27,7 @@ class Project(bases.Model): deletedAt: datetime | None = None -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): list: str = "projects" get: str = "projects/{project_id}" get_data: str = "projects/{project_id}/forms/{form_id}.svc/{table_name}" diff --git a/pyodk/_endpoints/submissions.py b/pyodk/_endpoints/submissions.py index c59e74b..3ec4609 100644 --- a/pyodk/_endpoints/submissions.py +++ b/pyodk/_endpoints/submissions.py @@ -24,10 +24,7 @@ class Submission(bases.Model): updatedAt: datetime | None = None -class URLs(bases.Model): - class Config: - frozen = True - +class URLs(bases.FrozenModel): _form: str = "projects/{project_id}/forms/{form_id}" list: str = f"{_form}/submissions" get: str = f"{_form}/submissions/{{instance_id}}"