self.comment = comment
self.visible = True
- self.parents = []
+ self.dependers = []
@classmethod
def from_dict(cls, db, d, id_):
subtasks += [self.db.tasks[id_]]
return subtasks
+ @property
+ def subtask_depth(self):
+ def count_depth(task):
+ sub_count = 1
+ for subtask in task.subtasks:
+ sub_count += count_depth(subtask)
+ return sub_count
+ return count_depth(self)
+
def subtask_loop_checker(self):
def f(subtask_ids_now):
loop_msg = "can't set subtask, would create loop"
s = 0
for todo in [todo for todo in self.linked_todos.values()
if self.date in todo.efforts.keys()]:
+ # and not todo.children]:
day_effort = todo.efforts[self.date]
if todo.done:
s += day_effort if day_effort else todo.task.default_effort.at(self.date)
day_tags=None,
importance=1.0,
efforts=None,
- child_ids=None):
+ dep_ids=None):
self.id_ = id_
self.db = db
self.task = task
self._done = done
- self._efforts = efforts if efforts else {}
+ self.efforts = efforts if efforts else {}
self.comment = comment
self.day_tags = day_tags if day_tags else set()
self.importance = importance
- self.child_ids = child_ids if child_ids else []
+ self.dep_ids = dep_ids if dep_ids else []
- self.parents = []
+ self.dependers = []
@classmethod
def from_dict(cls, db, d, id_):
set(d['day_tags']),
d['importance'],
d['efforts'],
- d['children'])
+ d['deps'])
return todo
def to_dict(self):
'day_tags': list(self.day_tags),
'importance': self.importance,
'efforts': self.efforts,
- 'children': self.child_ids}
-
- @property
- def parent(self):
- return self.parents[0] if len(self.parents) > 0 else None
+ 'deps': self.dep_ids}
@property
def title(self):
return f'{self.earliest_date}:{self.title}'
@property
- def children(self):
- return [self.db.todos[id_] for id_ in self.child_ids]
+ def deps(self):
+ return [self.db.todos[id_] for id_ in self.dep_ids]
- @children.setter
- def children(self, children):
- self.child_ids = [child.id_ for child in children]
+ @deps.setter
+ def deps(self, deps):
+ self.dep_ids = [dep.id_ for dep in deps]
@property
def default_effort(self):
@property
def done(self):
- if len(self.children) > 0:
- for child in self.children:
- if not child.done:
- return False
- return True
- else:
- return self._done
+ return self.deps_done and self._done
@done.setter
def done(self, doneness):
self._done = doneness
@property
- def efforts(self):
- if self.children:
- efforts = {}
- for date in self._efforts.keys():
- efforts[date] = None
- for child in self.children:
- to_add = None
- for date, effort in child.efforts.items():
- if not date in efforts.keys():
- efforts[date] = None
- if effort is not None:
- to_add = effort / len(child.parents)
- elif child.done:
- to_add = child.task.default_effort.at(date) / len(child.parents)
- if to_add is not None:
- if efforts[date] is not None:
- efforts[date] += to_add
- else:
- efforts[date] = to_add
- return efforts
+ def deps_done(self):
+ if len(self.deps) > 0:
+ for dep in self.deps:
+ if not dep.done:
+ return False
+ return True
+
+ @property
+ def dep_efforts(self):
+ dep_efforts = 0
+ if self.deps:
+ for dep in self.deps:
+ dep_efforts += dep.all_days_effort
+ dep_efforts += dep.dep_efforts
+ return dep_efforts
+
+ def depender_path(self, dep):
+ if self.dependers:
+ return f'Y{depender.depender_path()}:{self.title}Y'
else:
- return self._efforts
+ return f'X{self.title}X'
- @efforts.setter
- def efforts(self, efforts_dict):
- self._efforts = efforts_dict
+ @property
+ def depender_paths(self):
+ paths = []
+ for depender in self.dependers:
+ if len(depender.depender_paths) == 0:
+ paths += [[depender]]
+ else:
+ for path in depender.depender_paths:
+ paths += [path + [depender]]
+ return paths
@property
def all_days_effort(self):
for tag in t.tags.now:
self.t_tags.add(tag)
for task in self.tasks.values():
- for child in task.subtasks:
- child.parents += [task]
+ for dep in task.subtasks:
+ dep.dependers += [task]
for id_, todo_dict in d['todos'].items():
todo = self.add_todo(todo_dict, id_, link_into_day=False)
for tag in todo.day_tags:
self.t_tags.add(tag)
for todo in self.todos.values():
- for child in todo.children:
- child.parents += [todo]
+ for dep in todo.deps:
+ dep.dependers += [todo]
for date, day_dict in d['days'].items():
self.add_day(dict_source=day_dict, date=date)
for date in todo.efforts.keys():
if not date in self.days.keys():
self.add_day(date)
- # if not todo in self.days[date].linked_todos_as_list:
- # self.days[date].linked_todos_as_list += [todo]
self.days[date].linked_todos_as_list += [todo]
self.set_visibilities()
task.comment = comment
return task
- def add_todo(self, todo_dict=None, id_=None, task=None, efforts=None, link_into_day=True):
+ def add_todo(self, todo_dict=None, id_=None, task=None, efforts=None, link_into_day=True, adopt_if_possible=True):
id_ = id_ if id_ else str(uuid4())
if todo_dict:
todo = Todo.from_dict(self, todo_dict, id_)
elif task and efforts:
todo = Todo(self, id_, task, efforts=efforts)
- children = []
- for child_task in task.subtasks:
- # if Todo expects chuldren, adopt any compatibles found in DB.selected_date
- # before creating new child Todos
- child_todo = None
- if list(efforts.keys())[0] == self.selected_date:
+ deps = []
+ for dep_task in task.subtasks:
+ # if Todo expects dependencies, adopt any compatibles found in DB.selected_date
+ # before creating new depended Todos
+ dep_todo = None
+ if adopt_if_possible and list(efforts.keys())[0] == self.selected_date:
adoptable_todos = [t for t in self.selected_day.linked_todos_as_list
- if t.task.id_ == child_task.id_]
+ if t.task.id_ == dep_task.id_]
if len(adoptable_todos) > 0:
- child_todo = adoptable_todos[0]
- if not child_todo:
- child_todo = self.add_todo(task=child_task,
- efforts=efforts, link_into_day=link_into_day)
- children += [child_todo]
- todo.child_ids = [child.id_ for child in children]
+ dep_todo = adoptable_todos[0]
+ if not dep_todo:
+ dep_todo = self.add_todo(task=dep_task, efforts=efforts,
+ link_into_day=link_into_day,
+ adopt_if_possible=adopt_if_possible)
+ deps += [dep_todo]
+ todo.dep_ids = [dep.id_ for dep in deps]
self.todos[id_] = todo
if link_into_day:
self.selected_day.linked_todos_as_list += [todo]
todo = self._update_todo_shared(id_, done, comment, importance)
todo.efforts[date] = effort
- def update_todo(self, id_, efforts, done, comment, tags, importance, children):
+ def update_todo(self, id_, efforts, done, comment, tags, importance, deps):
todo = self._update_todo_shared(id_, done, comment, importance)
- if len(efforts) == 0 and not todo.children:
+ if len(efforts) == 0 and not todo.deps:
raise PlomException('todo must have at least one effort!')
- todo.children = children
+ todo.deps = deps
todo.efforts = efforts
for date in todo.efforts.keys():
if not date in self.days.keys():
dates_to_delete += [date]
for date in dates_to_delete:
self.delete_effort(todo, date, force=True)
- for parent in todo.parents:
- parent.child_ids.remove(todo.id_)
+ for depender in todo.dependers:
+ depender.dep_ids.remove(todo.id_)
del self.todos[id_]
def delete_task(self, id_):
def show_do_todos(self, sort_order=None):
prev_date_str, next_date_str = self.neighbor_dates()
+ adoptable_past_todos = []
+ for todo in self.todos.values():
+ if todo.done\
+ or (not todo.visible)\
+ or todo.earliest_date >= self.selected_date:
+ continue
+ adoptable_past_todos += [todo]
todos = [t for t in self.selected_day.linked_todos_as_list
- if t.visible
- and not t.children]
+ if t.visible]
+ # and not t.deps]
if sort_order == 'title':
todos.sort(key=lambda t: t.task.title.then)
elif sort_order == 'done':
filter_and=self.tag_filter_and,
filter_not=self.tag_filter_not,
prev_date=prev_date_str,
+ adoptable_past_todos=adoptable_past_todos,
next_date=next_date_str,
+ all_tasks=[t for t in self.tasks.values()],
todos=todos,
sort=sort_order,
hide_done=self.hide_done)
- def show_todo(self, id_, search, start_date, end_date):
+ def show_todo(self, id_, start_date, end_date):
todo = self.todos[id_]
filtered_tasks = [t for t in self.tasks.values()
if t != todo.task]
todo=todo,
filtered_todos=date_filtered_todos,
filtered_tasks=filtered_tasks,
- child_todos=todo.children,
+ dep_todos=todo.deps,
start_date=start_date,
end_date=end_date)
filtered_tasks=filtered_tasks,
task=task)
- def show_tasks(self, expand_uuid):
- expanded_tasks = {}
- if expand_uuid:
- for uuid in self.tasks[expand_uuid].subtask_ids.now:
- expanded_tasks[uuid] = self.tasks[uuid]
- return j2env.get_template('tasks.html').render(
- db=self,
- filter_and=self.tag_filter_and,
- filter_not=self.tag_filter_not,
- expand_uuid=expand_uuid,
- expanded_tasks=expanded_tasks)
-
- def show_pick_tasks(self, search, hide_chosen_tasks, sort_order=None):
- prev_date_str, next_date_str = self.neighbor_dates()
-
- chosen_todos = self.selected_day.linked_todos_as_list
-
- relevant_todos = []
- for todo in self.todos.values():
- if todo.done\
- or (not todo.visible)\
- or (not todo.matches(search))\
- or todo.earliest_date >= self.selected_date:
- continue
- relevant_todos += [todo]
-
- filtered_tasks = []
- chosen_tasks = [todo.task for todo in self.selected_day.linked_todos_as_list]
- for uuid, task in self.tasks.items():
- if (not task.visible)\
- or (not task.matches(search))\
- or (hide_chosen_tasks and task in chosen_tasks):
- continue
+ def show_tasks(self, search, sort_order=None):
+ filtered_tasks = []
+ for task in [t for t in self.tasks.values() if (not search) or t.matches(search)]:
filtered_tasks += [task]
-
if sort_order == 'title':
- chosen_todos.sort(key=lambda t: t.title)
- relevant_todos.sort(key=lambda t: t.dated_title)
- tasks.sort(key=lambda t: t.title.then)
- elif sort_order == 'effort':
- chosen_todos.sort(key=lambda t:
- t.day_effort if t.day_effort else (t.default_effort if t.done else 0),
- reverse=True)
- relevant_todos.sort(key=lambda t: t.all_days_effort, reverse=True)
- filtered_tasks.sort(key=lambda t: t.default_effort.then, reverse=True)
-
- return j2env.get_template('pick_tasks.html').render(
+ filtered_tasks.sort(key=lambda t: t.title.now)
+ elif sort_order == 'default_effort':
+ filtered_tasks.sort(key=lambda t: t.default_effort.now, reverse=True)
+ elif sort_order == 'depth':
+ filtered_tasks.sort(key=lambda t: t.subtask_depth, reverse=True)
+ return j2env.get_template('tasks.html').render(
sort=sort_order,
+ tasks=filtered_tasks,
tags=self.t_tags,
- chosen_todos=chosen_todos,
filter_and=self.tag_filter_and,
filter_not=self.tag_filter_not,
- day=self.selected_day,
- prev_date=prev_date_str,
- next_date=next_date_str,
- all_tasks=[t for t in self.tasks.values()],
- filtered_tasks=filtered_tasks,
- hide_chosen_tasks=hide_chosen_tasks,
- relevant_todos=relevant_todos,
search=search)
+ # def show_pick_tasks(self, search, hide_chosen_tasks, sort_order=None):
+ # prev_date_str, next_date_str = self.neighbor_dates()
+
+ # chosen_todos = self.selected_day.linked_todos_as_list
+
+ # relevant_todos = []
+ # for todo in self.todos.values():
+ # if todo.done\
+ # or (not todo.visible)\
+ # or (not todo.matches(search))\
+ # or todo.earliest_date >= self.selected_date:
+ # continue
+ # relevant_todos += [todo]
+
+ # filtered_tasks = []
+ # chosen_tasks = [todo.task for todo in self.selected_day.linked_todos_as_list]
+ # for uuid, task in self.tasks.items():
+ # if (not task.visible)\
+ # or (not task.matches(search))\
+ # or (hide_chosen_tasks and task in chosen_tasks):
+ # continue
+ # filtered_tasks += [task]
+
+ # if sort_order == 'title':
+ # chosen_todos.sort(key=lambda t: t.title)
+ # relevant_todos.sort(key=lambda t: t.dated_title)
+ # tasks.sort(key=lambda t: t.title.then)
+ # elif sort_order == 'effort':
+ # chosen_todos.sort(key=lambda t:
+ # t.day_effort if t.day_effort else (t.default_effort if t.done else 0),
+ # reverse=True)
+ # relevant_todos.sort(key=lambda t: t.all_days_effort, reverse=True)
+ # filtered_tasks.sort(key=lambda t: t.default_effort.then, reverse=True)
+
+ # return j2env.get_template('pick_tasks.html').render(
+ # sort=sort_order,
+ # tags=self.t_tags,
+ # chosen_todos=chosen_todos,
+ # filter_and=self.tag_filter_and,
+ # filter_not=self.tag_filter_not,
+ # day=self.selected_day,
+ # prev_date=prev_date_str,
+ # next_date=next_date_str,
+ # all_tasks=[t for t in self.tasks.values()],
+ # filtered_tasks=filtered_tasks,
+ # hide_chosen_tasks=hide_chosen_tasks,
+ # relevant_todos=relevant_todos,
+ # search=search)
+
# helpers
def set_visibilities(self):
if site in {'calendar', 'todo'}:
redir_params += [('end', postvars.get('end', '-'))]
redir_params += [('start', postvars.get('start', '-'))]
- if site in {'todo', 'pick_tasks'}:
- redir_params += [('search', postvars.get('search', ''))]
- redir_params += [('search', postvars.get('search', ''))]
- redir_params += [('search', postvars.get('search', ''))]
+ # if site in {'tasks', 'pick_tasks'}:
+ # redir_params += [('search', postvars.get('search', ''))]
if postvars.has('filter'):
postvars.set('return_to', '')
- if 'todo' == site:
+ if 'tasks' == site:
+ redir_params += [('search', postvars.get('search', ''))]
+
+ elif 'todo' == site:
todo_id = postvars.get('todo_id')
redir_params += [('id', todo_id)]
old_todo = db.todos[todo_id] if todo_id in db.todos.keys() else None
raise PlomException(f'bad date string')
latest_date = date
efforts[date] = None
- if not (old_todo and old_todo.children):
+ if not (old_todo and old_todo.deps):
efforts[date] = postvars.get_at_index('effort', i, on_empty=None,
float_if_possible=True)
if postvars.has('delete'):
for date in postvars.get_all('delete_effort'):
db.delete_effort(old_todo, date)
del efforts[date]
- children = [db.todos[id_] for id_ in postvars.get_all('adopt_child', [])
- if id_ in db.todos.keys()]
- for child in children:
- if not todo_id in [t.id_ for t in child.parents]:
- child.parents += [db.todos[todo_id]]
- tasks_to_birth = [db.tasks[id_] for id_ in postvars.get_all('birth_child', [])]
+ deps = [db.todos[id_] for id_ in postvars.get_all('adopt_dep', [])
+ if id_ in db.todos.keys()]
+ for dep in deps:
+ if not todo_id in [t.id_ for t in dep.dependers]:
+ dep.dependers += [db.todos[todo_id]]
+ tasks_to_birth = [db.tasks[id_] for id_ in postvars.get_all('birth_dep', [])]
for task in tasks_to_birth:
- children += [db.add_todo(task=task, efforts={latest_date: None})]
+ deps += [db.add_todo(task=task, efforts={latest_date: None})]
db.update_todo(id_=todo_id,
efforts=efforts,
done=postvars.has('done'),
comment=postvars.get('comment', ''),
tags=postvars.get_all('tag', []),
importance=float(postvars.get('importance')),
- children=children)
+ deps=deps)
elif 'task' == site:
task_id = postvars.get('task_id')
db.add_todo(task=task, efforts={postvars.get('selected_date'): None})
redir_params += [('id', task_id)]
- elif 'pick_tasks' == site:
- redir_params += [('hide_chosen_tasks', int(postvars.has('hide_chosen_tasks')))]
- if postvars.has('update'):
- db.selected_date = postvars.get('date')
- todos_to_shrink = []
- todos_to_delete = []
- for todo in db.selected_day.linked_todos_as_list:
- if todo.visible and not todo.id_ in postvars.get_all('chosen_todo', []):
- if len(todo.comment) > 0\
- or len(todo.day_tags) > 0\
- or not todo.is_effort_removable(db.selected_date):
- raise PlomException('will not remove effort of preserve-worthy values')
- if len(todo.efforts) > 1:
- todos_to_shrink += [todo]
- else:
- todos_to_delete += [todo]
- for todo in todos_to_shrink:
- db.delete_effort(todo, db.selected_date)
- for todo in todos_to_delete:
- db.delete_todo(todo.id_)
- for id_ in postvars.get_all('choose_task', []):
- db.add_todo(task=db.tasks[id_], efforts={db.selected_date: None})
- for id_ in postvars.get_all('choose_todo', []):
- db.todos[id_].efforts[db.selected_date] = None
+ # elif 'pick_tasks' == site:
+ # redir_params += [('hide_chosen_tasks', int(postvars.has('hide_chosen_tasks')))]
+ # if postvars.has('update'):
+ # db.selected_date = postvars.get('date')
+ # todos_to_shrink = []
+ # todos_to_delete = []
+ # for todo in db.selected_day.linked_todos_as_list:
+ # if todo.visible and not todo.id_ in postvars.get_all('chosen_todo', []):
+ # if len(todo.comment) > 0\
+ # or len(todo.day_tags) > 0\
+ # or not todo.is_effort_removable(db.selected_date):
+ # raise PlomException('will not remove effort of preserve-worthy values')
+ # if len(todo.efforts) > 1:
+ # todos_to_shrink += [todo]
+ # else:
+ # todos_to_delete += [todo]
+ # for todo in todos_to_shrink:
+ # db.delete_effort(todo, db.selected_date)
+ # for todo in todos_to_delete:
+ # db.delete_todo(todo.id_)
+ # for id_ in postvars.get_all('choose_task', []):
+ # db.add_todo(task=db.tasks[id_], efforts={db.selected_date: None})
+ # for id_ in postvars.get_all('choose_todo', []):
+ # db.todos[id_].efforts[db.selected_date] = None
elif 'do_todos' == site:
redir_params += [('hide_done', int(postvars.has('hide_done')))]
db.selected_date = postvars.get('date')
redir_params += [('date', db.selected_date)]
db.selected_day.comment = postvars.get('day_comment', '')
+ task_id = postvars.get('choose_task', None)
+ if task_id:
+ if task_id not in db.tasks.keys():
+ raise PlomException('illegal task ID entered')
+ db.add_todo(task=db.tasks[task_id], efforts={db.selected_date: None},
+ adopt_if_possible=(not postvars.has('dont_adopt')))
+ for id_ in postvars.get_all('choose_todo', []):
+ db.todos[id_].efforts[db.selected_date] = None
for i, todo_id in enumerate(postvars.get_all('todo_id', [])):
old_todo = db.todos[todo_id]
done = todo_id in postvars.get_all('done', [])
selected_date = tag_filter_and = tag_filter_not = None
hide_unchosen = hide_done = False
return_to = params.get('return_to', '')
- if site in {'do_todos', 'pick_tasks', 'calendar', 'task'}:
+ if site in {'do_todos', 'calendar', 'task'}:
selected_date = params.get_cookied('date')
- if site in {'do_todos', 'pick_tasks'}:
+ if site in {'do_todos', 'tasks'}:
tag_filter_and = params.get_cookied_chain('and_tag', prefix=site)
tag_filter_not = params.get_cookied_chain('not_tag', prefix=site)
if 'do_todos' == site:
db = TodoDB(selected_date, tag_filter_and, tag_filter_not, hide_unchosen, hide_done)
if site in {'todo', 'task'}:
id_ = params.get('id')
- if site in {'todo', 'pick_tasks'}:
- search = params.get('search', '')
- if site in {'do_todos', 'pick_tasks'}:
+ if site in {'do_todos', 'tasks'}:
sort_order = params.get_cookied('sort', prefix=site)
if site in {'', 'calendar', 'todo'}:
start_date = params.get_cookied('start', prefix=site)
end_date = params.get_cookied('end', prefix=site)
if 'reset_cookie' == site:
cookie_db = { # sensible defaults
- params.cookie_key_from_params_key('pick_tasks', 'and_tag'): ['default'],
- params.cookie_key_from_params_key('pick_tasks', 'not_tag'): ['ignore'],
+ # params.cookie_key_from_params_key('pick_tasks', 'and_tag'): ['default'],
+ # params.cookie_key_from_params_key('pick_tasks', 'not_tag'): ['ignore'],
params.cookie_key_from_params_key('todo', 'and_tag'): ['default'],
params.cookie_key_from_params_key('todo', 'not_tag'): ['ignore'],
params.cookie_key_from_params_key('todo', 'start'): 'yesterday',
page = db.show_message('cookie unset!')
elif 'do_todos' == site:
page = db.show_do_todos(sort_order)
- elif 'pick_tasks' == site:
- hide_chosen_tasks = params.get('hide_chosen_tasks', False)
- page = db.show_pick_tasks(search, hide_chosen_tasks, sort_order)
+ # elif 'pick_tasks' == site:
+ # hide_chosen_tasks = params.get('hide_chosen_tasks', False)
+ # page = db.show_pick_tasks(search, hide_chosen_tasks, sort_order)
elif site == 'todo':
- page = db.show_todo(id_, search, start_date, end_date)
+ page = db.show_todo(id_, start_date, end_date)
elif 'task' == site:
page = db.show_task(id_)
elif 'tasks' == site:
- expand_uuid = params.get('expand_uuid')
- page = db.show_tasks(expand_uuid)
+ search = params.get('search', '')
+ page = db.show_tasks(search, sort_order)
elif 'add_task' == site:
page = db.show_task(None)
else: # 'calendar' == site