From 934180ef261cbd2c6575baa1623881d7eeb09260 Mon Sep 17 00:00:00 2001 From: teplyakov <teolyakov@perx.ru> Date: Wed, 19 Feb 2025 16:27:04 +0300 Subject: [PATCH 1/3] feat: AUTO-3805 CollectionProps type --- perxis/collections/helpers.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/perxis/collections/helpers.py b/perxis/collections/helpers.py index 44c99f8..28a74e4 100644 --- a/perxis/collections/helpers.py +++ b/perxis/collections/helpers.py @@ -1,5 +1,5 @@ from perxis.collections import collections_pb2 -from typing import TypedDict +from dataclasses import dataclass, asdict from typing_extensions import deprecated @@ -22,11 +22,18 @@ def make_collection_instances( return collections -class CollectionProps(TypedDict): - single: bool - system: bool - no_data: bool - hidden: bool +@dataclass +class CollectionProps: + single: bool = False + system: bool = False + no_data: bool = False + hidden: bool = False + no_revisions: bool = False + no_archive: bool = False + no_publish: bool = False + + def to_dict(self) -> dict: + return asdict(self) # noqa def init_collections( @@ -41,7 +48,7 @@ def init_collections( collection_schema = file.read() kwargs = { - **(collections_settings_mapping.get(collection_id) or {}), + **(collections_settings_mapping.get(collection_id).to_dict()), "id": collection_id, "name": collection_name, "schema": collection_schema, -- GitLab From 691fd67dd0a66c0424aa8be837af72e093c40d7a Mon Sep 17 00:00:00 2001 From: teplyakov <teolyakov@perx.ru> Date: Wed, 19 Feb 2025 16:27:48 +0300 Subject: [PATCH 2/3] feat: AUTO-3805 CollectionProps type --- perxis/collections/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perxis/collections/helpers.py b/perxis/collections/helpers.py index 28a74e4..0a0d66f 100644 --- a/perxis/collections/helpers.py +++ b/perxis/collections/helpers.py @@ -48,7 +48,7 @@ def init_collections( collection_schema = file.read() kwargs = { - **(collections_settings_mapping.get(collection_id).to_dict()), + **collections_settings_mapping.get(collection_id).to_dict(), "id": collection_id, "name": collection_name, "schema": collection_schema, -- GitLab From 4fc4d5593fb74ff1c9e374fcd3554621eaccf241 Mon Sep 17 00:00:00 2001 From: teplyakov <teolyakov@perx.ru> Date: Wed, 19 Feb 2025 16:34:37 +0300 Subject: [PATCH 3/3] feat: AUTO-3805 Add isinstance check --- perxis/collections/helpers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/perxis/collections/helpers.py b/perxis/collections/helpers.py index 0a0d66f..d4215d6 100644 --- a/perxis/collections/helpers.py +++ b/perxis/collections/helpers.py @@ -47,8 +47,13 @@ def init_collections( with open(f"{schemes_dir}/{collection_id}.json", "r") as file: collection_schema = file.read() + props = collections_settings_mapping.get(collection_id) or CollectionProps() + + if not isinstance(props, CollectionProps): + raise TypeError("collections_settings_mapping value must be an instance of CollectionProps") + kwargs = { - **collections_settings_mapping.get(collection_id).to_dict(), + **props.to_dict(), "id": collection_id, "name": collection_name, "schema": collection_schema, -- GitLab