From: Christian Heller Date: Sat, 20 Jan 2024 06:34:46 +0000 (+0100) Subject: Improve todo accounting script. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/static/git-favicon.png?a=commitdiff_plain;h=979de59ced9fe3fd3860d19288b42485d7f02346;p=misc Improve todo accounting script. --- diff --git a/todo.py b/todo.py index 1e493ac..3ea09b0 100644 --- a/todo.py +++ b/todo.py @@ -189,7 +189,6 @@ class Day: for todo in [todo for todo in self.linked_todos.values() if self.date in todo.efforts.keys()]: day_effort = todo.efforts[self.date] - # print("DEBUG b", day_effort, todo.task.default_effort_at(self.date)) if todo.done: s += day_effort if day_effort else todo.task.default_effort.at(self.date) elif include_undone: @@ -200,10 +199,6 @@ class Day: def todos_sum(self): return self._todos_sum() - # @property - # def todos_sum2(self): - # return self._todos_sum(True) - class Todo: @@ -227,7 +222,7 @@ class Todo: self.importance = importance self.child_ids = child_ids if child_ids else [] - self.parent = None + self.parents = [] @classmethod def from_dict(cls, db, d, id_): @@ -253,6 +248,10 @@ class Todo: 'efforts': self.efforts, 'children': self.child_ids} + @property + def parent(self): + return self.parents[0] if len(self.parents) > 0 else None + @property def title(self): return self.task.title.at(self.earliest_date) @@ -261,6 +260,10 @@ class Todo: def children(self): return [self.db.todos[id_] for id_ in self.child_ids] + @children.setter + def children(self, children): + self.child_ids = [child.id_ for child in children] + @property def default_effort(self): return self.task.default_effort.at(self.earliest_date) @@ -375,7 +378,7 @@ class TodoDB(PlomDB): hide_unchosen=False, hide_done=False): self.prefix = prefix - self.selected_date = selected_date if selected_date else today_date() #str(datetime.now())[:10] + self.selected_date = selected_date if selected_date else today_date() self.t_filter_and = t_filter_and if t_filter_and else [] self.t_filter_not = t_filter_not if t_filter_not else [] self.hide_unchosen = hide_unchosen @@ -387,6 +390,8 @@ class TodoDB(PlomDB): self.todos = {} super().__init__(db_path) + # savefile I/O + def read_db_file(self, f): d = json.load(f) for id_, t_dict in d['tasks'].items(): @@ -402,7 +407,7 @@ class TodoDB(PlomDB): self.add_day(dict_source=day_dict, date=date) for todo in self.todos.values(): for child in todo.children: - child.parent = todo + child.parents += [todo] for date in todo.efforts.keys(): if not date in self.days.keys(): self.add_day(date) @@ -410,21 +415,6 @@ class TodoDB(PlomDB): self.days[date].linked_todos_as_list += [todo] self.set_visibilities() - def set_visibilities(self): - for uuid, t in self.tasks.items(): - t.visible = len([tag for tag in self.t_filter_and if not tag in t.tags.now]) == 0\ - and len([tag for tag in self.t_filter_not if tag in t.tags.now]) == 0\ - and ((not self.hide_unchosen) or uuid in self.selected_day.todos.keys()) - # for day in self.days.values(): - # for todo in day.todos.values(): - # todo.visible = len([tag for tag in self.t_filter_and if not tag in todo.day_tags | todo.task.tags ]) == 0\ - # and len([tag for tag in self.t_filter_not if tag in todo.day_tags | todo.task.tags ]) == 0\ - # and ((not self.hide_done) or (not todo.done)) - for todo in self.todos.values(): - todo.visible = len([tag for tag in self.t_filter_and if not tag in todo.day_tags | todo.task.tags.now ]) == 0\ - and len([tag for tag in self.t_filter_not if tag in todo.day_tags | todo.task.tags.now ]) == 0\ - and ((not self.hide_done) or (not todo.done)) - def to_dict(self): d = {'tasks': {}, 'days': {}, 'todos': {}} for uuid, t in self.tasks.items(): @@ -437,13 +427,6 @@ class TodoDB(PlomDB): d['todos'][id_] = todo.to_dict() return d - @property - def selected_day(self): - if not self.selected_date in self.days.keys(): - self.days[self.selected_date] = self.add_day(date=self.selected_date) - # print("DEBUG selected_day", self.days[self.selected_date].date) - return self.days[self.selected_date] - def write(self): dates_to_purge = [] for date, day in self.days.items(): @@ -453,12 +436,35 @@ class TodoDB(PlomDB): del self.days[date] self.write_text_to_db(json.dumps(self.to_dict())) + # properties + + @property + def selected_day(self): + if not self.selected_date in self.days.keys(): + self.days[self.selected_date] = self.add_day(date=self.selected_date) + return self.days[self.selected_date] + + # table manipulations + + def add_day(self, date, dict_source=None): + day = Day.from_dict(self, dict_source, date) if dict_source else Day(self, date) + self.days[date] = day + return day + def add_task(self, id_=None, dict_source=None): id_ = id_ if id_ else str(uuid4()) t = Task.from_dict(self, dict_source, id_) if dict_source else Task(self, id_) self.tasks[id_] = t return t + def update_task(self, id_, title, default_effort, tags, subtask_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.comment = comment + def add_todo(self, todo_dict=None, id_=None, task=None, efforts=None): id_ = id_ if id_ else str(uuid4()) if todo_dict: @@ -472,115 +478,29 @@ class TodoDB(PlomDB): self.todos[id_] = todo return todo - def add_day(self, date, dict_source=None): - day = Day.from_dict(self, dict_source, date) if dict_source else Day(self, date) - self.days[date] = day - return day - - 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 - - def show_do_todos(self, sort_order=None): - prev_date_str, next_date_str = self.neighbor_dates() - todos = [t for t in self.selected_day.linked_todos_as_list if t.visible] - 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.then 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( - day=self.selected_day, - tags=self.t_tags, - filter_and=self.t_filter_and, - filter_not=self.t_filter_not, - prev_date=prev_date_str, - next_date=next_date_str, - todos=todos, - sort=sort_order, - hide_done=self.hide_done) - - def show_calendar(self, start_date_str, end_date_str): - self.t_filter_and = ['calendar'] - self.t_filter_not = ['deleted'] - self.set_visibilities() - days_to_show = {} - todays_date_str = today_date() # str(datetime.now())[:10] - todays_date_obj = datetime.strptime(todays_date_str, DATE_FORMAT) - yesterdays_date_obj = todays_date_obj - timedelta(1) - yesterdays_date_str = yesterdays_date_obj.strftime(DATE_FORMAT) - start_date_obj = datetime.strptime(sorted(self.days.keys())[0], DATE_FORMAT) - if start_date_str and len(start_date_str) > 0: - if start_date_str in {'today', 'yesterday'}: - start_date_obj = todays_date_obj if start_date_str == 'today' else yesterdays_date_obj - else: - start_date_obj = datetime.strptime(start_date_str, DATE_FORMAT) - end_date_obj = datetime.strptime(sorted(self.days.keys())[-1], DATE_FORMAT) - if end_date_str and len(end_date_str) > 0: - if end_date_str in {'today', 'yesterday'}: - end_date_obj = todays_date_obj if end_date_str == 'today' else yesterdays_date_obj - else: - end_date_obj = datetime.strptime(end_date_str, DATE_FORMAT) - for n in range(int((end_date_obj - start_date_obj).days) + 1): - current_date_obj = start_date_obj + timedelta(n) - current_date_str = current_date_obj.strftime(DATE_FORMAT) - if current_date_str not in self.days.keys(): - days_to_show[current_date_str] = self.add_day(current_date_str) - else: - days_to_show[current_date_str] = self.days[current_date_str] - days_to_show[current_date_str].weekday = datetime.strptime(current_date_str, DATE_FORMAT).strftime('%A')[:2] - return j2env.get_template('calendar.html').render( - db=self, - days=days_to_show, - start_date=start_date_str, - end_date=end_date_str) - - def show_todo(self, id_, return_to): - todo = self.todos[id_] - filtered_todos = [] #[t for t in self.todos.values() if t.visible and t != self and (t not in linked_todos) and (len(search) == 0 or t.matches(search))] - return j2env.get_template('todo.html').render( - db=self, - todo=todo, - filtered_todos=filtered_todos, - child_todos=todo.children, - return_to=return_to) - - def collect_tags(self, tags_joined, tags_checked): - tags = set() - for tag in [tag.strip() for tag in tags_joined.split(';') if tag.strip() != '']: - tags.add(tag) - for tag in tags_checked: - tags.add(tag) - return tags - - def update_todo_for_day(self, id_, date, effort, done, comment, importance): + def _update_todo_shared(self, id_, done, comment, importance): todo = self.todos[id_] todo.done = done - todo.efforts[date] = effort todo.comment = comment todo.importance = importance + return todo - def update_todo(self, id_, efforts, done, comment, day_tags_joined, day_tags_checked, importance): - todo = self.todos[id_] + def update_todo_for_day(self, id_, date, effort, done, comment, importance): + todo = self._update_todo_shared(id_, done, comment, importance) + todo.efforts[date] = effort + + def update_todo(self, id_, efforts, done, comment, tags, importance, children): + todo = self._update_todo_shared(id_, done, comment, importance) if len(efforts) == 0 and not todo.children: raise PlomException('todo must have at least one effort!') - todo.done = done + todo.children = children todo.efforts = efforts for date in todo.efforts: if not date in self.days.keys(): self.add_day(date=date) if not self in self.days[date].linked_todos_as_list: self.days[date].linked_todos_as_list += [todo] - todo.comment = comment - todo.day_tags = self.collect_tags(day_tags_joined, day_tags_checked) - todo.importance = importance + todo.day_tags = tags def delete_todo(self, id_): todo = self.todos[id_] @@ -589,8 +509,8 @@ class TodoDB(PlomDB): dates_to_delete += [date] for date in dates_to_delete: self.delete_effort(todo, date, force=True) - if todo.parent: - todo.parent.child_ids.remove(todo.id_) + for parent in todo.parents: + parent.child_ids.remove(todo.id_) del self.todos[id_] def delete_effort(self, todo, date, force=False): @@ -599,12 +519,95 @@ class TodoDB(PlomDB): self.days[date].linked_todos_as_list.remove(todo) del todo.efforts[date] + # views + + def show_calendar(self, start_date_str, end_date_str): + self.t_filter_and = ['calendar'] + self.t_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) + days_to_show = {} + for n in range(int((end_date_obj - start_date_obj).days) + 1): + date_obj = start_date_obj + timedelta(n) + date_str = date_obj.strftime(DATE_FORMAT) + if date_str not in self.days.keys(): + days_to_show[date_str] = self.add_day(date_str) + else: + days_to_show[date_str] = self.days[date_str] + days_to_show[date_str].month_title = date_obj.strftime('%B') if date_obj.day == 1 else None + days_to_show[date_str].weekday = datetime.strptime(date_str, DATE_FORMAT).strftime('%A')[:2] + + return j2env.get_template('calendar.html').render( + selected_date=self.selected_date, + days=days_to_show, + 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() + todos = [t for t in self.selected_day.linked_todos_as_list + if t.visible + and not t.children] + 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( + day=self.selected_day, + tags=self.t_tags, + filter_and=self.t_filter_and, + filter_not=self.t_filter_not, + prev_date=prev_date_str, + next_date=next_date_str, + todos=todos, + sort=sort_order, + hide_done=self.hide_done) + + def show_todo(self, id_, return_to, search, start_date, end_date): + todo = self.todos[id_] + 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)] + filtered_todos = [t for t in self.todos.values() + if t.visible + and t != todo + and (len(search) == 0 or t.matches(search))] + date_filtered_todos = [] + for date in legal_dates: + for filtered_todo in filtered_todos: + if filtered_todo in date_filtered_todos: + continue + if date in filtered_todo.efforts.keys(): + date_filtered_todos += [filtered_todo] + return j2env.get_template('todo.html').render( + filter_and=self.t_filter_and, + filter_not=self.t_filter_not, + tags=self.t_tags, + todo=todo, + filtered_todos=date_filtered_todos, + child_todos=todo.children, + return_to=return_to, + start_date=start_date, + end_date=end_date) + def show_task(self, id_, return_to='', search=''): task = self.tasks[id_] if id_ else self.add_task() selected = task.id_ in self.selected_day.todos.keys() - filtered_tasks = [t for t in self.tasks.values() if t.visible and t != self and (t not in task.subtasks) and (len(search) == 0 or t.matches(search))] + filtered_tasks = [t for t in self.tasks.values() + if t.visible + and t != task + and (t not in task.subtasks) + and (len(search) == 0 or t.matches(search))] return j2env.get_template('task.html').render( - db=self, search=search, tags=self.t_tags, filter_and=self.t_filter_and, @@ -613,14 +616,6 @@ class TodoDB(PlomDB): task=task, return_to=return_to) - def update_task(self, id_, title, default_effort, tags_joined, tags_checked, subtask_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(float(default_effort) if len(default_effort) > 0 else None) - task.tags.set(self.collect_tags(tags_joined, tags_checked)) - task.subtask_ids.set(subtask_ids) - task.comment = comment - def show_tasks(self, expand_uuid): expanded_tasks = {} if expand_uuid: @@ -635,26 +630,38 @@ class TodoDB(PlomDB): 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: + if todo.done\ + or (not todo.visible)\ + or (not todo.matches(search))\ + or todo.earliest_date >= self.selected_date: continue relevant_todos += [todo] + 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): + if (not task.visible)\ + or (not task.matches(search))\ + or (hide_chosen_tasks and task in chosen_tasks): continue tasks += [task] + if sort_order == 'title': chosen_todos.sort(key=lambda t: t.title) relevant_todos.sort(key=lambda t: t.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) + 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) 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, @@ -669,6 +676,42 @@ class TodoDB(PlomDB): 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.t_filter_and if not tag in t.tags.now]) == 0\ + and len([tag for tag in self.t_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.t_filter_and if not tag in todo.day_tags | todo.task.tags.now ]) == 0\ + and len([tag for tag in self.t_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: @@ -696,7 +739,6 @@ class ParamsParser: return param def get_cookied_chain(self, key, default=None): - # default = default if default else ['-'] params = self.params.get(key, default) if params == ['-']: params = None @@ -709,6 +751,51 @@ class ParamsParser: return params +class PostvarsParser: + + def __init__(self, postvars): + self.postvars = postvars + + def has(self, key): + return key in self.postvars.keys() + + def get(self, key, on_empty=None): + return self.get_at_index(key, 0, on_empty) + + def get_at_index(self, key, i, on_empty=None): + if self.has(key) and len(self.postvars[key][i]) > 0: + return self.postvars[key][i] + return on_empty + + def get_float_if_possible(self, key): + s = self.get(key) + if s is not None: + return float(s) + else: + return None + + def get_all(self, key, on_empty=None): + if self.has(key) and len(self.postvars[key]) > 0: + return self.postvars[key] + return on_empty + + def get_defined_tags(self, joined_key, key_prefix): + tags = set() + tags_checked = [] + for k in self.postvars.keys(): + if k.startswith(key_prefix): + tags_checked += [k[len(key_prefix):]] + tags_joined = self.get(joined_key, '') + for tag in [tag.strip() for tag in tags_joined.split(';') if tag.strip() != '']: + tags.add(tag) + for tag in tags_checked: + tags.add(tag) + return tags + + def set(self, key, value): + self.postvars[key] = [value] + + class TodoHandler(PlomHandler): def config_init(self): @@ -725,44 +812,44 @@ class TodoHandler(PlomHandler): return 'todo', {'cookie_name': 'todo_cookie', 'prefix': default_path, 'cookie_path': default_path} def do_POST(self): - self.try_do(self.config_init) self.try_do(self.write_db) def write_db(self): from urllib.parse import urlencode config = self.apps['todo'] if hasattr(self, 'apps') else self.config_init() - length = int(self.headers['content-length']) - postvars = parse_qs(self.rfile.read(length).decode(), keep_blank_values=1) parsed_url = urlparse(self.path) - site = path_split(urlparse(self.path).path)[1] + site = path_split(parsed_url.path)[1] + length = int(self.headers['content-length']) + postvars = PostvarsParser(parse_qs(self.rfile.read(length).decode(), keep_blank_values=1)) + db = TodoDB(prefix=config['prefix']) redir_params = [] + # if we do encounter a filter post, we repost it (and if empty, the emptying command '-') for param_name, filter_db_name in {('t_and', 't_filter_and'), ('t_not', 't_filter_not')}: filter_db = getattr(db, filter_db_name) - if param_name in postvars.keys(): - for target in postvars[param_name]: + if postvars.has(param_name): + for target in postvars.get_all(param_name, []): if len(target) > 0 and not target in filter_db: filter_db += [target] if len(filter_db) == 0: redir_params += [(param_name, '-')] redir_params += [(param_name, f) for f in filter_db] - - def collect_checked(prefix, postvars): - tags_checked = [] - for k in postvars.keys(): - if k.startswith(prefix): - tags_checked += [k[len(prefix):]] - return tags_checked + if site in {'calendar', 'todo'}: + redir_params += [('end', postvars.get('end', '-'))] + redir_params += [('start', postvars.get('start', '-'))] + if site in {'todo', 'task', 'pick_tasks'}: + redir_params += [('search', postvars.get('search', ''))] + redir_params += [('search', postvars.get('search', ''))] + redir_params += [('search', postvars.get('search', ''))] + if postvars.has('filter'): + postvars.set('return_to', '') - if 'calendar' == site: - redir_params += [('start', postvars['start'][0] if len(postvars['start'][0]) > 0 else '-')] - redir_params += [('end', postvars['end'][0] if len(postvars['end'][0]) > 0 else '-')] - - elif 'todo' == site: - todo_id = postvars['todo_id'][0] - old_todo = db.todos[todo_id] + if '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 efforts = {} - for i, date in enumerate(postvars['effort_date']): + for i, date in enumerate(postvars.get_all('effort_date', [])): if '' == date: continue try: @@ -770,166 +857,141 @@ class TodoHandler(PlomHandler): except ValueError: raise PlomException(f'bad date string') efforts[date] = None - if not old_todo.children: - efforts[date] = float(postvars['effort'][i]) if len(postvars['effort'][i]) > 0 else None - if 'delete' in postvars.keys(): - has_day_effort = False - for effort in efforts.values(): - if effort is not None: - has_day_effort = True - break - if 'done' in postvars or postvars['comment'][0] != '' or len(collect_checked('day_tag_', postvars)) > 0 or postvars['joined_day_tags'][0] != '' or has_day_effort: + if not (old_todo and old_todo.children): + efforts[date] = postvars.get_at_index('effort', i, None) + if postvars.has('delete'): + has_day_effort = len([e for e in efforts.values() if e is not None]) > 0 + if postvars.has('done')\ + or postvars.get('comment')\ + or len(postvars.get_defined_tags('joined_day_tags', 'day_tag_')) > 0\ + or has_day_effort: raise PlomException('will not remove todo of preserve-worthy values') db.delete_todo(todo_id) - else: - redir_params += [('id', todo_id)] - if 'delete_effort' in postvars.keys(): - for date in postvars['delete_effort']: + if not postvars.get('return_to'): + postvars.set('return_to', 'calendar') + elif postvars.has('update'): + if postvars.has('delete_effort'): + 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', [])] db.update_todo(id_=todo_id, efforts=efforts, - done='done' in postvars.keys(), - comment=postvars['comment'][0], - day_tags_joined=postvars['joined_day_tags'][0], - day_tags_checked=collect_checked('day_tag_', postvars), - importance=float(postvars['importance'][0])) + done=postvars.has('done'), + comment=postvars.get('comment', ''), + tags=postvars.get_defined_tags('joined_day_tags', 'day_tag_'), + importance=float(postvars.get('importance')), + children=children) elif 'task' == site: - id_ = postvars['id'][0] - if 'filter' in postvars.keys(): - redir_params += [('search', postvars['search'][0])] - elif 'title' in postvars.keys(): - subtask_ids = [] if not 'subtask' in postvars.keys() else postvars['subtask'] - default_effort = '0' if not 'default_effort' in postvars.keys() else postvars['default_effort'][0] - db.update_task(id_, postvars['title'][0], default_effort, postvars['joined_tags'][0], collect_checked('tag_', postvars), subtask_ids, postvars['comment'][0]) - redir_params += [('id', id_)] + task_id = postvars.get('task_id') + if postvars.has('update'): + db.update_task( + id_=task_id, + title=postvars.get('title', ''), + default_effort=postvars.get_float_if_possible('default_effort'), + tags=postvars.get_defined_tags('joined_tags', 'tag_'), + subtask_ids=postvars.get_all('subtask', []), + comment=postvars.get('comment', '')) + redir_params += [('id', task_id)] elif 'pick_tasks' == site: - if 'filter' in postvars.keys(): - redir_params += [('search', postvars['search'][0])] - redir_params += [('hide_chosen_tasks', int('hide_chosen_tasks' in postvars.keys()))] - else: - db.selected_date = postvars['date'][0] + 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 ('chosen_todo' in postvars.keys() and todo.id_ in postvars['chosen_todo']): - if len(todo.comment) > 0 or len(todo.day_tags) > 0 or not todo.is_effort_removable(db.selected_date): - # print("DEBUG", len(todo.comment) > 0, len(todo.day_tags) > 0, todo.is_effort_removable(db.selected_date)) + 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] - # db.delete_effort(todo, db.selected_date) else: todos_to_delete += [todo] - # db.delete_todo(todo.id_) for todo in todos_to_shrink: db.delete_effort(todo, db.selected_date) for todo in todos_to_delete: db.delete_todo(todo.id_) - if 'choose_task' in postvars.keys(): - for id_ in postvars['choose_task']: - db.add_todo(task=db.tasks[id_], efforts={db.selected_date: None}) - if 'choose_todo' in postvars.keys(): - for id_ in postvars['choose_todo']: - todo = db.todos[id_] - todo.efforts[db.selected_date] = None + 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: - if 'filter' in postvars.keys(): - redir_params += [('hide_done', int('hide_done' in postvars.keys()))] - else: - db.selected_date = postvars['date'][0] + redir_params += [('hide_done', int(postvars.has('hide_done')))] + if postvars.has('update'): + db.selected_date = postvars.get('date') redir_params += [('date', db.selected_date)] - db.selected_day.comment = postvars['day_comment'][0] - if 'todo_id' in postvars.keys(): - for i, todo_id in enumerate(postvars['todo_id']): - old_todo = None if not todo_id in db.todos.keys() else db.todos[todo_id] - done = ('done' in postvars) and (todo_id in postvars['done']) - day_effort_input = postvars['effort'][i] - day_effort = float(day_effort_input) if len(day_effort_input) > 0 else None - comment = postvars['effort_comment'][i] - importance = float(postvars['importance'][i]) - if old_todo and old_todo.done == done and old_todo.day_effort == day_effort and comment == old_todo.comment and old_todo.importance == importance: - continue - db.update_todo_for_day(todo_id, db.selected_date, day_effort, done, comment, importance) - - elif 'day' == site: - # always store the two hide params in the URL if possible … TODO: find out if really necessary - if 'expect_unchosen_done' in postvars.keys(): - redir_params += [('hide_unchosen', int('hide_unchosen' in postvars.keys()))] + [('hide_done', int('hide_done' in postvars.keys()))] - - if 'date' in postvars.keys(): - db.selected_date = postvars['date'][0] - if 'day_comment' in postvars.keys(): - db.selected_day.comment = postvars['day_comment'][0] - redir_params += [('date', db.selected_date)] - - # handle todo list updates via task UUIDs - if 't_uuid' in postvars.keys(): - for i, uuid in enumerate(postvars['t_uuid']): - task = db.tasks[uuid] - old_todo = None if not uuid in db.selected_day.todos.keys() else db.selected_day.todos[uuid] - selects_as_todo = 'choose' in postvars and uuid in postvars['choose'] - too_much_keepworthy_data = ('done' in postvars and uuid in postvars['done']) or postvars['day_effort'][i] != '' or (old_todo and not old_todo.internals_empty()) - if old_todo and too_much_keepworthy_data and not selects_as_todo: - raise PlomException('cannot deselect task as todo of preserve-worthy values') - elif old_todo and not selects_as_todo: - del db.selected_day.todos[uuid] - elif too_much_keepworthy_data or selects_as_todo: - done = ('done' in postvars) and (uuid in postvars['done']) - day_effort_input = postvars['day_effort'][i] - day_effort = float(day_effort_input) if len(day_effort_input) > 0 else None - importance = float(postvars['importance'][i]) - if old_todo and old_todo.done == done and old_todo.day_effort == day_effort and old_todo.importance == importance: - continue - db.update_todo_mini(uuid, db.selected_date, day_effort, done, importance) - - if 'return_to' in postvars.keys() and len(postvars['return_to'][0]) > 0: - homepage = postvars['return_to'][0] - else: + db.selected_day.comment = postvars.get('day_comment', '') + for i, todo_id in enumerate(postvars.get_all('todo_id')): + old_todo = None if not todo_id in db.todos.keys() else db.todos[todo_id] + done = todo_id in postvars.get_all('done', []) + day_effort_input = postvars.get_at_index('effort', i, '') + day_effort = float(day_effort_input) if len(day_effort_input) > 0 else None + comment = postvars.get_at_index('effort_comment', i, '') + importance = float(postvars.get_at_index('importance', i)) + if old_todo\ + and old_todo.done == done\ + and old_todo.day_effort == day_effort\ + and comment == old_todo.comment\ + and old_todo.importance == importance: + continue + db.update_todo_for_day( + todo_id, + db.selected_date, + day_effort, + done, + comment, + importance) + + homepage = postvars.get('return_to') + if not homepage: encoded_params = urlencode(redir_params) homepage = f'{site}?{encoded_params}' db.write() self.redirect(homepage) def do_GET(self): - self.try_do(self.config_init) self.try_do(self.show_db) def show_db(self): config = self.apps['todo'] if hasattr(self, 'apps') else self.config_init() - cookie_db = self.get_cookie_db(config['cookie_name']) parsed_url = urlparse(self.path) site = path_split(parsed_url.path)[1] - + cookie_db = self.get_cookie_db(config['cookie_name']) params = ParamsParser(parsed_url.query, cookie_db) + selected_date = t_filter_and = t_filter_not = None hide_unchosen = hide_done = False return_to = params.get('return_to', '') - if site in {'do_todos', 'pick_tasks'}: + if site in {'do_todos', 'pick_tasks', 'calendar'}: selected_date = params.get_cookied('date') - if site in {'do_todos', 'pick_tasks', 'task', 'tasks'}: + if site in {'do_todos', 'pick_tasks', 'task', 'todo'}: t_filter_and = params.get_cookied_chain('t_and') t_filter_not = params.get_cookied_chain('t_not') if 'do_todos' == site: hide_done = params.get('hide_done', False) db = TodoDB(config['prefix'], selected_date, t_filter_and, t_filter_not, hide_unchosen, hide_done) - if 'do_todos' == site: + if site in {'todo', 'task'}: + id_ = params.get('id') + if site in {'todo', 'task', 'pick_tasks'}: + search = params.get('search', '') + if site in {'do_todos', 'pick_tasks'}: sort_order = params.get_cookied('sort') + if site in {'calendar', 'todo'}: + start_date = params.get_cookied('start') + end_date = params.get_cookied('end') + if 'do_todos' == site: page = db.show_do_todos(sort_order) elif 'pick_tasks' == site: - sort_order = params.get_cookied('sort') hide_chosen_tasks = params.get('hide_chosen_tasks', False) - search = params.get('search', '') page = db.show_pick_tasks(search, hide_chosen_tasks, sort_order) elif site == 'todo': - todo_id = params.get('id') - page = db.show_todo(todo_id, return_to) + page = db.show_todo(id_, return_to, search, start_date, end_date) elif 'task' == site: - id_ = params.get('id') - search = params.get('search', '') page = db.show_task(id_, return_to, search) elif 'tasks' == site: expand_uuid = params.get('expand_uuid') @@ -942,8 +1004,6 @@ class TodoHandler(PlomHandler): self.unset_cookie(config['cookie_name'], config['cookie_path']) page = 'cookie unset!' else: - start_date = params.get_cookied('start') - end_date = params.get_cookied('end') page = db.show_calendar(start_date, end_date) if 'unset_cookie' != site: diff --git a/todo_templates/base.html b/todo_templates/base.html index 92cdff0..b010333 100644 --- a/todo_templates/base.html +++ b/todo_templates/base.html @@ -1,6 +1,19 @@ diff --git a/todo_templates/calendar.html b/todo_templates/calendar.html index 82a9ca2..bc77ccd 100644 --- a/todo_templates/calendar.html +++ b/todo_templates/calendar.html @@ -1,30 +1,70 @@ {% extends 'base.html' %} + {% block css %} -tr td { background-color: white; } +#filter { margin-bottom: 1em; } +tr.month_row td { color: white; background-color: #555555; text-align: center; } tr.week_row td { height: 0.1em; background-color: black; } -tr.day_row td { background-color: #cccccc } -td.checkbox { width: 0.1em; height: 0.1em; padding: 0em; text-align: center; } +tr.day_row td { background-color: #cccccc; } +span.selected_date { font-weight: bold; } {% endblock %} + {% block content %} +

