From 8d67f1c3f3fd01dea3e39fdcee2bec6f586f2556 Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Thu, 7 Sep 2023 16:48:58 -0300 Subject: [PATCH 1/3] feat: add duration to Task object --- todoist_api_python/models.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/todoist_api_python/models.py b/todoist_api_python/models.py index 7a78719..065139d 100644 --- a/todoist_api_python/models.py +++ b/todoist_api_python/models.py @@ -128,16 +128,21 @@ class Task(object): project_id: str section_id: str | None url: str + duration: Duration | None sync_id: str | None = None @classmethod def from_dict(cls, obj): due: Due | None = None + duration: Duration | None = None if obj.get("due"): due = Due.from_dict(obj["due"]) + if obj.get("duration"): + duration = Duration.from_dict(obj["duration"]) + return cls( assignee_id=obj.get("assignee_id"), assigner_id=obj.get("assigner_id"), @@ -156,6 +161,7 @@ def from_dict(cls, obj): project_id=obj["project_id"], section_id=obj["section_id"], url=obj["url"], + duration=duration ) def to_dict(self): @@ -183,6 +189,7 @@ def to_dict(self): "section_id": self.section_id, "sync_id": self.sync_id, "url": self.url, + "duration": self.duration } @classmethod @@ -421,3 +428,22 @@ def from_dict(cls, obj: dict[str, Any]) -> CompletedItems: has_more=obj["has_more"], next_cursor=obj.get("next_cursor"), ) + + +@dataclass +class Duration(object): + amount: int + unit: str + + @classmethod + def from_dict(cls, obj): + return cls( + amount=obj["amount"], + unit=obj["unit"], + ) + + def to_dict(self): + return { + "amount": self.amount, + "unit": self.unit, + } From 45b49b30701b304f74aa9007c500160d6c244303 Mon Sep 17 00:00:00 2001 From: Andrew Mleczko Date: Tue, 7 May 2024 15:25:29 +0200 Subject: [PATCH 2/3] Update models.py force test rebuild --- todoist_api_python/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/todoist_api_python/models.py b/todoist_api_python/models.py index 065139d..79d2539 100644 --- a/todoist_api_python/models.py +++ b/todoist_api_python/models.py @@ -141,6 +141,7 @@ def from_dict(cls, obj): due = Due.from_dict(obj["due"]) if obj.get("duration"): + # only get duration when it exists duration = Duration.from_dict(obj["duration"]) return cls( From c1c625db148114f3cb3fdaac5af89740a3067aae Mon Sep 17 00:00:00 2001 From: Andrew Mleczko Date: Tue, 7 May 2024 15:33:42 +0200 Subject: [PATCH 3/3] fix missing class method --- todoist_api_python/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/todoist_api_python/models.py b/todoist_api_python/models.py index 79d2539..9bb7047 100644 --- a/todoist_api_python/models.py +++ b/todoist_api_python/models.py @@ -141,7 +141,6 @@ def from_dict(cls, obj): due = Due.from_dict(obj["due"]) if obj.get("duration"): - # only get duration when it exists duration = Duration.from_dict(obj["duration"]) return cls( @@ -196,10 +195,14 @@ def to_dict(self): @classmethod def from_quick_add_response(cls, obj): due: Due | None = None + duration: Duration | None = None if obj.get("due"): due = Due.from_quick_add_response(obj) + if obj.get("duration"): + duration = Duration.from_dict(obj["duration"]) + return cls( assignee_id=obj.get("responsible_uid"), assigner_id=obj.get("assigned_by_uid"), @@ -210,6 +213,7 @@ def from_quick_add_response(cls, obj): creator_id=obj["added_by_uid"], description=obj["description"], due=due, + duration=duration, id=obj["id"], labels=obj["labels"], order=obj["child_order"],