Skip to content

Include Formatting Helpers for CollectionView and PageBlock #284

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions notion/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
import time
import uuid
import base64

from cached_property import cached_property
from copy import deepcopy
Expand Down Expand Up @@ -557,6 +558,59 @@ def get_backlinks(self):
backlinks.append(self._client.get_block(block_id))
return backlinks

def set_full_width(self, full_width):
args = {"page_full_width": full_width}
self._client.submit_transaction(
[build_operation(
id=self.id, path=["format"], args=args, command="update"
)]
)
self.refresh()

def set_small_text(self, small_text):
args = {"page_small_text": small_text}
self._client.submit_transaction(
[build_operation(
id=self.id, path=["format"], args=args, command="update"
)]
)
self.refresh()

def set_page_font(self, page_font):
args = {"page_font": page_font}
self._client.submit_transaction(
[build_operation(
id=self.id, path=["format"], args=args, command="update"
)]
)
self.refresh()

def set_page_icon(self, icon):

self._client.submit_transaction(
[build_operation(
id=self.id, path=["format", "page_icon"], args=icon, command="set"
)])

def set_page_cover(self, args, page_cover_position=0.5):

postion_args = {"page_cover_position": page_cover_position}
self._client.submit_transaction(
[build_operation(
id=self.id, path=["format"], args=postion_args, command="update"
),build_operation(
id=self.id, path=["format", "page_cover"], args=args, command="set"
)]
)

def set_page_cover_position(self, page_cover_position):

postion_args = {"page_cover_position": page_cover_position}
self._client.submit_transaction(
[build_operation(
id=self.id, path=["format"], args=postion_args, command="update"
)]
)

class BulletedListBlock(BasicBlock):

Expand Down
14 changes: 9 additions & 5 deletions notion/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,22 @@ def post(self, endpoint, data):
response.raise_for_status()
return response

def submit_transaction(self, operations, update_last_edited=True):
def submit_transaction(self, operations, generate_update_last_edited=True, updated_blocks=None):

if not operations:
return

if isinstance(operations, dict):
operations = [operations]

if update_last_edited:
updated_blocks = set(
[op["id"] for op in operations if op["table"] == "block"]
)
if generate_update_last_edited:
generated_updated_blocks = [op["id"] for op in operations if op["table"] == "block"]
if updated_blocks is not None and type(updated_blocks) is list:
generated_updated_blocks.extend(updated_blocks)

updated_blocks = set(generated_updated_blocks)

if updated_blocks is not None:
operations += [
operation_update_last_edited(self.current_user.id, block_id)
for block_id in updated_blocks
Expand Down
Loading