From f6b8d07c559098cb6ff31543f8a762d3f64a1c3a Mon Sep 17 00:00:00 2001 From: kraanzu Date: Wed, 13 Nov 2024 17:27:13 +0530 Subject: [PATCH] add basic recurrence functionality like v2 (closes #204) --- dooit/api/hooks/update_hooks.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dooit/api/hooks/update_hooks.py b/dooit/api/hooks/update_hooks.py index a07584bc..5e687917 100644 --- a/dooit/api/hooks/update_hooks.py +++ b/dooit/api/hooks/update_hooks.py @@ -1,3 +1,4 @@ +from datetime import datetime from sqlalchemy import event, update from ..todo import Todo @@ -56,3 +57,18 @@ def update_parent_completed(todo: Todo): ) connection.execute(query) + + +@event.listens_for(Todo, "before_update") +def update_due_for_recurrence(mapper, connection, todo: Todo): + if todo.recurrence is None: + return + + if todo.due is None: + todo.due = datetime.now() + + if todo.pending: + return + + todo.pending = True + todo.due += todo.recurrence