Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set(self, path, value):
"""
Set a specific `value` (under the specific `path`) on the record's data structure on the server.
"""
self._client.submit_transaction(
build_operation(id=self.id, path=path, args=value, table=self._table)
)
if not self.is_alias:
# If it's not an alias, we actually remove the block
with self._client.as_atomic_transaction():
# Mark the block as inactive
self._client.submit_transaction(
build_operation(
id=self.id, path=[], args={"alive": False}, command="update"
)
)
# Remove the block's ID from a list on its parent, if needed
if self.parent.child_list_key:
self._client.submit_transaction(
build_operation(
id=self.get("parent_id"),
path=[self.parent.child_list_key],
args={"id": self.id},
command="listRemove",
table=self.get("parent_table"),
)
)
if permanently:
block_id = self.id
self._client.post(
"deleteBlocks", {"blockIds": [block_id], "permanentlyDelete": True}
)
del self._client._store._values["block"][block_id]
else:
def remove(self, permanently=False):
"""
Removes the node from its parent, and marks it as inactive. This corresponds to what happens in the
Notion UI when you delete a block. Note that it doesn't *actually* delete it, just orphan it, unless
`permanently` is set to True, in which case we make an extra call to hard-delete.
"""
if not self.is_alias:
# If it's not an alias, we actually remove the block
with self._client.as_atomic_transaction():
# Mark the block as inactive
self._client.submit_transaction(
build_operation(
id=self.id, path=[], args={"alive": False}, command="update"
)
)
# Remove the block's ID from a list on its parent, if needed
if self.parent.child_list_key:
self._client.submit_transaction(
build_operation(
id=self.get("parent_id"),
path=[self.parent.child_list_key],
args={"id": self.id},
command="listRemove",
table=self.get("parent_table"),
)
)
def add_alias(self, block):
"""
Adds an alias to the provided `block`, i.e. adds the block's ID to the parent's content list,
but doesn't change the block's parent_id.
"""
# add the block to the content list of the parent
self._client.submit_transaction(
build_operation(
id=self._parent.id,
path=[self.child_list_key],
args={"id": block.id},
command="listAfter",
)
)
return self._get_block(block.id)
def remove(self):
# Mark the block as inactive
self._client.submit_transaction(
build_operation(
id=self.id, path=[], args={"alive": False}, command="update"
)
"id": record_id,
"version": 1,
"alive": True,
"created_by": self.current_user.id,
"created_time": now(),
"parent_id": parent.id,
"parent_table": parent._table,
}
args.update(kwargs)
with self.as_atomic_transaction():
# create the new record
self.submit_transaction(
build_operation(
args=args, command="set", id=record_id, path=[], table=table
)
)
# add the record to the content list of the parent, if needed
if child_list_key:
self.submit_transaction(
build_operation(
id=parent.id,
path=[child_list_key],
args={"id": record_id},
command="listAfter",
table=parent._table,
)
)
args.update(kwargs)
with self.as_atomic_transaction():
# create the new record
self.submit_transaction(
build_operation(
args=args, command="set", id=record_id, path=[], table=table
)
)
# add the record to the content list of the parent, if needed
if child_list_key:
self.submit_transaction(
build_operation(
id=parent.id,
path=[child_list_key],
args={"id": record_id},
command="listAfter",
table=parent._table,
)
)
return record_id