Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _convert_notion_to_python(self, val, prop):
if prop["type"] in ["title", "text"]:
val = notion_to_markdown(val) if val else ""
if prop["type"] in ["number"]:
if val is not None:
val = val[0][0]
if "." in val:
val = float(val)
else:
val = int(val)
if prop["type"] in ["select"]:
val = val[0][0] if val else None
if prop["type"] in ["multi_select"]:
val = [v.strip() for v in val[0][0].split(",")] if val else []
if prop["type"] in ["person"]:
val = (
[self._client.get_user(item[1][0][1]) for item in val if item[0] == "‣"]
if val
else []
def api2py(x):
x = x or [[""]]
if markdown:
x = notion_to_markdown(x)
return api_to_python(x)
return [["‣", [["d", data]]]]
class Collection(Record):
"""
A "collection" corresponds to what's sometimes called a "database" in the Notion UI.
"""
_table = "collection"
name = field_map(
"name", api_to_python=notion_to_markdown, python_to_api=markdown_to_notion
)
description = field_map(
"description",
api_to_python=notion_to_markdown,
python_to_api=markdown_to_notion,
)
cover = field_map("cover")
@property
def templates(self):
if not hasattr(self, "_templates"):
template_ids = self.get("template_pages", [])
self._client.refresh_records(block=template_ids)
self._templates = Templates(parent=self)
return self._templates
def get_schema_properties(self):
"""
Fetch a flattened list of all properties in the collection's schema.
"""