class AttributeWithHistory:
- def __init__(self, default_if_empty, history=None, then_date='2000-01-01', set_check=None, alt_get=None):
+ def __init__(self, default_if_empty, history=None, then_date='2000-01-01', set_check=None):
self.default = default_if_empty
self.then_date = then_date
self.history = history if history else {}
self.set_check = set_check
- self.alt_get = alt_get
def set(self, value):
+ print("DEBUG set", value, "HAS SET CHECK?", self.set_check)
if self.set_check:
+ print("DEBUG set CALLED SET CHECK")
self.set_check(value)
keys = sorted(self.history.keys())
if len(self.history) == 0 or value != self.history[keys[-1]]:
self.history[today_date(with_time=True)] = value
def at(self, queried_date):
- if self.alt_get:
- ret = self.alt_get('at', queried_date)
- if ret is not None:
- return ret
if 0 == len(self.history):
return self.default
ret = self.history[sorted(self.history.keys())[0]]
@property
def now(self):
- if self.alt_get:
- ret = self.alt_get('now')
- if ret is not None:
- return ret
keys = sorted(self.history.keys())
return self.default if 0 == len(self.history) else self.history[keys[-1]]
@property
def then(self):
- if self.alt_get:
- ret = self.alt_get('then')
- if ret is not None:
- return ret
return self.at(self.then_date)
-class Task:
+class TaskLike:
+
+ def __init__(self, db, id_, comment):
+ self.db = db
+ self.id_ = id_
+ self.comment = comment
+ self.dependers = []
+
+ @property
+ def visible(self):
+ visible_by_and = 0 == len([tag for tag in self.db.tag_filter_and
+ if not tag in self.tags])
+ visible_by_not = 0 == len([tag for tag in self.db.tag_filter_not
+ if tag in self.tags])
+ return visible_by_and and visible_by_not
+
+ @property
+ def deps_depth(self):
+ if len(self.deps) == 0:
+ return 0
+ return 1 + max([d.deps_depth for d in self.deps])
+
+ @property
+ def deps_chain(self):
+ all_deps = set()
+ def add_deps(todo, all_deps):
+ for dep in todo.deps:
+ all_deps.add(dep)
+ add_deps(dep, all_deps)
+ add_deps(self, all_deps)
+ chain = list(all_deps)
+ chain.sort(key=lambda t: t.deps_depth)
+ return chain
+
+
+
+class Task(TaskLike):
def __init__(self,
db,
title_history=None,
tags_history=None,
default_effort_history=None,
- subtask_ids_history=None,
+ dep_ids_history=None,
comment=''):
- self.db = db
- self.id_ = id_
+ super().__init__(db, id_, comment)
self.title = AttributeWithHistory('', title_history, self.db.selected_date)
self.tags = AttributeWithHistory(set(), tags_history, self.db.selected_date)
- self.default_effort = AttributeWithHistory(0.0, default_effort_history, self.db.selected_date, alt_get=self.subtasks_sum_maker())
- self.subtask_ids = AttributeWithHistory(set(), subtask_ids_history, self.db.selected_date, set_check=self.subtask_loop_checker())
- self.comment = comment
-
- self.visible = True
- self.dependers = []
+ self.default_effort = AttributeWithHistory(0.0, default_effort_history, self.db.selected_date)
+ self.dep_ids = AttributeWithHistory(set(), dep_ids_history, self.db.selected_date, set_check=self.dep_loop_checker())
@classmethod
def from_dict(cls, db, d, id_):
d['title_history'],
{k: set(v) for k, v in d['tags_history'].items()},
d['default_effort_history'],
- {k: set(v) for k, v in d['subtasks_history'].items()},
+ {k: set(v) for k, v in d['deps_history'].items()},
d['comment'])
return t
'title_history': self.title.history,
'default_effort_history': self.default_effort.history,
'tags_history': {k: list(v) for k, v in self.tags.history.items()},
- 'subtasks_history': {k: list(v) for k, v in self.subtask_ids.history.items()},
+ 'deps_history': {k: list(v) for k, v in self.dep_ids.history.items()},
'comment': self.comment,
}
@property
- def subtasks(self):
- subtasks = []
- for id_ in self.subtask_ids.now:
+ def deps(self):
+ deps = []
+ for id_ in self.dep_ids.now:
if len(id_) == 0:
continue
- subtasks += [self.db.tasks[id_]]
- return subtasks
+ elif id_ not in self.db.tasks.keys():
+ raise PlomException(f'dep referenced on Task {self.id_} not found: {id_}')
+ deps += [self.db.tasks[id_]]
+ return deps
@property
- def subtask_depth(self):
- def count_depth(task):
+ def deps_weight(self):
+ def count_weight(task):
sub_count = 1
- for subtask in task.subtasks:
- sub_count += count_depth(subtask)
+ for dep in task.deps:
+ sub_count += count_weight(dep)
return sub_count
- return count_depth(self)
+ return count_weight(self)
- def subtask_loop_checker(self):
- def f(subtask_ids_now):
- loop_msg = "can't set subtask, would create loop"
- for id_ in subtask_ids_now:
+ def dep_loop_checker(self):
+ def f(dep_ids_now):
+ loop_msg = "can't set dep, would create loop"
+ for id_ in dep_ids_now:
if id_ == self.id_:
raise PlomException(loop_msg)
elif id_ in self.db.tasks.keys():
- subtask = self.db.tasks[id_]
- f(subtask.subtask_ids.now)
+ dep = self.db.tasks[id_]
+ f(dep.dep_ids.now)
return f
- def subtasks_sum_maker(self):
- def f(f_name, queried_date=None):
- subtask_ids_to_check = getattr(self.subtask_ids, f_name)
- if queried_date:
- subtasks = [self.db.tasks[id_] for id_ in subtask_ids_to_check(queried_date)]
- else:
- subtasks = [self.db.tasks[id_] for id_ in subtask_ids_to_check]
- if len(self.subtasks) > 0:
- summe = 0
- for subtask in self.subtasks:
- if queried_date:
- to_add = getattr(subtask.default_effort, f_name)
- summe += to_add(queried_date)
- else:
- summe += getattr(subtask.default_effort, f_name)
- return summe
- return None
- return f
-
def matches(self, search):
if search is None:
return False
return search in self.title.now or search in self.comment or search in '$'.join(self.tags.now)
+
class Day:
def __init__(self, db, date, comment=''):
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)
def todos_sum(self):
return self._todos_sum()
+ def sorted_todos(self, done, is_tree_shaped, sort_order, legal_keys):
+ todos = [t for t in self.linked_todos_as_list if t.visible and t.done == done]
+ reverse = False
+ sort_column = sort_order[:]
+ if sort_order and '-' == sort_order[0]:
+ reverse = True
+ sort_column = sort_order[1:]
+ if sort_column in legal_keys:
+ todos.sort(key=lambda t: getattr(t, sort_column))
+ if reverse:
+ todos.reverse()
+ if is_tree_shaped:
+ def walk_tree(todo, sorted_todos):
+ todo.deps = [t for t in sorted_todos if t in todo.deps]
+ for dep in [t for t in sorted_todos if t in todo.deps]:
+ walk_tree(dep, sorted_todos)
+ if done:
+ trunk = [t for t in todos if len([td for td in t.dependers if td.done]) == 0]
+ else:
+ trunk = [t for t in todos if len(t.dependers) == 0]
+ for node in trunk:
+ walk_tree(node, todos)
+ todos = trunk
+ return todos
+
+
-class Todo:
+class Todo(TaskLike):
def __init__(self,
db,
importance=1.0,
efforts=None,
dep_ids=None):
- self.id_ = id_
- self.db = db
+ super().__init__(db, id_, comment)
self.task = task
self._done = done
self.efforts = efforts if efforts else {}
- self.comment = comment
self.day_tags = day_tags if day_tags else set()
self.importance = importance
- self.dep_ids = dep_ids if dep_ids else []
-
- self.dependers = []
+ self._dep_ids = dep_ids if dep_ids else []
+ self.already_listed = False
+ self.been_observed = False
@classmethod
def from_dict(cls, db, d, id_):
'day_tags': list(self.day_tags),
'importance': self.importance,
'efforts': self.efforts,
- 'deps': self.dep_ids}
+ 'deps': self._dep_ids}
@property
def title(self):
- return self.task.title.at(self.earliest_date)
+ return self.task.title.at(self.db.selected_date)
@property
def dated_title(self):
@property
def deps(self):
- return [self.db.todos[id_] for id_ in self.dep_ids]
+ return [self.db.todos[id_] for id_ in self._dep_ids]
@deps.setter
def deps(self, deps):
- self.dep_ids = [dep.id_ for dep in deps]
+ self._dep_ids = [dep.id_ for dep in deps]
+ def f(deps):
+ loop_msg = "can't set dep, would create loop"
+ for dep in deps:
+ if dep == self:
+ raise PlomException(loop_msg)
+ else:
+ f(dep.deps)
+ f(self.deps)
@property
def default_effort(self):
paths += [path + [depender]]
return paths
+ @property
+ def shortened_depender_paths(self):
+ new_paths = []
+ for path in self.depender_paths:
+ new_path = []
+ for i, step in enumerate(path):
+ next_step = None if len(path) <= i+1 else path[i+1]
+ for distinct_path in new_paths:
+ if len(distinct_path) >= i+2 and distinct_path[i+1] == next_step:
+ step = None
+ new_path += [step]
+ new_paths += [new_path]
+ return new_paths
+
@property
def all_days_effort(self):
total = 0
def day_effort(self):
return self.efforts[self.db.selected_date]
+ @property
+ def effort_at_selected_date(self):
+ if self.db.selected_date in self.efforts.keys() and self.day_effort is not None:
+ return self.day_effort
+ else:
+ return self.task.default_effort.then
+
@property
def day(self):
return self.db.days[self.earliest_date]
def latest_date(self):
return self.sorted_effort_dates[-1]
+ @property
+ def has_dependers(self):
+ return len(self.dependers) > 0
+
+ @property
+ def has_deps(self):
+ return len(self.deps) > 0
+
+ @property
+ def sort_done(self):
+ return self.day_effort if self.day_effort else 0
+
+ @property
+ def family_effort(self):
+ return self.effort_at_selected_date + self.dep_efforts
+
+ def observe(self):
+ self.been_observed = True
+ return ''
+
+
class TodoDB(PlomDB):
def __init__(self,
selected_date=None,
tag_filter_and = None,
- tag_filter_not = None,
- hide_unchosen=False,
- hide_done=False):
+ tag_filter_not = None):
self.selected_date = selected_date if selected_date else today_date()
self.tag_filter_and = tag_filter_and if tag_filter_and else []
self.tag_filter_not = tag_filter_not if tag_filter_not else []
- self.hide_unchosen = hide_unchosen
- self.hide_done = hide_done
self.days = {}
self.tasks = {}
for tag in t.tags.now:
self.t_tags.add(tag)
for task in self.tasks.values():
- for dep in task.subtasks:
+ for dep in task.deps:
dep.dependers += [task]
for id_, todo_dict in d['todos'].items():
self.add_day(date)
self.days[date].linked_todos_as_list += [todo]
- self.set_visibilities()
+ # self.set_visibilities()
def to_dict(self):
d = {'tasks': {}, 'days': {}, 'todos': {}}
self.tasks[id_] = t
return t
- def update_task(self, id_, title, default_effort, tags, subtask_ids, comment):
+ def update_task(self, id_, title, default_effort, tags, dep_ids, comment):
task = self.tasks[id_] if id_ in self.tasks.keys() else self.add_task(id_)
task.title.set(title)
task.default_effort.set(default_effort)
task.tags.set(tags)
- task.subtask_ids.set(subtask_ids)
+ task.dep_ids.set(dep_ids)
task.comment = comment
return task
elif task and efforts:
todo = Todo(self, id_, task, efforts=efforts)
deps = []
- for dep_task in task.subtasks:
+ for dep_task in task.deps:
# if Todo expects dependencies, adopt any compatibles found in DB.selected_date
# before creating new depended Todos
dep_todo = None
link_into_day=link_into_day,
adopt_if_possible=adopt_if_possible)
deps += [dep_todo]
- todo.dep_ids = [dep.id_ for dep in deps]
+ # todo.dep_ids = [dep.id_ for dep in deps]
+ todo.deps = deps
self.todos[id_] = todo
if link_into_day:
self.selected_day.linked_todos_as_list += [todo]
for date in dates_to_delete:
self.delete_effort(todo, date, force=True)
for depender in todo.dependers:
- depender.dep_ids.remove(todo.id_)
+ depender._dep_ids.remove(todo.id_)
del self.todos[id_]
def delete_task(self, id_):
def show_calendar(self, start_date_str, end_date_str):
self.tag_filter_and = ['calendar']
self.tag_filter_not = ['deleted']
- self.set_visibilities()
- start_date_obj, end_date_obj = self.get_limit_days_from_date_strings(start_date_str, end_date_str)
+
+ todays_date_obj = datetime.strptime(today_date(), DATE_FORMAT)
+ yesterdays_date_obj = todays_date_obj - timedelta(1)
+ def get_day_limit_obj(index, day_limit_string):
+ date_obj = datetime.strptime(sorted(self.days.keys())[index], DATE_FORMAT)
+ if day_limit_string and len(day_limit_string) > 0:
+ if day_limit_string in {'today', 'yesterday'}:
+ date_obj = todays_date_obj if day_limit_string == 'today' else yesterdays_date_obj
+ else:
+ date_obj = datetime.strptime(day_limit_string, DATE_FORMAT)
+ return date_obj
+ start_date_obj = get_day_limit_obj(0, start_date_str)
+ end_date_obj = get_day_limit_obj(-1, end_date_str)
+
days_to_show = {}
for n in range(int((end_date_obj - start_date_obj).days) + 1):
date_obj = start_date_obj + timedelta(n)
start_date=start_date_str,
end_date=end_date_str)
- def show_do_todos(self, sort_order=None):
- prev_date_str, next_date_str = self.neighbor_dates()
+ def show_day_todos(self, undone_sort_order=None, done_sort_order=None, is_tree_shaped=False):
+ legal_undone_sort_keys = {'title', 'sort_done', 'default_effort', 'importance'}
+ legal_done_sort_keys = {'title', 'effort_at_selected_date', 'family_effort'}
+
+ current_date = datetime.strptime(self.selected_date, DATE_FORMAT)
+ prev_date = current_date - timedelta(days=1)
+ prev_date_str = prev_date.strftime(DATE_FORMAT)
+ next_date = current_date + timedelta(days=1)
+ next_date_str = next_date.strftime(DATE_FORMAT)
+
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.deps]
- if sort_order == 'title':
- todos.sort(key=lambda t: t.task.title.then)
- elif sort_order == 'done':
- todos.sort(key=lambda t: t.day_effort if t.day_effort else t.default_effort if t.done else 0, reverse=True)
- elif sort_order == 'default_effort':
- todos.sort(key=lambda t: t.default_effort, reverse=True)
- elif sort_order == 'importance':
- todos.sort(key=lambda t: t.importance, reverse=True)
- return j2env.get_template('do_todos.html').render(
+ for todo in [t for t in self.todos.values()
+ if t.visible
+ and (not t.done)
+ and t.earliest_date < self.selected_date]:
+ adoptable_past_todos += [todo]
+ undone_todos = self.selected_day.sorted_todos(False, is_tree_shaped, undone_sort_order,
+ legal_undone_sort_keys)
+ done_todos = self.selected_day.sorted_todos(True, is_tree_shaped, done_sort_order,
+ legal_done_sort_keys)
+
+ return j2env.get_template('day_todos.html').render(
day=self.selected_day,
tags=self.t_tags,
filter_and=self.tag_filter_and,
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)
+ undone_todos=undone_todos,
+ done_todos=done_todos,
+ is_tree_shaped=is_tree_shaped,
+ undone_sort=undone_sort_order,
+ done_sort=done_sort_order)
- def show_todo(self, id_, start_date, end_date):
+ def show_todo(self, id_):
todo = self.todos[id_]
filtered_tasks = [t for t in self.tasks.values()
if t != todo.task]
filtered_todos = [t for t in self.todos.values()
- if t != todo]
-
- # if going into the past, only allow 3-day ranges
- start_day, end_day = self.get_limit_days_from_date_strings(start_date, end_date)
- if start_day < datetime.now() - timedelta(days=2):
- end_day = start_day + timedelta(days=3)
- end_date = end_day.strftime(DATE_FORMAT)
- legal_dates = []
- for n in range(int((end_day - start_day).days) + 1):
- day = start_day + timedelta(n)
- legal_dates += [day.strftime(DATE_FORMAT)]
+ if t != todo
+ and t not in todo.deps]
+
+ legal_dates = list(todo.efforts.keys())
date_filtered_todos = []
for date in legal_dates:
for filtered_todo in filtered_todos:
if date in filtered_todo.efforts.keys():
date_filtered_todos += [filtered_todo]
+ dep_slots = []
+ for dep in todo.task.deps:
+ dep_slots += [{'task': dep,
+ 'todos': [t for t in todo.deps if t.task == dep]}]
+
+ suggested_todos = {}
+ for dep in todo.task.deps:
+ suggested_todos[dep.id_] = [t for t in date_filtered_todos if t.task.id_ == dep.id_]
+ additional_deps = [t for t in todo.deps if not t.task in todo.task.deps]
+
return j2env.get_template('todo.html').render(
tags=self.t_tags,
todo=todo,
filtered_todos=date_filtered_todos,
filtered_tasks=filtered_tasks,
- dep_todos=todo.deps,
- start_date=start_date,
- end_date=end_date)
+ dep_slots=dep_slots,
+ suggested_todos=suggested_todos,
+ additional_deps=additional_deps,
+ dep_todos=todo.deps)
def show_task(self, id_):
task = self.tasks[id_] if id_ else self.add_task()
task.default_effort.set(1.0)
filtered_tasks = [t for t in self.tasks.values()
if t != task
- and (t not in task.subtasks)]
+ and (t not in task.deps)]
+
return j2env.get_template('task.html').render(
selected_date=self.selected_date,
tags=self.t_tags,
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':
+ reverse = False
+ sort_column = sort_order
+ if sort_order and '-' == sort_order[0]:
+ reverse = True
+ sort_column = sort_order[1:]
+ if sort_column == 'title':
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)
+ elif sort_column == 'default_effort':
+ filtered_tasks.sort(key=lambda t: t.default_effort.now)
+ elif sort_column == 'weight':
+ filtered_tasks.sort(key=lambda t: t.deps_weight)
+ if reverse:
+ filtered_tasks.reverse()
return j2env.get_template('tasks.html').render(
sort=sort_order,
tasks=filtered_tasks,
filter_not=self.tag_filter_not,
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):
- for uuid, t in self.tasks.items():
- t.visible = len([tag for tag in self.tag_filter_and if not tag in t.tags.now]) == 0\
- and len([tag for tag in self.tag_filter_not if tag in t.tags.now]) == 0\
- and ((not self.hide_unchosen) or uuid in self.selected_day.todos.keys())
- for todo in self.todos.values():
- todo.visible = len([tag for tag in self.tag_filter_and if not tag in todo.day_tags | todo.task.tags.now ]) == 0\
- and len([tag for tag in self.tag_filter_not if tag in todo.day_tags | todo.task.tags.now ]) == 0\
- and ((not self.hide_done) or (not todo.done))
-
- def get_limit_days_from_date_strings(self, start_date_str, end_date_str):
- todays_date_obj = datetime.strptime(today_date(), DATE_FORMAT)
- yesterdays_date_obj = todays_date_obj - timedelta(1)
- def get_day_limit_obj(index, day_limit_string):
- date_obj = datetime.strptime(sorted(self.days.keys())[index], DATE_FORMAT)
- if day_limit_string and len(day_limit_string) > 0:
- if day_limit_string in {'today', 'yesterday'}:
- date_obj = todays_date_obj if day_limit_string == 'today' else yesterdays_date_obj
- else:
- date_obj = datetime.strptime(day_limit_string, DATE_FORMAT)
- return date_obj
- start_date_obj = get_day_limit_obj(0, start_date_str)
- end_date_obj = get_day_limit_obj(-1, end_date_str)
- return start_date_obj, end_date_obj
-
- def neighbor_dates(self):
- current_date = datetime.strptime(self.selected_date, DATE_FORMAT)
- prev_date = current_date - timedelta(days=1)
- prev_date_str = prev_date.strftime(DATE_FORMAT)
- next_date = current_date + timedelta(days=1)
- next_date_str = next_date.strftime(DATE_FORMAT)
- return prev_date_str, next_date_str
-
class ParamsParser:
self.params = parse_qs(parsed_url_query)
self.cookie_db = cookie_db
- def get(self, key, default=None):
- boolean = bool == type(default)
+ def get(self, key, default=None, as_bool=False):
+ # boolean = bool == type(default)
param = self.params.get(key, [default])[0]
- if boolean:
- param = param != '0'
+ if as_bool:
+ if param == '0':
+ param = False
+ elif param is not None:
+ param = True
return param
def cookie_key_from_params_key(self, prefix, key):
return f'{prefix}:{key}' if prefix else key
- def get_cookied(self, key, default=None, prefix=None):
+ def get_cookied(self, key, default=None, prefix=None, as_bool=False):
cookie_key = self.cookie_key_from_params_key(prefix, key)
- param = self.get(key, default)
+ param = self.get(key, default, as_bool)
if param == '-':
param = None
if cookie_key in self.cookie_db.keys():
return params
+
class PostvarsParser:
def __init__(self, postvars):
raise PlomException('will not remove Task describing existing Todos')
if postvars.get('title', '')\
or postvars.get_all('tag', [])\
- or postvars.get_all('subtask', [])\
+ or postvars.get_all('dep', [])\
or postvars.get('comment', ''):
raise PlomException('will not remove Task of preserve-worthy values')
db.delete_task(task_id)
elif postvars.has('update'):
+ dep_ids = postvars.get_all('dep', [])
+ for id_ in [id_ for id_ in dep_ids if not id_ in db.tasks.keys()]:
+ raise PlomException('submitted illegal dep ID')
task = db.update_task(
id_=task_id,
title=postvars.get('title', ''),
default_effort=postvars.get('default_effort', float_if_possible=True),
tags=postvars.get_all('tag', []),
- subtask_ids=postvars.get_all('subtask', []),
+ dep_ids=dep_ids,
comment=postvars.get('comment', ''))
if postvars.has('add_as_todo'):
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 'do_todos' == site:
- redir_params += [('hide_done', int(postvars.has('hide_done')))]
+ elif 'day_todos' == site:
if postvars.has('update'):
db.selected_date = postvars.get('date')
redir_params += [('date', db.selected_date)]
params = ParamsParser(parsed_url.query, cookie_db)
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', 'calendar', 'task'}:
+ if site in {'day_todos', 'calendar', 'task'}:
selected_date = params.get_cookied('date')
- if site in {'do_todos', 'tasks'}:
+ if site in {'day_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:
- hide_done = params.get('hide_done', False)
- db = TodoDB(selected_date, tag_filter_and, tag_filter_not, hide_unchosen, hide_done)
+ db = TodoDB(selected_date, tag_filter_and, tag_filter_not)
if site in {'todo', 'task'}:
id_ = params.get('id')
- 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('day_todos', 'tree'): True,
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',
params.cookie_key_from_params_key('todo', 'end'): 'today'}
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 'day_todos' == site:
+ is_tree_shaped = params.get_cookied('tree', prefix=site, as_bool=True)
+ undone_sort_order = params.get_cookied('undone_sort', prefix=site)
+ done_sort_order = params.get_cookied('done_sort', prefix=site)
+ page = db.show_day_todos(undone_sort_order, done_sort_order, is_tree_shaped)
elif site == 'todo':
- page = db.show_todo(id_, start_date, end_date)
+ page = db.show_todo(id_)
elif 'task' == site:
page = db.show_task(id_)
elif 'tasks' == site:
+ sort_order = params.get_cookied('sort', prefix=site)
search = params.get('search', '')
page = db.show_tasks(search, sort_order)
elif 'add_task' == site:
page = db.show_task(None)
else: # 'calendar' == site
+ start_date = params.get_cookied('start', prefix=site)
+ end_date = params.get_cookied('end', prefix=site)
page = db.show_calendar(start_date, end_date)
self.set_cookie(config['cookie_name'], config['cookie_path'], cookie_db)
--- /dev/null
+{% extends 'base.html' %}
+
+
+
+{% block css %}
+td.checkbox { text-align: center; }
+td { vertical-align: middle; }
+td button { padding: 0em; }
+th.centered { text-align: center; }
+ul { padding-left: 1.5em; margin: 0; }
+details > summary.todo {
+ list-style-type: ' ';
+}
+details > summary.has_dependers {
+ list-style-type: '[+]:';
+}
+details[open] > summary.has_dependers {
+ list-style-type: '[▼]:';
+}
+details > summary.has_deps::after {
+ content: ':[+]';
+}
+details[open] > summary.has_deps::after {
+ content: ':[▼]';
+}
+table.undone_todos tr.deps_undone {
+ background-color: #cccccc;
+}
+details.adoptables {
+ margin-bottom: 1em;
+}
+details.adoptables summary span {
+ background-color: #cccccc;
+}
+table.undone_todos tr td {
+ border-bottom: 1px dotted black;
+}
+td.left { text-align: left; }
+td.unbreakable { white-space: nowrap; }
+{% endblock %}
+
+
+
+{% macro todo_title_expandable(todo, show_deps_doneness, ignore=0) %}
+{% if todo.has_dependers or todo.has_deps %}
+<details>
+<summary class="todo {% if todo.has_dependers %}has_dependers{% endif %} {% if todo.has_deps %}has_deps{% endif %}">
+{% else %}
+
+{% endif %}
+<a href="todo?id={{todo.id_}}&return_to=day_todos">{{todo.title|e}}</a>
+{% if todo.has_dependers or todo.has_deps %}
+</summary>
+{% if todo.has_dependers %}
+dependers:
+<ul>
+{% for path in todo.depender_paths %}
+<li>{% for depender_todo in path %}<a href="todo?id={{depender_todo.id_}}&return_to=day_todos">{{ depender_todo.title|e }}</a>{% if not loop.last %}:{% endif %}{% endfor %}
+{% endfor %}
+</ul>
+{% endif %}
+{% if todo.has_deps %}
+depends on:
+<ul>
+{% for dep_todo in todo.deps %}
+<li>
+{% if show_deps_doneness == true %}{{ macros.doneness_string(dep_todo) }}{% endif %}
+<a href="todo?id={{dep_todo.id_}}&return_to=day_todos">{{ dep_todo.title|e }}</a>{% if dep_todo.has_deps %}:+{% endif %}
+{% endfor %}
+</ul>
+{% endif %}
+</details>
+{% endif %}
+{% endmacro %}
+
+
+
+{% macro todo_title_as_tree_node(todo, indent) %}
+{% for i in range(indent-1) %} {% endfor %}
+{% if indent>0 %} +{% endif %}
+{% if todo.been_observed %}({% endif %}<a href="todo?id={{todo.id_}}&return_to=day_todos">{{todo.title}}</a>{% if todo.been_observed %}){% endif %}
+{% endmacro %}
+
+
+
+{% macro draw_undone_todo_row(todo, title_drawer, indent_or_doneness) %}
+<tr {% if todo.deps_done == false %}class="deps_undone"{% endif %}>
+{% if todo.already_listed %}
+<td class="checkbox"><input type="checkbox" disabled /></td>
+<td class="number left"><input type="number" value="{{todo.day_effort}}" size=7 disabled /></td>
+<td class="number"><input type="number" value="{{todo.importance}}" size=7 disabled /></td>
+<td>
+{{ title_drawer(todo, indent_or_doneness ) }}
+</td>
+<td><input value="{{todo.comment|e}}" size=100 disabled /></td>
+{% else %}
+<input name="todo_id" value="{{todo.id_}}" type="hidden" >
+<td class="checkbox">
+<input name="done" type="checkbox" value="{{todo.id_}}" {% if todo.done %}checked{% endif %} {% if todo.deps_done == false %}disabled{% endif %}>
+</td>
+<td class="number unbreakable">
+<input class="effort_input" name="effort" type="number" step=0.1 size=7 value="{% if todo.day_effort is not none %}{{todo.day_effort}}{% endif %}" placeholder={{"%.1f"|format(todo.task.default_effort.then)}} >
+</td>
+<td class="number">
+<input name="importance" type="number" step=0.1 size=7 value={{todo.importance}} } >
+</td>
+<td>
+{{ title_drawer(todo, indent_or_doneness) }}
+</td>
+<td>
+<input name="effort_comment" type="text" size=100 value="{{todo.comment|e}}" />
+</td>
+{% endif %}
+</tr>
+{% endmacro %}
+
+
+
+{% macro draw_done_todo_row(todo, title_drawer, indent) %}
+<tr>
+<td class="number">{{ '{:4.1f}'.format(todo.effort_at_selected_date) }}</td>
+<td class="number">{{ '{:4.1f}'.format(todo.effort_at_selected_date + todo.dep_efforts) }}</td>
+<td>
+{{ title_drawer(todo, indent) }}
+</td>
+</td>
+</td>
+<td>{{ todo.comment }}</td>
+</tr>
+{% endmacro %}
+
+
+
+{% macro draw_todo_rows(todos, is_tree_shaped, todo_row_drawer, indent, show_deps_doneness=false) %}
+{% for todo in todos %}
+{% if is_tree_shaped %}
+{{ todo_row_drawer(todo, todo_title_as_tree_node, indent) }}
+{% if not todo.been_observed and todo.deps %}
+{{ draw_todo_rows(todo.deps, is_tree_shaped, todo_row_drawer, indent+1) }}
+{% endif %}
+{% else %}
+{{ todo_row_drawer(todo, todo_title_expandable, show_deps_doneness) }}
+{% endif %}
+{{ todo.observe() }}
+{% endfor %}
+{% endmacro %}
+
+
+
+{% block content %}
+<h3>day todos</h3>
+
+<form id="form_to_watch" action="day_todos" method="POST">
+{% include 'tagfilters.html' %}
+<br />
+<input id="filter_button" type="submit" name="filter" value="filter" />
+<p>
+| <a href="day_todos?date={{prev_date}}">prev</a> | {{day.date}} | <a href="day_todos?date={{next_date}}">next</a> |
+comment: <input name="day_comment" value="{{day.comment|e}}">
+<input class="update" type="submit" name="update" value="update">
+<input type="hidden" name="date" value="{{day.date}}" />
+| show as {% if is_tree_shaped %}<a href="?tree=0">flat</a>|<b>tree</b>{% else %}<b>flat</b>|<a href="?tree=1">tree</a>{% endif %}
+</p>
+
+<h3>undone</h3>
+<p>
+task quick-add: <input name="choose_task" size=50 list="tasks" autocomplete="off">
+don't adopt, make new: <input type="checkbox" name="dont_adopt" />
+</p>
+{{ macros.datalist_tasks(all_tasks, with_weight=true) }}
+
+{% if adoptable_past_todos %}
+<details class="adoptables">
+<summary><span>there are adoptable/unfinished past todos ({{adoptable_past_todos|count}})</span></summary>
+<table class="alternating">
+<tr>
+<th>adopt?</th><th>date</th><th>title</th><th>comment</th>
+</tr
+{% for todo in adoptable_past_todos %}
+<tr>
+<td class="checkbox"><input name="choose_todo" type="checkbox" value="{{todo.id_}}"></td>
+<td>{{todo.earliest_date}}</td>
+<td><a href="todo?id={{todo.id_}}">{{todo.title|e}}</a></td>
+<td>{{todo.comment|e}}</td>
+</tr>
+{% endfor %}
+</table>
+</details>
+{% endif %}
+
+{% if undone_todos %}
+<table class="undone_todos">
+<tr>
+{{ macros.sort_head(undone_sort, "sort_done", "done", "undone_sort") }}
+{{ macros.sort_head(undone_sort, "default_effort", "effort", "undone_sort") }}
+{{ macros.sort_head(undone_sort, "importance", "importance", "undone_sort") }}
+{{ macros.sort_head(undone_sort, "title", "todo", "undone_sort") }}
+<th>comment</th>
+</tr>
+{{ draw_todo_rows(undone_todos, is_tree_shaped, draw_undone_todo_row, 0, show_deps_doneness=true) }}
+{% endif %}
+
+</table>
+<input id="update_button" class="update" type="submit" name="update" value="update">
+</form>
+
+{% if done_todos %}
+<h3>done</h3>
+<table class="alternating">
+<tr>
+{{ macros.sort_head(done_sort, "effort_at_selected_date", "single<br />effort", "done_sort") }}
+{{ macros.sort_head(done_sort, "family_effort", "family<br />effort", "done_sort") }}
+{{ macros.sort_head(done_sort, "title", "todo", "done_sort") }}
+<th>comment</th>
+</tr>
+{{ draw_todo_rows(done_todos, is_tree_shaped, draw_done_todo_row, 0) }}
+</table>
+{% endif %}
+
+{% include 'watch_form.html' %}
+<script>
+var effort_inputs = document.getElementsByClassName("effort_input");
+for (let i = 0; i < effort_inputs.length; i++) {
+ let input = effort_inputs[i];
+ let button = document.createElement('button');
+ button.innerHTML = '+' + parseFloat(input.placeholder).toFixed(1);
+ button.onclick = function(event) {
+ event.preventDefault();
+ if (input.value) {
+ input.value = parseFloat(input.value) + parseFloat(input.placeholder);
+ } else {
+ input.value = parseFloat(input.placeholder);
+ }
+ input.value = parseFloat(input.value).toFixed(1);
+ changes_to_commit = true;
+ };
+ input.insertAdjacentElement('afterend', button);
+}
+</script>
+{% endblock %}