todooit 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- todooit/__init__.py +0 -0
- todooit/__main__.py +71 -0
- todooit/api/__init__.py +90 -0
- todooit/api/cadence.py +179 -0
- todooit/api/exceptions.py +25 -0
- todooit/api/expansion.py +33 -0
- todooit/api/fixed_projects.py +422 -0
- todooit/api/history.py +376 -0
- todooit/api/hooks/fix_hooks.py +40 -0
- todooit/api/hooks/validation_hooks.py +30 -0
- todooit/api/lifecycle.py +509 -0
- todooit/api/manager.py +113 -0
- todooit/api/model.py +233 -0
- todooit/api/note_migration.py +159 -0
- todooit/api/orphan_migration.py +51 -0
- todooit/api/pinned_note.py +69 -0
- todooit/api/placement.py +68 -0
- todooit/api/project.py +201 -0
- todooit/api/recycle.py +152 -0
- todooit/api/theme.py +86 -0
- todooit/api/todo.py +363 -0
- todooit/paths.py +57 -0
- todooit/ui/__init__.py +0 -0
- todooit/ui/api/__init__.py +24 -0
- todooit/ui/api/api_components/__init__.py +19 -0
- todooit/ui/api/api_components/_base.py +2 -0
- todooit/ui/api/api_components/bar.py +20 -0
- todooit/ui/api/api_components/formatters/__init__.py +9 -0
- todooit/ui/api/api_components/formatters/_decorators.py +8 -0
- todooit/ui/api/api_components/formatters/_model_formatter_base.py +21 -0
- todooit/ui/api/api_components/formatters/formatter.py +13 -0
- todooit/ui/api/api_components/formatters/formatter_store.py +141 -0
- todooit/ui/api/api_components/formatters/model_formatters.py +28 -0
- todooit/ui/api/api_components/keys.py +229 -0
- todooit/ui/api/api_components/layout.py +33 -0
- todooit/ui/api/api_components/vars.py +178 -0
- todooit/ui/api/api_components/vim.py +21 -0
- todooit/ui/api/bar_widgets.py +76 -0
- todooit/ui/api/event_handlers.py +29 -0
- todooit/ui/api/events/__init__.py +51 -0
- todooit/ui/api/events/events.py +191 -0
- todooit/ui/api/formatter_presets.py +86 -0
- todooit/ui/api/loader.py +47 -0
- todooit/ui/api/plug.py +89 -0
- todooit/ui/api/todooit_api.py +532 -0
- todooit/ui/api/widgets.py +22 -0
- todooit/ui/pane_layout.py +259 -0
- todooit/ui/screens/__init__.py +18 -0
- todooit/ui/screens/base.py +69 -0
- todooit/ui/screens/calendar.py +327 -0
- todooit/ui/screens/help.py +238 -0
- todooit/ui/screens/index.py +566 -0
- todooit/ui/screens/move.py +198 -0
- todooit/ui/screens/note/__init__.py +13 -0
- todooit/ui/screens/note/disp/__init__.py +12 -0
- todooit/ui/screens/note/disp/document.py +464 -0
- todooit/ui/screens/note/disp/markdown.py +272 -0
- todooit/ui/screens/note/disp/markup.py +429 -0
- todooit/ui/screens/note/disp/theme.py +153 -0
- todooit/ui/screens/note/disp/view.py +410 -0
- todooit/ui/screens/note/screens/__init__.py +12 -0
- todooit/ui/screens/note/screens/attachments.py +221 -0
- todooit/ui/screens/note/screens/help.py +269 -0
- todooit/ui/screens/note/screens/pinned.py +27 -0
- todooit/ui/screens/note/screens/screen.py +623 -0
- todooit/ui/screens/note/vim/__init__.py +13 -0
- todooit/ui/screens/note/vim/buffer.py +208 -0
- todooit/ui/screens/note/vim/clipboard.py +200 -0
- todooit/ui/screens/note/vim/editing.py +229 -0
- todooit/ui/screens/note/vim/editor.py +125 -0
- todooit/ui/screens/note/vim/history.py +61 -0
- todooit/ui/screens/note/vim/host.py +48 -0
- todooit/ui/screens/note/vim/modes.py +509 -0
- todooit/ui/screens/panel.py +115 -0
- todooit/ui/screens/project_completion.py +380 -0
- todooit/ui/screens/quick_add.py +334 -0
- todooit/ui/screens/search.py +634 -0
- todooit/ui/slim_cursor.py +83 -0
- todooit/ui/styles.tcss +297 -0
- todooit/ui/tui.py +109 -0
- todooit/ui/widgets/__init__.py +7 -0
- todooit/ui/widgets/bars/__init__.py +12 -0
- todooit/ui/widgets/bars/_base.py +61 -0
- todooit/ui/widgets/bars/bar_switcher.py +85 -0
- todooit/ui/widgets/bars/confirm_bar/__init__.py +3 -0
- todooit/ui/widgets/bars/confirm_bar/bar.py +52 -0
- todooit/ui/widgets/bars/field_bar/__init__.py +3 -0
- todooit/ui/widgets/bars/field_bar/bar.py +77 -0
- todooit/ui/widgets/bars/notification_bar/__init__.py +3 -0
- todooit/ui/widgets/bars/notification_bar/bar.py +114 -0
- todooit/ui/widgets/bars/status_bar/__init__.py +4 -0
- todooit/ui/widgets/bars/status_bar/bar.py +38 -0
- todooit/ui/widgets/bars/status_bar/bar_widget.py +44 -0
- todooit/ui/widgets/inputs/_input.py +360 -0
- todooit/ui/widgets/inputs/model_inputs.py +216 -0
- todooit/ui/widgets/inputs/simple_input.py +81 -0
- todooit/ui/widgets/inputs/vim_input.py +279 -0
- todooit/ui/widgets/renderers/__init__.py +11 -0
- todooit/ui/widgets/renderers/base_renderer.py +394 -0
- todooit/ui/widgets/renderers/project_renderer.py +11 -0
- todooit/ui/widgets/renderers/todo_renderer.py +27 -0
- todooit/ui/widgets/trees/__init__.py +25 -0
- todooit/ui/widgets/trees/_decorators.py +88 -0
- todooit/ui/widgets/trees/_render_dict.py +54 -0
- todooit/ui/widgets/trees/base_tree.py +71 -0
- todooit/ui/widgets/trees/bin_todos_tree.py +23 -0
- todooit/ui/widgets/trees/fixed_todos_tree.py +275 -0
- todooit/ui/widgets/trees/flash_jump.py +216 -0
- todooit/ui/widgets/trees/model_tree.py +1125 -0
- todooit/ui/widgets/trees/projects_tree.py +369 -0
- todooit/ui/widgets/trees/todos_tree.py +362 -0
- todooit/utils/__init__.py +71 -0
- todooit/utils/clipboard.py +218 -0
- todooit/utils/colors.py +13 -0
- todooit/utils/css_manager.py +106 -0
- todooit/utils/database.py +10 -0
- todooit/utils/date_parser.py +515 -0
- todooit/utils/day_names.py +24 -0
- todooit/utils/default_config.py +981 -0
- todooit/utils/files.py +399 -0
- todooit/utils/holidays.py +102 -0
- todooit/utils/links.py +629 -0
- todooit/utils/project_complete.py +257 -0
- todooit/utils/quick_add.py +350 -0
- todooit/vim_engine/__init__.py +64 -0
- todooit/vim_engine/buffer.py +125 -0
- todooit/vim_engine/engine.py +1735 -0
- todooit/vim_engine/keymap.py +184 -0
- todooit/vim_engine/motions.py +282 -0
- todooit/vim_engine/register.py +87 -0
- todooit/vim_engine/search.py +67 -0
- todooit/vim_engine/text_objects.py +293 -0
- todooit/vim_engine/vim_flash.py +191 -0
- todooit-1.0.0.dist-info/METADATA +163 -0
- todooit-1.0.0.dist-info/RECORD +138 -0
- todooit-1.0.0.dist-info/WHEEL +4 -0
- todooit-1.0.0.dist-info/entry_points.txt +2 -0
- todooit-1.0.0.dist-info/licenses/LICENSE +23 -0
todooit/__init__.py
ADDED
|
File without changes
|
todooit/__main__.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from importlib.metadata import version as _package_version
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
|
|
8
|
+
from todooit.paths import DEV_HOME, HOME_ENV_VAR, config_file
|
|
9
|
+
|
|
10
|
+
# pyproject.toml is the one place the version is written
|
|
11
|
+
VERSION = _package_version("todooit")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def run_todooit(config: Optional[str] = None, db_path: Optional[str] = None):
|
|
15
|
+
config_path = None if not config else Path(config)
|
|
16
|
+
|
|
17
|
+
if config_path and not (config_path.exists() and config_path.is_file()):
|
|
18
|
+
print(f"Config file {config} not found.")
|
|
19
|
+
return
|
|
20
|
+
|
|
21
|
+
from todooit.api.note_migration import BackupFailed
|
|
22
|
+
from todooit.ui.tui import Todooit
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
app = Todooit(config=config_path, db_path=db_path)
|
|
26
|
+
except BackupFailed as error:
|
|
27
|
+
raise click.ClickException(str(error)) from error
|
|
28
|
+
|
|
29
|
+
app.run()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@click.group(
|
|
33
|
+
context_settings={"help_option_names": ["-h", "--help"]},
|
|
34
|
+
invoke_without_command=True,
|
|
35
|
+
)
|
|
36
|
+
@click.option(
|
|
37
|
+
"--version",
|
|
38
|
+
"-v",
|
|
39
|
+
is_flag=True,
|
|
40
|
+
help="Show version and exit.",
|
|
41
|
+
)
|
|
42
|
+
@click.option("-c", "--config", default=None, help="Path to config file")
|
|
43
|
+
@click.option("--db", default=None, help="Path to database file")
|
|
44
|
+
@click.option(
|
|
45
|
+
"--dev",
|
|
46
|
+
is_flag=True,
|
|
47
|
+
help="Run an isolated dev instance (own database, cache and config).",
|
|
48
|
+
)
|
|
49
|
+
@click.pass_context
|
|
50
|
+
def main(ctx, version: bool, config: str, db: str, dev: bool) -> None:
|
|
51
|
+
if version:
|
|
52
|
+
return print(f"todooit - {VERSION}")
|
|
53
|
+
|
|
54
|
+
# Must happen before anything imports the package: Todooit.CSS_PATH is
|
|
55
|
+
# evaluated in the class body, so the cache dir is resolved at import time.
|
|
56
|
+
# setdefault so an explicit TODOOIT_HOME still wins over --dev.
|
|
57
|
+
if dev:
|
|
58
|
+
os.environ.setdefault(HOME_ENV_VAR, str(DEV_HOME))
|
|
59
|
+
|
|
60
|
+
if ctx.invoked_subcommand is None:
|
|
61
|
+
run_todooit(config=config, db_path=db)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@main.command(help="Show config location.")
|
|
65
|
+
def config_loc() -> None:
|
|
66
|
+
"""Print the location of the configuration file."""
|
|
67
|
+
print(config_file())
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if __name__ == "__main__":
|
|
71
|
+
main()
|
todooit/api/__init__.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from . import lifecycle
|
|
2
|
+
from .cadence import Cadence
|
|
3
|
+
from .fixed_projects import (
|
|
4
|
+
BIN,
|
|
5
|
+
TODAY,
|
|
6
|
+
UPCOMING,
|
|
7
|
+
FixedProject,
|
|
8
|
+
TodoGroup,
|
|
9
|
+
TodoRow,
|
|
10
|
+
binned_tasks,
|
|
11
|
+
fixed_project_from_id,
|
|
12
|
+
fixed_project_from_key,
|
|
13
|
+
fixed_projects,
|
|
14
|
+
)
|
|
15
|
+
from .history import ChangedRows, History
|
|
16
|
+
from .hooks import fix_hooks, validation_hooks
|
|
17
|
+
from .manager import manager
|
|
18
|
+
from .model import BaseModel, TodooitModel
|
|
19
|
+
from .pinned_note import PINNED_NOTE_ID, PinnedNote
|
|
20
|
+
from .project import Project
|
|
21
|
+
from .recycle import (
|
|
22
|
+
REVIVED_PREFIX,
|
|
23
|
+
empty_bin,
|
|
24
|
+
move_project_to_bin,
|
|
25
|
+
move_todo_to_bin,
|
|
26
|
+
restore_todo,
|
|
27
|
+
revive_home,
|
|
28
|
+
)
|
|
29
|
+
from .todo import (
|
|
30
|
+
SORT_KEYS,
|
|
31
|
+
Todo,
|
|
32
|
+
TodoSortModeType,
|
|
33
|
+
freeze_sort_order,
|
|
34
|
+
sort_todos,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def drop_blank_models() -> None:
|
|
39
|
+
"""
|
|
40
|
+
Delete childless items with a blank description (left over from quitting mid-edit)
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def is_blank(model) -> bool:
|
|
44
|
+
return not (model.description or "").strip()
|
|
45
|
+
|
|
46
|
+
for project in Project.all():
|
|
47
|
+
if is_blank(project) and not project.projects and not project.todos:
|
|
48
|
+
project.drop()
|
|
49
|
+
|
|
50
|
+
for todo in Todo.all():
|
|
51
|
+
if is_blank(todo) and not todo.todos:
|
|
52
|
+
todo.drop()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
__all__ = [
|
|
56
|
+
"BaseModel",
|
|
57
|
+
"TodooitModel",
|
|
58
|
+
"Cadence",
|
|
59
|
+
"Todo",
|
|
60
|
+
"TodoSortModeType",
|
|
61
|
+
"SORT_KEYS",
|
|
62
|
+
"sort_todos",
|
|
63
|
+
"freeze_sort_order",
|
|
64
|
+
"Project",
|
|
65
|
+
"PinnedNote",
|
|
66
|
+
"PINNED_NOTE_ID",
|
|
67
|
+
"FixedProject",
|
|
68
|
+
"TodoGroup",
|
|
69
|
+
"TodoRow",
|
|
70
|
+
"TODAY",
|
|
71
|
+
"UPCOMING",
|
|
72
|
+
"BIN",
|
|
73
|
+
"REVIVED_PREFIX",
|
|
74
|
+
"empty_bin",
|
|
75
|
+
"move_project_to_bin",
|
|
76
|
+
"move_todo_to_bin",
|
|
77
|
+
"restore_todo",
|
|
78
|
+
"revive_home",
|
|
79
|
+
"fixed_project_from_id",
|
|
80
|
+
"fixed_project_from_key",
|
|
81
|
+
"fixed_projects",
|
|
82
|
+
"binned_tasks",
|
|
83
|
+
"ChangedRows",
|
|
84
|
+
"History",
|
|
85
|
+
"manager",
|
|
86
|
+
"lifecycle",
|
|
87
|
+
"drop_blank_models",
|
|
88
|
+
"fix_hooks",
|
|
89
|
+
"validation_hooks",
|
|
90
|
+
]
|
todooit/api/cadence.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""
|
|
2
|
+
How often a recurring todo comes back
|
|
3
|
+
|
|
4
|
+
A count of one unit, written the way it is typed: `2h`, `3d`, `1w`, `1m`,
|
|
5
|
+
`1y`. There are no minutes, so `m` is a month (`mo` is read too). Months and
|
|
6
|
+
years are calendar steps, not a fixed length, so a monthly todo on the 5th
|
|
7
|
+
stays on the 5th.
|
|
8
|
+
|
|
9
|
+
A todo on a day a shorter month lacks lands on that month's last day and goes
|
|
10
|
+
back to its own day after: 31 Jan, 28 Feb, 31 Mar, 30 Apr. While it sits on
|
|
11
|
+
such a clamped day, the day it belongs on is kept in `day`.
|
|
12
|
+
|
|
13
|
+
`eom` is the month's last working day: the last weekday that is not an
|
|
14
|
+
Austrian public holiday. It has no count and no kept day; each month's is
|
|
15
|
+
worked out from the calendar.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import re
|
|
19
|
+
from calendar import monthrange
|
|
20
|
+
from dataclasses import dataclass, replace
|
|
21
|
+
from datetime import date, datetime, timedelta
|
|
22
|
+
from typing import Optional, Tuple
|
|
23
|
+
|
|
24
|
+
from sqlalchemy import String
|
|
25
|
+
from sqlalchemy.types import TypeDecorator
|
|
26
|
+
|
|
27
|
+
from ..utils.holidays import next_month_end
|
|
28
|
+
|
|
29
|
+
# Typed suffix -> unit
|
|
30
|
+
UNITS = {
|
|
31
|
+
"mo": "months",
|
|
32
|
+
"m": "months",
|
|
33
|
+
"h": "hours",
|
|
34
|
+
"d": "days",
|
|
35
|
+
"w": "weeks",
|
|
36
|
+
"y": "years",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
SUFFIXES = {"months": "m", "hours": "h", "days": "d", "weeks": "w", "years": "y"}
|
|
40
|
+
|
|
41
|
+
CALENDAR_UNITS = ("months", "years")
|
|
42
|
+
|
|
43
|
+
PATTERN = re.compile(r"^(\d+)(mo|m|h|d|w|y)(?:@(\d+))?$")
|
|
44
|
+
|
|
45
|
+
MONTH_END = "eom"
|
|
46
|
+
|
|
47
|
+
# Rows written before cadences were stored as text hold an SQLAlchemy Interval:
|
|
48
|
+
# the timedelta as a moment after the epoch
|
|
49
|
+
EPOCH = datetime(1970, 1, 1)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass(frozen=True)
|
|
53
|
+
class Cadence:
|
|
54
|
+
count: int
|
|
55
|
+
unit: str
|
|
56
|
+
# Calendar units only: the day of the month a clamped date goes back to
|
|
57
|
+
day: Optional[int] = None
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def parse(cls, text: str) -> "Cadence":
|
|
61
|
+
text = text.strip()
|
|
62
|
+
|
|
63
|
+
if text.lower() == MONTH_END:
|
|
64
|
+
return cls(1, MONTH_END)
|
|
65
|
+
|
|
66
|
+
match = PATTERN.match(text)
|
|
67
|
+
|
|
68
|
+
if match is None or int(match[1]) == 0:
|
|
69
|
+
raise ValueError("Invalid recurrence format")
|
|
70
|
+
|
|
71
|
+
day = int(match[3]) if match[3] else None
|
|
72
|
+
return cls(int(match[1]), UNITS[match[2]], day)
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
def from_timedelta(cls, td: timedelta) -> "Cadence":
|
|
76
|
+
"""
|
|
77
|
+
The largest unit that measures it exactly
|
|
78
|
+
|
|
79
|
+
An old interval of whole minutes was typed as `Nm`, which now means
|
|
80
|
+
N months, so that is what it becomes.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
if td.seconds == 0 and td.days % 7 == 0:
|
|
84
|
+
return cls(td.days // 7, "weeks")
|
|
85
|
+
|
|
86
|
+
if td.seconds == 0:
|
|
87
|
+
return cls(td.days, "days")
|
|
88
|
+
|
|
89
|
+
minutes = int(td.total_seconds()) // 60
|
|
90
|
+
|
|
91
|
+
if minutes % 60 == 0:
|
|
92
|
+
return cls(minutes // 60, "hours")
|
|
93
|
+
|
|
94
|
+
return cls(minutes, "months")
|
|
95
|
+
|
|
96
|
+
def __str__(self) -> str:
|
|
97
|
+
"""As typed, without the kept day"""
|
|
98
|
+
|
|
99
|
+
if self.unit == MONTH_END:
|
|
100
|
+
return MONTH_END
|
|
101
|
+
|
|
102
|
+
return f"{self.count}{SUFFIXES[self.unit]}"
|
|
103
|
+
|
|
104
|
+
def stored(self) -> str:
|
|
105
|
+
return f"{self}@{self.day}" if self.day else str(self)
|
|
106
|
+
|
|
107
|
+
def first(self, when: datetime) -> datetime:
|
|
108
|
+
"""
|
|
109
|
+
The first occurrence on or after `when`
|
|
110
|
+
|
|
111
|
+
Any date starts a fixed or calendar cadence; a month end only starts
|
|
112
|
+
on a month end.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
if self.unit == MONTH_END:
|
|
116
|
+
return _on(next_month_end(when.date()), when)
|
|
117
|
+
|
|
118
|
+
return when
|
|
119
|
+
|
|
120
|
+
def after(self, when: datetime) -> Tuple[datetime, "Cadence"]:
|
|
121
|
+
"""
|
|
122
|
+
The next occurrence after `when`, and the cadence to keep for the one
|
|
123
|
+
after it (which remembers a day the new date had to give up)
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
if self.unit == MONTH_END:
|
|
127
|
+
return _on(next_month_end(when.date(), strictly_after=True), when), self
|
|
128
|
+
|
|
129
|
+
if self.unit not in CALENDAR_UNITS:
|
|
130
|
+
return when + timedelta(**{self.unit: self.count}), self
|
|
131
|
+
|
|
132
|
+
# The kept day only holds while the date is still where it put it;
|
|
133
|
+
# a todo moved by hand recurs on its new day
|
|
134
|
+
day = self.day if self.day and _clamp(when, self.day) == when.day else when.day
|
|
135
|
+
months = self.count * (12 if self.unit == "years" else 1)
|
|
136
|
+
|
|
137
|
+
index = when.month - 1 + months
|
|
138
|
+
year, month = when.year + index // 12, index % 12 + 1
|
|
139
|
+
new = when.replace(year=year, month=month, day=1)
|
|
140
|
+
new = new.replace(day=_clamp(new, day))
|
|
141
|
+
|
|
142
|
+
return new, replace(self, day=day if day != new.day else None)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _on(day: date, when: datetime) -> datetime:
|
|
146
|
+
"""`when`'s time of day, on another day"""
|
|
147
|
+
|
|
148
|
+
return datetime.combine(day, when.time())
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _clamp(when: datetime, day: int) -> int:
|
|
152
|
+
return min(day, monthrange(when.year, when.month)[1])
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class CadenceType(TypeDecorator):
|
|
156
|
+
"""
|
|
157
|
+
A cadence in the old Interval column, as its typed text
|
|
158
|
+
|
|
159
|
+
No migration: SQLite keeps text as text in that column, and the old
|
|
160
|
+
epoch-datetime rows are read as the fixed interval they always were.
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
impl = String
|
|
164
|
+
cache_ok = True
|
|
165
|
+
|
|
166
|
+
def process_bind_param(self, value: Optional[Cadence], dialect) -> Optional[str]:
|
|
167
|
+
return None if value is None else value.stored()
|
|
168
|
+
|
|
169
|
+
def process_result_value(self, value, dialect) -> Optional[Cadence]:
|
|
170
|
+
if value is None:
|
|
171
|
+
return None
|
|
172
|
+
|
|
173
|
+
if isinstance(value, datetime):
|
|
174
|
+
return Cadence.from_timedelta(value - EPOCH)
|
|
175
|
+
|
|
176
|
+
if value == MONTH_END or PATTERN.match(value):
|
|
177
|
+
return Cadence.parse(value)
|
|
178
|
+
|
|
179
|
+
return Cadence.from_timedelta(datetime.fromisoformat(value) - EPOCH)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class TodooitError(Exception):
|
|
2
|
+
"""
|
|
3
|
+
Base class for all exceptions raised by the API.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class NoParentError(TodooitError):
|
|
8
|
+
"""
|
|
9
|
+
Raised when user tries to add a Todo object without a parent
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MultipleParentError(TodooitError):
|
|
14
|
+
"""
|
|
15
|
+
Raised when user tries to add a Todo object with both a project and a todo parent
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class NoNodeError(TodooitError):
|
|
20
|
+
"""
|
|
21
|
+
Raised when user tried to perform an operation that requires a node, but no node is selected
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __str__(self) -> str: # pragma: no cover
|
|
25
|
+
return "No item selected"
|
todooit/api/expansion.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Expansion state by row id, for the panes that know a row only by its uuid
|
|
3
|
+
|
|
4
|
+
The state itself is `TodooitModel.expanded`. Ids that are no stored row
|
|
5
|
+
(fixed projects, headings) are always open and ignore being closed.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Optional, Union
|
|
9
|
+
|
|
10
|
+
from .project import Project
|
|
11
|
+
from .todo import Todo
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _model(_id: str) -> Optional[Union[Project, Todo]]:
|
|
15
|
+
if _id.startswith("Todo_"):
|
|
16
|
+
return Todo.from_id(_id)
|
|
17
|
+
|
|
18
|
+
if _id.startswith("Project_"):
|
|
19
|
+
return Project.from_id(_id)
|
|
20
|
+
|
|
21
|
+
return None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def is_expanded(_id: str) -> bool:
|
|
25
|
+
model = _model(_id)
|
|
26
|
+
return True if model is None else model.expanded
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def set_expanded(_id: str, expanded: bool) -> None:
|
|
30
|
+
model = _model(_id)
|
|
31
|
+
|
|
32
|
+
if model is not None:
|
|
33
|
+
model.set_expanded(expanded)
|