notion-py icon indicating copy to clipboard operation
notion-py copied to clipboard

Support adding a row from a template

Open ITAYC0HEN opened this issue 4 years ago • 1 comments

Hey :wave: This pull request implements a naive way to add a new row to a collection where its origin is a template (another block_id).

The implementation is based on a sequence of API calls:

  • Enqueue a new task of type duplicateBlock (API: v3/enqueueTask)
  • Loop N times every X seconds (or milliseconds) and check the status of the task (API: v3/getTasks)

The usage is very straightforward:

cv = client.get_collection_view("...")
cv.collection.add_row(sourceBlockId="75dd203a-EXAMPLE-a12b-ba492c37a1f6")

And of course, more parameters can be added:

cv.collection.add_row(
    sourceBlockId="75dd203a-EXAMPLE-a12b-ba492c37a1f6",
    name="The Hen House: Episode #123",
    type="Podcast"
)

Note: The v3/getTasks actually supports getting the status of multiple tasks. I used it to get the status of a single one. We can consider improving it to support multiple tasks but didn't find it useful in the current design.

closes #194

ITAYC0HEN avatar Jan 30 '21 16:01 ITAYC0HEN

Hi there!

My next step is use template on creation, did some CR, if u don't mind. ;)

ag0n1k avatar Feb 07 '21 23:02 ag0n1k