Skip to content

Commit

Permalink
allow setting of page ID
Browse files Browse the repository at this point in the history
  • Loading branch information
thrau committed Mar 28, 2024
1 parent 9c3e77f commit a4f35f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion notion_objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .properties import *
from .values import *

__version__ = "0.5.0"
__version__ = "0.5.1"
4 changes: 2 additions & 2 deletions notion_objects/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Iterable, List

from .encode import _ConverterMixin
from .properties import ChangeTracker, Properties, Property, RootProperty
from .properties import ChangeTracker, Id, Properties, Property, RootProperty


class NotionClass(type):
Expand Down Expand Up @@ -90,6 +90,6 @@ def __str__(self):


class Page(NotionObject):
id: str = RootProperty("id")
id: str = Id()
created_time: datetime = RootProperty()
last_edited_time: datetime = RootProperty()
10 changes: 10 additions & 0 deletions notion_objects/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ def get(self, field: str, obj: dict):
return value


class Id(RootProperty[str]):
def __init__(self):
super().__init__("id")

def __set__(self, instance, value):
if self.object_locator:
instance = getattr(instance, self.object_locator)
instance[self.field] = value


class TitlePlainText(Property[str]):
def get(self, field: str, obj: dict) -> str:
items = obj["properties"][field]["title"]
Expand Down

0 comments on commit a4f35f2

Please sign in to comment.