calendar

-

+ +

from: to: -

+
+ -{% for date, day in days.items() | sort() %} -{% if day.weekday == 'Mo' %}{% endif %} - -{% for todo in day.linked_todos_as_list %} +{% for date, day in days.items() %} -{% if todo.visible %} - +{% if day.month_title %} + + + +{% endif %} + +{% if day.weekday == 'Mo' %} + + + {% endif %} + + + + +{% for todo in day.linked_todos_as_list %} +{% if todo.visible %} + + + + +{% endif %} {% endfor %} + {% endfor %}
{{ day.weekday }} {{ date }} |{{ "%5.1f" |format(day.todos_sum)}}| {{ day.comment|e }}
{% if todo.done and not "cancelled" in todo.tags%}✓{% else %}  {% endif %}{% if "cancelled" in todo.tags %}{% endif %}{% if "deadline" in todo.tags %}DEADLINE: {% endif %}{{ todo.title|e }}{%if "cancelled" in todo.tags%}{% endif %}{{ todo.comment|e }}
{{ day.month_title }}
+ +{{ day.weekday }} {{ date }} + +|{{ '{:5.1f}'.format(day.todos_sum)}}| +{{ day.comment|e }} +
+{% if "cancelled" in todo.tags %}{% endif %} +[{% if todo.done and not "cancelled" in todo.tags %}✓{% else %} {% endif %}] + +{% if "deadline" in todo.tags %}DEADLINE: {% endif %} +{{ todo.title|e }} + +{%if "cancelled" in todo.tags%}{% endif %} + +{{ todo.comment|e }} +
+
{% endblock %} diff --git a/todo_templates/do_todos.html b/todo_templates/do_todos.html index 7a8ae82..129018f 100644 --- a/todo_templates/do_todos.html +++ b/todo_templates/do_todos.html @@ -1,69 +1,72 @@ {% extends 'base.html' %} + {% block css %} -table.alternating tr:nth-child(even) { - background-color: #cccccc; -} -table.alternating tr:nth-child(odd) { - background-color: #ffffff; -} -th, td { text-align: left} -th.desc { background: linear-gradient(to bottom, white, grey); } -th.center { text-align: center; } -td.checkbox, td.number { height: 0.1em; padding: 0em; text-align: center; } -td.checkbox { width: 0.1em; text-align: center; } -td button { height: 1.5em; padding: 0em; margin: 0em } -input[type="number"] { text-align: right; } -th.desc { background: linear-gradient(to bottom, white, grey); } +td.number, td.checkbox { text-align: center; } +td { vertical-align: middle; } +td button { padding: 0em; } +th.centered { text-align: center; } {% endblock %} + {% block content %} -
+

do todos

+ + {% include 'tagfilters.html' %}
hide done -
-

do day

-

| prev | {{day.date}} | next | comment: - +

+ - - - - + + + + + + {% for todo in todos %} - - - + + + {% endfor %} +
doneeffortimportancetodo +done + +effort + +importance + +todo + comment
-{% if todo.children %} -{% if todo.done %}✓{% else %}  {% endif %} -{% else %} -{% endif %} -{% if todo.children %} - -{% else %} -{% endif %} {{todo.path}}{{todo.title}} + + +{{todo.path}}{{todo.title}} + + +
- +
+ {% include 'watch_form.html' %} {% endblock %} - diff --git a/todo_templates/tagfilters.html b/todo_templates/tagfilters.html index 869cf54..21333f6 100644 --- a/todo_templates/tagfilters.html +++ b/todo_templates/tagfilters.html @@ -1,4 +1,4 @@ -mandatory tags: +need: {% for and_filter in filter_and %}
-forbidden tags: +hide: {% for not_filter in filter_not %} + +
+ - - - + + + + + + + + + + + - + + + - +add: +
+
+history +
    +{% for k,v in task.tags.history.items() | sort(attribute='0', reverse=True) %} +
  • {{ k }}: {{ v|e }} +{% endfor %} +
+
+ + + + + +
title
history
    {% for k,v in task.title.history.items() | sort(attribute='0', reverse=True) %}
  • {{ k }}: {{ v|e }}{% endfor %}
selected for {{db.selected_date}}
comment
title + +
+history +
    +{% for k,v in task.title.history.items() | sort(attribute='0', reverse=True) %} +
  • {{ k }}: {{ v|e }} +{% endfor %} +
+
+
comment + +
default effort {% if task.subtasks %} {{ task.default_effort.now }} {% else %} -
history
    {% for k,v in task.default_effort.history.items() | sort(attribute='0', reverse=True) %}
  • {{ k }}: {{ v|e }}{% endfor %}
+ +
+history +
    +{% for k,v in task.default_effort.history.items() | sort(attribute='0', reverse=True) %} +
  • {{ k }}: {{ v|e }} +{% endfor %} +
+
{% endif %}
tags
tags -{% for tag in db.t_tags | sort %} - {{ tag }}
+{% for tag in tags | sort %} + {{ tag }} +
{% endfor %} -add:
-
history
    {% for k,v in task.tags.history.items() | sort(attribute='0', reverse=True) %}
  • {{ k }}: {{ v|e }}{% endfor %}
-
children
children + {% for subtask in task.subtasks %} - - + + {% endfor %} + + {% for subtask in filtered_tasks %} - - + + {% endfor %} +
{{subtask.title.now}} + + +{{subtask.title.now}} +
---
{{subtask.title.now}} + + +{{subtask.title.now}} +
- -
-
- + +
{% include 'tagfilters.html' %}
search:
+ {% include 'watch_form.html' %} + {% endblock %} diff --git a/todo_templates/todo.html b/todo_templates/todo.html index beccb75..404ac1c 100644 --- a/todo_templates/todo.html +++ b/todo_templates/todo.html @@ -1,83 +1,157 @@ {% extends 'base.html' %} + {% block css %} -th, td { vertical-align: top; text-align: left} -td.checkbox { width: 0.1em; height: 0.1em; padding: 0em; text-align: center; } -input[type="number"] { text-align: right; } +th.toplevel { padding-right: 1em; } +input[type="submit"].delete { background-color: #ff7777; } +div.delete { float: right; } +td.center { text-align: center; } {% endblock %} + {% block content %} -

edit todo

+ + - - + - + + + + + + + + + + + + - + + - - + + + + + + + + + + + - + + + - - + + +
task{{ todo.task.title.then|e }}
default effort{{ todo.default_effort }}
effortstask{{ todo.task.title.then|e }}
default effort{{ todo.default_effort }}
efforts - + {% for date, effort in todo.efforts.items() %} - - - + + + {% endfor %} - - + +
dateeffortdelete
dateeffortdelete
{% if not (todo.children and effort) %}{% endif %} + + + + +{% if not (todo.children and effort) %}{% endif %} +
+ + + +
total effort{{todo.all_days_effort}}total effort{{todo.all_days_effort}}
importance
comment
importance + +
comment + +
done {% if todo.children %}✓{% else %}{% endif %}
day tags
day tags -{% for tag in db.t_tags | sort %} -{% if tag in todo.task.tags.now %} âœ“{% else %}{% endif %} {{ tag }}
+{% for tag in tags | sort %} +{% if tag in todo.task.tags.now %} + âœ“ +{% else %} + +{% endif %} {{ tag }} +
{% endfor %} add:
parent{% if todo.parent %}{{todo.parent.title}}{% else %}–{% endif %}
children
parents - + + + + + + + + +
children + + + + {% for todo in child_todos %} - - - + + + {% endfor %} -
adoptefforttitlecomments
{% if todo.done %}✓{% endif %}{{todo.all_days_effort}}{{todo.title}}{{ '{:2.1f}'.format(todo.all_days_effort) }} {% if todo.done %}✓{% else %} {% endif %}{{todo.day.date}} {{todo.title}}
- -
- + +
+
+ +
+{% include 'tagfilters.html' %} +
+from: +to: +search: + + +{% include 'watch_form.html' %} + {% endblock %} diff --git a/todo_templates/watch_form.html b/todo_templates/watch_form.html index 979c1da..62fee48 100644 --- a/todo_templates/watch_form.html +++ b/todo_templates/watch_form.html @@ -1,19 +1,29 @@