-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v.1.0 ready for your review #69
Changes from 6 commits
a9e2bc8
2d08d31
d4edc42
18a08e3
7cb749b
82c093c
d2417f0
131dff2
0c51a54
5ad7ec9
4511c3f
4487660
07e070b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -570,8 +570,30 @@ def to_pandoc(self): | |
return self.children_to_pandoc() | ||
|
||
|
||
class LinkToPageBlock(WarningBlock): | ||
pass | ||
class LinkToPageBlock(Block): | ||
def __init__(self, client, notion_data, page, get_children=True): | ||
super().__init__(client, notion_data, page, get_children) | ||
|
||
self.link_type = self.notion_data["type"] | ||
# The key for the object id may be either "page_id" | ||
# or "database_id". | ||
self.linked_page_id = self.notion_data[self.link_type] | ||
|
||
def to_pandoc(self): | ||
# TODO: in the future, if we are exporting the linked page too, then add | ||
# a link to the page. For now, we just display the text of the page. | ||
|
||
# The linked page may be outside the scope of what is accessible to n2y. | ||
try: | ||
page = self.client.get_page_or_database(self.linked_page_id) | ||
title = page.title.to_pandoc() | ||
except PermissionError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does |
||
msg = ( | ||
"Permission denied when attempting to access linked page having id [%s]" | ||
) | ||
logger.warning(msg, self.linked_page_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see the comment on my previous review here: #69 (comment) I don't think you fully addressed the comment. |
||
|
||
return Para(title) | ||
|
||
|
||
def render_with_caption(content_ast, caption_ast): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import logging | ||
|
||
from n2y.blocks import LinkToPageBlock | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class LinkToPage(LinkToPageBlock): | ||
""" | ||
Replace page link with the content of the linked-to page. | ||
|
||
""" | ||
|
||
def __init__(self, client, notion_data, page, get_children=True): | ||
|
||
super().__init__(client, page, notion_data, get_children) | ||
|
||
# The type of object link can be either "page_id" or "database_id" | ||
self.link_type = self.notion_data["type"] | ||
self.linked_page_id = self.notion_data[self.link_type] | ||
self.linking_page_id = self.page.notion_id | ||
|
||
def to_pandoc(self): | ||
assert self.linked_page_id is not None | ||
|
||
# TODO: Might be expanded to handle links to databases as well. | ||
if self.link_type == "page_id": | ||
|
||
try: | ||
page = self.client.get_page_or_database(self.linked_page_id) | ||
|
||
rich_text = self.client.wrap_notion_rich_text_array( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @idolcemia can you explain the reasoning behind this line of code? I don't think it really makes sense and I'm surprised that the tests are passing. |
||
page.notion_data["rich_text"], self) | ||
|
||
except PermissionError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my other comment |
||
msg = ( | ||
"Permission denied when attempting to access linked page having id [%s]" | ||
) | ||
logger.warning(msg, self.linked_page_id) | ||
return None | ||
|
||
return rich_text.to_pandoc() | ||
|
||
else: | ||
|
||
logger.warning( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, all log messages should include URLs to the block in Notion where the error can be fixed. Thus, we should include a URL to the @idolcemia I thought I'd spelled this out pretty clearly in the original Issue:
I also brought it up in my first review. Please pay attention to the details on this stuff. |
||
'Links to databases (to:%s from:%s) not supported at this time.', | ||
self.linked_page_id, self.linking_page_id | ||
) | ||
|
||
return None | ||
|
||
|
||
notion_classes = { | ||
"blocks": { | ||
"link_to_page": LinkToPage, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea combining the if/else branches in my previous version of
LinkToPageBlock
. I think, given that the return value can be either a page or a database, the variable is misleading. I'd rename it tonode
as that is what we use in other places for nodes that can be either a database or a page (e.g., inmain.py
).