Skip to content
Murli Tawari edited this page Sep 1, 2023 · 12 revisions

Manager (class)

The Manager class is responsible for managing the top level of the Dooit application. This includes reading and writing to-do data to a storage location, as well as providing high-level operations for managing the application's workspaces.

You can get the storage location by using this command:

python -c "import appdirs; print(appdirs.user_data_dir('dooit'))"

Manager Methods

# Importing manager class
from dooit.api import manager

commit() -> None
# This function commits all the changes made to the storage file

refresh_data() -> bool
# This function syncs the data with the storage file and returns `True` if the data was modified inside the class

add_workspace() -> Workspace
# Adds a child workspace and returns the object

Workspace (class)

Workspace class is, to put simply, a class with it's own sets of todos and child workspaces which it manages

Variables

description: str # The description of the workspace
workspaces: List[Workspace] # List of child workspaces
todos: List[Todo] # List of todos

Workspace Methods

add_sibling() -> Workspace
# Adds a sibling to the workspace and returns it

add_workspace(index: int = 0)
# Adds a child workspace with the given index (defaults to first child)

add_todo() -> Todo:
# Adds a todo to the workspace and returns it

# ... more below

Todo (class)

Variables

description: str # the description of todo
effort: str # effort of todo
urgency: str # 1,2,3, or 4
recurrence: str # in the format <number><m/h/d/w>
due: str # date in format "{day} {Month} {hours:min}"
status: str # PENDING, OVERDUE, or COMPLETED
tags: List[str] # A list of tags associated with the todo
todos: List[Todo] # List of child todos

Todo Methods

add_sibling() -> Todo:
# Adds a sibling todo and returns it

add_todo(index: int = 0, inherit: bool = False)
# Add a child todo in the preferred index
# pass inherit=True if you want to copy the parent's vars values (except the description)

toggle_complete() ->  bool
# Toggles the todo between complete/incomplete and returns True if marked as completed

increase_urgency() -> None
# increases the urgency by 1. The maximum value is 4

decrease_urgency() -> None
# decreases the urgency by 1. The Minimum value is 1 

has_due_date(self) -> bool:
# returns if todo has a due date

is_due_today(self) -> bool:
# returns if the todo is due today

is_completed(self) -> bool:
# returns if the todo is completed

is_pending(self) -> bool:
# returns if the todo is pending

is_overdue(self) -> bool:
# returns if the todo is overdue

# ... more below

Result (class)

Now that we know some basic methods of the Workspace and Todo classes, I need you to meet the Result class which gets returned if you make changes to the Workspace and Todo class

Variables

ok: bool # if the operation was successful
cancel_op: bool # if true, the operation was not okay and the node will be removed 
message: str | None # Any additional messages

More common methods for Workspace and Todo classes:

shift_up() -> None
# shifts item up in the list if possible

shift_down() -> None:
# shifts item down in the list if possible

prev_sibling() -> Optional[T] # T can be either workspace/todo
# returns previous/upper sibling if there is one else none

next_sibling() -> Optional[T] # T can be either workspace/todo
# returns next/lower sibling if there is one else none

drop() -> None
# removes/delete the current item

sort(attr: str) -> None
# sorts the sibling with the given attr
# You can get the sortable keys of a model with its variable `sortable_fields`
# Actually you can just use any variable except `tags` in todo because idk if todos can be sorted based on their tags :)
# Feel free to open a PR if you think there could be good implementation

edit(key: str, value: str) -> Result
# Edits the given attribute (key) to a new value (value) and returns a Result class
# Edits can fail due to several reasons such as duplicate description, wrong date format, etc