diff --git a/CHANGELOG.md b/CHANGELOG.md index 297ade6..e2a29c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v1.3.2 +- [#34](https://github.com/lastorel/pytion/issues/34): `status` Property type added + ## v1.3.1 - [#32](https://github.com/lastorel/pytion/issues/32): Rollback of Page retrieving with properties - [#35](https://github.com/lastorel/pytion/issues/35): Fix PropertyValue with rollup type diff --git a/README.md b/README.md index d6186e4..17e9414 100644 --- a/README.md +++ b/README.md @@ -309,36 +309,37 @@ Extension attributes are listed below in support matrix: ### Supported Property types -| Property type | value type | read (DB) | read value (Page) | create (DB) | create value (Page) | Oper attrs | Config attrs | -|-----------------------|---------------------|-----------|-------------------|-------------|---------------------|------------------------------------|-----------------------------------| -| `title` | `RichTextArray` | + | + | + | + | | | -| `rich_text` | `RichTextArray` | + | + | + | + | | | -| `number` | `int`/`float` | + | + | + | + | | ~~format~~ | -| `select` | `str` | + | + | + | + | | ~~options~~ | -| `multi_select` | `List[str]` | + | + | + | + | | ~~options~~ | -| `status` | | - | - | - | - | | ~~options~~ ~~groups~~ | -| `date` | `str` | + | + | + | + | `start: datetime` `end: datetime`* | | -| `people` | `List[User]` | + | + | + | +** | | | -| `files` | | + | - | + | - | | | -| `checkbox` | `bool` | + | + | + | + | | | -| `url` | `str` | + | + | + | + | | | -| `email` | `str` | + | + | + | + | | | -| `phone_number` | `str` | + | + | + | + | | | -| `formula` | | - | + | - | - | | | -| `relation` | `List[LinkTo]` | + | + | + | + | | `single_property`/`dual_property` | -| `rollup` | depends on relation | - | + | - | - | | | -| `created_time`*** | `datetime` | + | + | + | - | | | -| `created_by`*** | `User` | + | + | + | - | | | -| `last_edited_time`*** | `datetime` | + | + | + | - | | | -| `last_edited_by`*** | `User` | + | + | + | - | | | - -> [*] - Create examples: +| Property type | value type | read (DB) | read value (Page) | create (DB) | create value (Page) | Oper attrs | Config attrs | +|--------------------------|---------------------|-----------|-------------------|-------------|---------------------|-------------------------------------|-----------------------------------| +| `title` | `RichTextArray` | + | + | + | + | | | +| `rich_text` | `RichTextArray` | + | + | + | + | | | +| `number` | `int`/`float` | + | + | + | + | | ~~format~~ | +| `select` | `str` | + | + | + | + | | ~~options~~ | +| `multi_select` | `List[str]` | + | + | + | + | | ~~options~~ | +| `status` | `str` | + | + | + | +\*\*\*\* | | `options`, `groups` (read-only) | +| `date` | `str` | + | + | + | + | `start: datetime` `end: datetime`\* | | +| `people` | `List[User]` | + | + | + | +\*\* | | | +| `files` | | + | - | + | - | | | +| `checkbox` | `bool` | + | + | + | + | | | +| `url` | `str` | + | + | + | + | | | +| `email` | `str` | + | + | + | + | | | +| `phone_number` | `str` | + | + | + | + | | | +| `formula` | | - | + | - | - | | | +| `relation` | `List[LinkTo]` | + | + | + | + | | `single_property`/`dual_property` | +| `rollup` | depends on relation | - | + | - | - | | | +| `created_time`\*\*\* | `datetime` | + | + | + | - | | | +| `created_by`\*\*\* | `User` | + | + | + | - | | | +| `last_edited_time`\*\*\* | `datetime` | + | + | + | - | | | +| `last_edited_by`\*\*\* | `User` | + | + | + | - | | | + +> [\*] - Create examples: > `pv = PropertyValue.create(type_="date", value=datetime.now())` > `pv = PropertyValue.create(type_="date", date={"start": str(datetime(2022, 2, 1, 5)), "end": str(datetime.now())})` -> [**] - Create example: +> [\*\*] - Create example: > `user = User.create('1d393ffb5efd4d09adfc2cb6738e4812')` > `pv = PropertyValue.create(type_="people", value=[user])` -> [***] - Every Base model like Page already has mandatory attributes created/last_edited returned by API +> [\*\*\*] - Every Base model like Page already has mandatory attributes created/last_edited returned by API +> [\*\*\*\*] - Status type is not configurable. API doesn't support NEW options added via Property modify or updating a Page ### Block creating examples diff --git a/pytion/models.py b/pytion/models.py index d9c95d8..180fc10 100644 --- a/pytion/models.py +++ b/pytion/models.py @@ -232,6 +232,11 @@ def __init__(self, data: Dict[str, Any]): self.relation_property_id = data[self.type][self.subtype].get("synced_property_id") self.relation_property_name = data[self.type][self.subtype].get("synced_property_name") + if self.type == "status": + if isinstance(data[self.type], dict): + self.options = data[self.type].get("options", []) + self.groups = data[self.type].get("groups", []) + def __str__(self): return self.name if self.name else self.type @@ -251,6 +256,13 @@ def get(self) -> Optional[Dict[str, Dict]]: # create relation type property with configuration if self.type == "relation": data[self.type] = {self.subtype: {}, "database_id": self.relation.id} + elif self.type == "status": + data[self.type] = {} + # not configurable + # if self.options: + # data[self.type]["options"] = self.options + # if self.groups: + # data[self.type]["groups"] = self.groups else: data[self.type] = {} return data @@ -259,6 +271,7 @@ def get(self) -> Optional[Dict[str, Dict]]: def create(cls, type_: Optional[str] = "", **kwargs): """ Property Schema Object (watch docs) + :param type_: see "create (DB)" column in "Supported Property types" matrix of README + addons: set type_ = `None` to delete this Property @@ -272,6 +285,8 @@ def create(cls, type_: Optional[str] = "", **kwargs): if type_ == "relation": subtype = next(kwarg for kwarg in kwargs if kwarg in ("single_property", "dual_property")) kwargs["relation"] = {"type": subtype, subtype: {}, "database_id": kwargs[subtype]} + elif type_ == "status": + kwargs["status"] = {} return cls({"type": type_, **kwargs}) @@ -359,6 +374,9 @@ def __init__(self, data: Dict, name: str, **kwargs): for item in data[self.type] ] + if self.type == "status": + self.value = data[self.type].get("name") if isinstance(data[self.type], dict) else data[self.type] + if self.type == "rollup": rollup_type = data["rollup"]["type"] if rollup_type == "array": @@ -450,6 +468,10 @@ def get(self): if self.type == "relation": return {self.type: [{"id": lt.id} for lt in self.value]} + # status type + if self.type == "status": + return {self.type: {"name": self.value}} + # unsupported types: if self.type in ["files"]: return {self.type: []} diff --git a/setup.py b/setup.py index 0c963af..e57d702 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pytion", - version="1.3.1", + version="1.3.2", author="Yegor Gomzin", author_email="slezycmex@mail.ru", description="Unofficial Python client for official Notion API", @@ -20,6 +20,7 @@ "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", ], diff --git a/tests/test_models.py b/tests/test_models.py index 2da8e6f..a693e78 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -43,3 +43,22 @@ def test_create__relation_dual(self): assert isinstance(p.relation, LinkTo) assert p.relation.uri == "databases" assert p.subtype == "dual_property" + + def test_create__status(self): + p = Property.create("status") + p_dict = p.get() + assert p.id is None + assert p.type == "status" + assert p.to_delete is False + assert isinstance(p.options, list) + assert isinstance(p.groups, list) + assert bool(p_dict["status"]) is False + + +class TestPropertyValue: + def test_create__status(self): + p = PropertyValue.create("status", value="Done") + p_dict = p.get() + assert p.id is None + assert p.type == "status" + assert p_dict["status"]["name"] == "Done"