From: Christian Heller Date: Tue, 12 Dec 2023 21:32:03 +0000 (+0100) Subject: Improve todo accounting. X-Git-Url: https://plomlompom.com/repos/?p=misc;a=commitdiff_plain;h=472874343c229fc77136e1cc3bae5a1d8bc543f9 Improve todo accounting. --- diff --git a/todo.py b/todo.py index 88684ac..42639a1 100644 --- a/todo.py +++ b/todo.py @@ -12,25 +12,28 @@ DATE_FORMAT = '%Y-%m-%d' html_head = """ tasks: list add | day: choose tasks -do tasks +do tasks | calendar
""" @@ -46,8 +49,8 @@ to: {% for date, day in days.items() | sort() %} -{% if day.weekday == "Monday" %}{% endif %} - +{% if day.weekday == "Mo" %}{% endif %} + {% for task, todo in day.todos.items() | sort(attribute='1.title', reverse=True) %} {% if todo.visible %} @@ -63,7 +66,7 @@ todo_tmpl = """ - +
{{ date }} {{ day.weekday }} ({{ day.todos_sum|round(2) }}) {{ day.comment|e }}
{{ day.weekday }} {{ date }} |{{ '%04.1f' % day.todos_sum|round(2) }}| {{ day.comment|e }}
{% if todo.done %}✓{% else %}  {% endif %}{{ todo.title }}{{ todo.comment|e }}
task{{ todo.task.title|e }}
default weight{{ todo.default_weight }}
day{{ todo.day.date }}
day weight
day weight
comment
done
@@ -73,17 +76,17 @@ task_tmpl = """ - +
title
history
    {% for k,v in task.title_history.items() | sort(attribute='0', reverse=True) %}
  • {{ k }}: {{ v|e }}{% endfor %}
default weight
history
    {% for k,v in task.default_weight_history.items() | sort(attribute='0', reverse=True) %}
  • {{ k }}: {{ v|e }}{% endfor %}
default weight
history
    {% for k,v in task.default_weight_history.items() | sort(attribute='0', reverse=True) %}
  • {{ k }}: {{ v|e }}{% endfor %}
tags
history
    {% for k,v in task.tags_history.items() | sort(attribute='0', reverse=True) %}
  • {{ k }}: {{ v|e }}{% endfor %}
""" day_tmpl = """

- hide unchosen | -prev next | + hide unchosen hide done | +prev next | -date: | +date: | {{ db.selected_day.todos_sum|round(2) }} ({{ db.selected_day.todos_sum2|round(2)}}) | comment:

@@ -95,9 +98,9 @@ comment:
] {{ t.current_title|e }}tags: {% for tag in t.tags | sort %}{{ tag }} {% endfor %}
- + - + {% endif %} @@ -149,7 +152,7 @@ tasks_tmpl = """ {% for uuid, t in db.tasks.items() | sort(attribute='1.title') %} {% if t.visible %} -{{ t.default_weight }} +{{ t.default_weight }} {{ t.title|e }} {% for tag in t.tags | sort %}{{ tag }} {% endfor %} {% endif %} @@ -344,12 +347,13 @@ class Todo: class TodoDB(PlomDB): - def __init__(self, prefix, selected_date=None, t_filter_and = None, t_filter_not = None, hide_unchosen=False): + def __init__(self, prefix, selected_date=None, t_filter_and = None, t_filter_not = None, hide_unchosen=False, hide_done=False): self.prefix = prefix self.selected_date = selected_date if selected_date else str(datetime.now())[:10] 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 + self.hide_done = hide_done self.days = {} self.tasks = {} self.t_tags = set() @@ -363,7 +367,8 @@ class TodoDB(PlomDB): t = self.add_task(id_=uuid, dict_source=t_dict) t.visible = len([tag for tag in self.t_filter_and if not tag in t.tags]) == 0\ and len([tag for tag in self.t_filter_not if tag in t.tags]) == 0\ - and ((not self.hide_unchosen) or uuid in self.selected_day.todos) + and ((not self.hide_unchosen) or uuid in self.selected_day.todos)\ + and ((not self.hide_done) or (uuid in self.selected_day.todos and not self.selected_day.todos[uuid].done)) for tag in t.tags: self.t_tags.add(tag) @@ -438,7 +443,7 @@ class TodoDB(PlomDB): days_to_show[current_date] = self.add_day() else: days_to_show[current_date] = self.days[current_date] - days_to_show[current_date].weekday = datetime.strptime(current_date, DATE_FORMAT).strftime('%A') + days_to_show[current_date].weekday = datetime.strptime(current_date, DATE_FORMAT).strftime('%A')[:2] for task_uuid, todo in days_to_show[current_date].todos.items(): todo.visible = self.tasks[task_uuid].visible return Template(form_header_tmpl + calendar_tmpl + form_footer).render(db=self, days=days_to_show, action=self.prefix+'/calendar', today=str(datetime.now())[:10], start_date=start_date_str, end_date=end_date_str) @@ -515,7 +520,9 @@ class TodoHandler(PlomHandler): db.t_filter_not += [target] if 'hide_unchosen' in postvars.keys(): db.hide_unchosen = True - data = [('t_and', f) for f in db.t_filter_and] + [('t_not', f) for f in db.t_filter_not] + [('hide_unchosen', int(db.hide_unchosen))] + if 'hide_done' in postvars.keys(): + db.hide_done = True + data = [('t_and', f) for f in db.t_filter_and] + [('t_not', f) for f in db.t_filter_not] + [('hide_unchosen', int(db.hide_unchosen))] + [('hide_done', int(db.hide_done))] if parsed_url.path == prefix + '/tasks': encoded_params = urlencode(data) @@ -561,7 +568,9 @@ class TodoHandler(PlomHandler): t_filter_not = params.get('t_not', ['deleted']) hide_unchosen_params = params.get('hide_unchosen', []) hide_unchosen = len(hide_unchosen_params) > 0 and hide_unchosen_params[0] != '0' - db = TodoDB(prefix, selected_date, t_filter_and, t_filter_not, hide_unchosen) + hide_done_params = params.get('hide_done', []) + hide_done = len(hide_done_params) > 0 and hide_done_params[0] != '0' + db = TodoDB(prefix, selected_date, t_filter_and, t_filter_not, hide_unchosen, hide_done) if parsed_url.path == prefix + '/day': page = db.show_day() elif parsed_url.path == prefix + '/todo':