Skip to content

Commit c38bd6d

Browse files
authored
Merge pull request #206 from dooit-org/develop
v3.0.2
2 parents 592b3e3 + 45e21b6 commit c38bd6d

File tree

14 files changed

+193
-172
lines changed

14 files changed

+193
-172
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 3.0.3
9+
10+
### Fixed
11+
12+
- Recurrence not working as expected (https://github.com/dooit-org/dooit/issues/204)
13+
- Dooit crash on item delete and then addition (https://github.com/dooit-org/dooit/issues/205)
14+
- Stuck on CONFIRM mode if deletions are fast
15+
- Messed up column widths on sudden width changes
16+
- Values not getting parsed because of whitespace
17+
818
## 3.0.2
919

1020
### Fixed

dooit/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from platformdirs import user_data_dir, user_config_dir
44

55
OLD_CONFIG = Path(user_data_dir("dooit")) / "todo.yaml"
6-
VERSION = "3.0.2"
6+
VERSION = "3.0.3"
77

88

99
def run_dooit():

dooit/api/hooks/update_hooks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
from sqlalchemy import event, update
23
from ..todo import Todo
34

@@ -56,3 +57,18 @@ def update_parent_completed(todo: Todo):
5657
)
5758

5859
connection.execute(query)
60+
61+
62+
@event.listens_for(Todo, "before_update")
63+
def update_due_for_recurrence(mapper, connection, todo: Todo):
64+
if todo.recurrence is None:
65+
return
66+
67+
if todo.due is None:
68+
todo.due = datetime.now()
69+
70+
if todo.pending:
71+
return
72+
73+
todo.pending = True
74+
todo.due += todo.recurrence

dooit/api/todo.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from functools import cmp_to_key
21
from typing import TYPE_CHECKING, Optional, Union
32
from datetime import datetime, timedelta
43
from typing import List
54
from sqlalchemy import ForeignKey, select, nulls_last
6-
from sqlalchemy.orm import Mapped, mapped_column, relationship
5+
from sqlalchemy.orm import Mapped, mapped_column, relationship, validates
76
from .model import DooitModel
87
from .manager import manager
98

@@ -12,29 +11,6 @@
1211
from dooit.api.workspace import Workspace
1312

1413

15-
def _custom_sort_by_status(x: "Todo", y: "Todo") -> int:
16-
if x.status == y.status:
17-
d1 = x.due or datetime.max
18-
d2 = y.due or datetime.max
19-
if d1 < d2:
20-
return 1
21-
elif d1 > d2:
22-
return -1
23-
else:
24-
return 0
25-
26-
values = {"completed": 0, "pending": 1, "overdue": 2}
27-
s1 = values[x.status]
28-
s2 = values[y.status]
29-
30-
if s1 < s2:
31-
return 1
32-
elif s1 > s2:
33-
return -1
34-
else:
35-
return 0
36-
37-
3814
class Todo(DooitModel):
3915
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
4016
order_index: Mapped[int] = mapped_column(default=-1)
@@ -71,6 +47,13 @@ class Todo(DooitModel):
7147
order_by=order_index,
7248
)
7349

50+
@validates("recurrence")
51+
def validate_pending(self, key, value):
52+
if value is not None:
53+
self.pending = True
54+
55+
return value
56+
7457
@classmethod
7558
def from_id(cls, _id: str) -> "Todo":
7659
_id = _id.lstrip("Todo_")
@@ -132,7 +115,11 @@ def sort_siblings(self, field: str):
132115
else:
133116
items = sorted(
134117
self.siblings,
135-
key=cmp_to_key(_custom_sort_by_status),
118+
key=lambda x: (
119+
not x.pending,
120+
x.due or datetime.max,
121+
x.order_index,
122+
),
136123
)
137124

138125
for index, todo in enumerate(items):
@@ -150,6 +137,7 @@ def _add_sibling(self) -> "Todo":
150137
parent_todo=self.parent_todo,
151138
parent_workspace=self.parent_workspace,
152139
)
140+
todo.save()
153141
return todo
154142

155143
# ----------- HELPER FUNCTIONS --------------

dooit/api/workspace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def _add_sibling(self) -> "Workspace":
105105
workspace = Workspace(
106106
parent_workspace=self.parent_workspace,
107107
)
108+
workspace.save()
108109
return workspace
109110

110111
def save(self) -> None:

dooit/ui/tui.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def shutdown(self, event: ShutDown):
9999
@on(ModeChanged)
100100
def change_status(self, event: ModeChanged):
101101
self._mode = event.mode
102+
if event.mode == "NORMAL":
103+
self.workspace_tree.refresh_options()
104+
todos_tree = self.api.vars.todos_tree
105+
if todos_tree:
106+
todos_tree.refresh_options()
102107

103108
@on(_QuitApp)
104109
async def quit_app(self):

dooit/ui/widgets/bars/_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def switcher(self) -> "BarSwitcher":
4444
assert isinstance(parent, BarSwitcher)
4545
return parent
4646

47-
def on_unmount(self):
47+
async def on_unmount(self):
48+
self.post_message(ModeChanged("NORMAL"))
4849
self.switcher.current = "status_bar"
4950

5051
def perform_action(self, cancel: bool):

dooit/ui/widgets/inputs/simple_input.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def reset(self) -> str:
4646
return self.value
4747

4848
def stop_edit(self) -> None:
49+
self._value = self.value.strip()
4950
try:
5051
self.model_value = self._typecast_value(self.value)
5152
self.model.save()

dooit/ui/widgets/trees/model_tree.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,11 @@ def add_sibling(self):
312312
@require_confirmation
313313
@refresh_tree
314314
def _remove_node(self):
315-
self.current_model.drop()
315+
model = self.current_model
316+
317+
self._renderers.pop(model.uuid)
318+
self.expanded_nodes.pop(model.uuid)
319+
model.drop()
316320

317321
@require_highlighted_node
318322
def remove_node(self):

0 commit comments

Comments
 (0)