Skip to content

Commit

Permalink
Return appropriate parent of database
Browse files Browse the repository at this point in the history
  • Loading branch information
russellkan committed Oct 1, 2023
1 parent e043c45 commit 56a061b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions n2y/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,22 @@ def _init_icon(self, icon_notion_data):

@property
def parent(self):
if self.notion_parent["type"] == "workspace":
"""
The parent of a database can be a page, another database, a block, or
it can be at the top level of workspace.
"""
type = self.notion_parent["type"]
if type == "workspace":
return None

if "page_id" not in self.notion_parent:
logger.warning(
f"Parent of database {self.title.to_plain_text()} (id: {self.notion_id})"
f" has no page_id: {self.notion_parent.items()}"
)
return None
if type == "page_id":
return self.client.get_page(self.notion_parent["page_id"])

if type == "database_id":
return self.client.get_database(self.notion_parent["database_id"])

return self.client.get_page(self.notion_parent["page_id"])
if type == "block_id":
return self.client.get_block(self.notion_parent["block_id"], page=None)

def to_pandoc(self):
return self.block.to_pandoc()

0 comments on commit 56a061b

Please sign in to comment.