From eb983d15a02e19ba95e0fb7608b3fb9769fa1390 Mon Sep 17 00:00:00 2001 From: lastorel Date: Tue, 27 Sep 2022 00:44:48 +0300 Subject: [PATCH] fix #32 --- CHANGELOG.md | 3 +++ README.md | 8 +++++--- pytion/api.py | 6 ++---- pytion/models.py | 9 +++++++-- setup.py | 3 ++- tests/fixtures.py | 1 - tests/test_api.py | 29 ++++++----------------------- 7 files changed, 25 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef103e7..f26d9f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v1.3.1 +- [#32](https://github.com/lastorel/pytion/issues/32): Rollback of Page retrieving with properties + ## v1.3.0 - [#27](https://github.com/lastorel/pytion/issues/27): Switched from `2022-02-22` to `2022-06-28` version of Notion API diff --git a/README.md b/README.md index 519a741..68327fd 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,13 @@ See [Change Log](./CHANGELOG.md) 1. [Quick Start](#quick-start) 2. [Pytion API](#pytion-api) - 1. [pytion.api.Element](#pytionapielement) + 1. [Searching](#search) + 2. [pytion.api.Element](#pytionapielement) 3. [Models](#models) 1. [pytion.models](#pytionmodels) 2. [Supported block types](#supported-block-types) - 3. [Block creating examples](#block-creating-examples) + 3. [Supported Property types](#supported-property-types) + 4. [Block creating examples](#block-creating-examples) 4. [Logging](#logging) ## Quick start @@ -162,6 +164,7 @@ There is a list of available methods for communicate with **api.notion.com**. Th `.get_page_property(property_id, id_, limit)` - Retrieve a page property item. `.get_page_properties(title_only, obj)` - Retrieve the title or all properties of current Page or Page `obj` +*(deprecated, useful for v1.3.0 only)* `.db_query(id_, limit, filter_, sorts)` - Query Database. @@ -210,7 +213,6 @@ There are classes **based on API** structures: - use `.db_filter()` to get database content with filtering and/or sorting - `Page` based on [Page object](https://developers.notion.com/reference/page) - You can create object `Page.create(...)` and/or use `.page_create(...)` API method - - use `.get_page_properties()` to retrieve page title and other `PropertyValue`-s - use `.page_update()` method to modify attributes or delete the page - use `.get_block_children()` to get page content (without nested blocks) (it will be `BlockArray`) - use `.get_block_children_recursive()` to get page content with nested blocks diff --git a/pytion/api.py b/pytion/api.py index 8e54b0c..a91446c 100644 --- a/pytion/api.py +++ b/pytion/api.py @@ -229,6 +229,7 @@ def get_block_children_recursive( def get_page_property(self, property_id: str, id_: Optional[str] = None, limit: int = 0) -> Optional[Element]: """ + DEPRECATED Retrieve a page property item. :param property_id: ID of property in current database @@ -300,10 +301,7 @@ def db_query( ) if r["object"] != "list": return None - pa = Element(api=self.api, name="pages", obj=PageArray(r["results"])) - for p in pa.obj: - pa.get_page_properties(title_only=True, obj=p) - return pa + return Element(api=self.api, name="pages", obj=PageArray(r["results"])) def db_filter(self, title: str = None, **kwargs) -> Optional[Element]: """ diff --git a/pytion/models.py b/pytion/models.py index f0fbea9..1d03b57 100644 --- a/pytion/models.py +++ b/pytion/models.py @@ -539,10 +539,15 @@ def __init__(self, **kwargs) -> None: self.url: str = kwargs.get("url") self.children = kwargs["children"] if "children" in kwargs else LinkTo(block=self) self.properties = { - name: (Property(data) if not isinstance(data, PropertyValue) else data) + name: (PropertyValue(data, name) if not isinstance(data, PropertyValue) else data) for name, data in kwargs["properties"].items() } - self.title = "unknown" + for p in self.properties.values(): + if "title" in p.type: + self.title = p.value + break + else: + self.title = None def __str__(self): return str(self.title) diff --git a/setup.py b/setup.py index ee23096..0c963af 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pytion", - version="1.3.0", + version="1.3.1", author="Yegor Gomzin", author_email="slezycmex@mail.ru", description="Unofficial Python client for official Notion API", @@ -14,6 +14,7 @@ url="https://github.com/lastorel/pytion", project_urls={ "Bug Tracker": "https://github.com/lastorel/pytion/issues", + "Changelog": "https://github.com/lastorel/pytion/blob/main/CHANGELOG.md", }, classifiers=[ "Programming Language :: Python :: 3.7", diff --git a/tests/fixtures.py b/tests/fixtures.py index 07d8f38..30a195d 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -29,5 +29,4 @@ def page_for_pages(no): @pytest.fixture(scope="session") def page_for_updates(no): page = no.pages.get("36223246a20e42df8f9b354ed1f11d75") - page.get_page_properties() return page diff --git a/tests/test_api.py b/tests/test_api.py index 3d99dbb..4d68fcc 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -37,7 +37,6 @@ def test_get__page(self, root_page): page = root_page assert isinstance(page.obj, Page), "get of .pages. must return Page object" assert page.obj.id == "878d628488d94894ab14f9b872cd6870" - page.get_page_properties() assert str(page.obj.title) == "Pytion Tests" def test_get__block(self, no): @@ -90,7 +89,6 @@ def test_get_parent__block2(self, no): parent_block = no.blocks.get_parent("8a920ba7dc1d4961811e5c82b28028ed") # Hello! How are you? assert isinstance(parent_block.obj, Page) assert parent_block.obj.id == "82ee5677402f44819a5da3302273400a" - parent_block.get_page_properties() assert str(parent_block.obj) == "Page with some texts" def test_get_parent__page(self, no): @@ -113,7 +111,6 @@ def test_get_parent__block_obj(self, no): parent_block = block.get_parent() assert isinstance(parent_block.obj, Page) assert parent_block.obj.id == "82ee5677402f44819a5da3302273400a" - parent_block.get_page_properties() assert str(parent_block.obj) == "Page with some texts" def test_get_parent__page_obj(self, no): # Database is the parent of this page @@ -128,7 +125,6 @@ def test_get_parent__database_obj(self, little_database): parent_page_block = database.get_parent() assert isinstance(parent_page_block.obj, Page) assert parent_page_block.obj.id == "878d628488d94894ab14f9b872cd6870" - parent_page_block.get_page_properties() assert str(parent_page_block.obj) == "Pytion Tests" def test_get_parent__child_page(self, no): @@ -136,7 +132,6 @@ def test_get_parent__child_page(self, no): page = child_page.get_parent() assert isinstance(page.obj, Page) assert page.obj.id == "878d628488d94894ab14f9b872cd6870" - page.get_page_properties() assert str(page.obj.title) == "Pytion Tests" def test_get_parent__child_database(self, no): @@ -272,8 +267,8 @@ def test_get_page_property__bad_page(self, no): def test_get_page_properties(self, no): page = no.pages.get("b85877eaf7bf4245a8c5218055eeb81f") # Parent testing page assert isinstance(page.obj, Page) - assert str(page.obj) == "unknown" - assert isinstance(page.obj.properties["Done"], Property) + # assert str(page.obj) == "unknown" + # assert isinstance(page.obj.properties["Done"], Property) page.get_page_properties() assert isinstance(page.obj.properties["Done"], PropertyValue) assert page.obj.properties["Digit"].value == 2 @@ -282,11 +277,11 @@ def test_get_page_properties(self, no): def test_get_page_properties__title(self, no): page = no.pages.get("b85877eaf7bf4245a8c5218055eeb81f") # Parent testing page assert isinstance(page.obj, Page) - assert str(page.obj) == "unknown" - assert isinstance(page.obj.properties["Done"], Property) + # assert str(page.obj) == "unknown" + # assert isinstance(page.obj.properties["Done"], Property) page.get_page_properties(title_only=True) - assert hasattr(page.obj.properties["by"], "value") is False - assert isinstance(page.obj.properties["Done"], Property) + # assert hasattr(page.obj.properties["by"], "value") is False + # assert isinstance(page.obj.properties["Done"], Property) assert str(page.obj.title) == "Parent testing page" def test_db_query__id(self, no): @@ -367,7 +362,6 @@ def test_db_filter__no_tags(self, little_database): def test_db_filter__tag_property_obj(self, no, little_database): page = no.pages.get("c2fc6b3dc3d244e9be2a3d28b26082bf") # Untitled - page.get_page_properties() my_prop = page.obj.properties["Tags"] pages = little_database.db_filter(property_obj=my_prop) assert isinstance(pages.obj, PageArray) @@ -468,7 +462,6 @@ def test_page_create__into_page(self, no, page_for_pages): parent = LinkTo(from_object=page_for_pages.obj) page = no.pages.page_create(parent=parent, title="Page 1") assert isinstance(page.obj, Page) - page.get_page_properties(title_only=True) assert str(page.obj.title) == "Page 1" # delete section delete_page = page.page_update(archived=True) @@ -478,7 +471,6 @@ def test_page_create__into_database(self, no): parent = LinkTo.create(database_id="35f50aa293964b0d93e09338bc980e2e") # Database for creating pages page = no.pages.page_create(parent=parent, title="Page 2") assert isinstance(page.obj, Page) - page.get_page_properties(title_only=True) assert str(page.obj.title) == "Page 2" # delete section delete_page = page.page_update(archived=True) @@ -493,7 +485,6 @@ def test_page_create__into_database_props(self, no): } page = no.pages.page_create(parent=parent, properties=props, title="Page 3") assert isinstance(page.obj, Page) - page.get_page_properties(title_only=True) assert str(page.obj.title) == "Page 3" # delete section delete_page = page.page_update(archived=True) @@ -504,7 +495,6 @@ def test_page_create__with_children(self, no, page_for_pages): child = Block.create("Hello, World!") page = no.pages.page_create(parent=parent, title="Page 4", children=[child]) assert isinstance(page.obj, Page) - page.get_page_properties(title_only=True) assert str(page.obj.title) == "Page 4" blocks = page.get_block_children() assert isinstance(blocks.obj, BlockArray) @@ -520,7 +510,6 @@ def test_page_create__from_obj(self, no, page_for_pages): page_obj = Page.create(parent=parent, title="Page 5") page = no.pages.page_create(page_obj=page_obj) assert isinstance(page.obj, Page) - page.get_page_properties(title_only=True) assert str(page.obj.title) == "Page 5" # delete section delete_page = page.page_update(archived=True) @@ -531,15 +520,12 @@ def test_page_update__rename(self, page_for_updates): new_name = "Updating for page" page = page_for_updates.page_update(title=new_name) assert isinstance(page.obj, Page) - page.get_page_properties(title_only=True) assert str(page.obj.title) == new_name old_page = page.page_update(title=RichTextArray.create(old_name)) - old_page.get_page_properties(title_only=True) assert str(old_page.obj.title) == old_name def test_page_update__change_props(self, page_for_updates): - page_for_updates.get_page_properties() old_props = page_for_updates.obj.properties new_props = { "Tags": PropertyValue.create("multi_select", ["tag2"]), @@ -548,12 +534,10 @@ def test_page_update__change_props(self, page_for_updates): } page = page_for_updates.page_update(properties=new_props) assert isinstance(page.obj, Page) - page.get_page_properties() assert "tag2" in page.obj.properties["Tags"].value assert page.obj.properties["done"].value is False old_page = page.page_update(properties=old_props) - old_page.get_page_properties() assert "tag1" in old_page.obj.properties["Tags"].value assert old_page.obj.properties["done"].value is True @@ -650,7 +634,6 @@ def test_from_linkto__base(self, no): page = no.pages.from_linkto(link) assert isinstance(page.obj, Page) assert page.obj.id == "878d628488d94894ab14f9b872cd6870" - page.get_page_properties(title_only=True) assert str(page.obj) == "Pytion Tests" def test_from_linkto__child(self, page_some_texts):