An ADHD-friendly regular task tracker
修订版 | ae06d844044ab32a5fd40ee4cfb1aad533dacff2 (tree) |
---|---|
时间 | 2024-03-10 10:08:47 |
作者 | Corbin <cds@corb...> |
Commiter | Corbin |
Put more string formatting into templates.
Also redo the calendrical maths again. This is one of the situations
where types would not help.
@@ -20,7 +20,7 @@ def root(): return "Working on it..." | ||
20 | 20 | SHOW_QUERY = """ |
21 | 21 | select label, description, updated_at, consequences_after_s from tasks |
22 | 22 | where updated_at + available_every_s <= unixepoch() and wheel = ? |
23 | -order by updated_at + consequences_after_s desc | |
23 | +order by updated_at + consequences_after_s asc | |
24 | 24 | """ |
25 | 25 | |
26 | 26 | SHOW_ALL_QUERY = """ |
@@ -32,33 +32,20 @@ order by updated_at asc | ||
32 | 32 | def roundUp(delta): return timedelta(seconds=delta).days + 1 |
33 | 33 | def roundDown(delta): return timedelta(seconds=delta).days - 1 |
34 | 34 | |
35 | -def formatTask(row): | |
36 | - label = html.escape(row[0]) | |
37 | - now = datetime.now() | |
38 | - updated_at = datetime.fromtimestamp(row[2]) | |
39 | - updated_delta = now - updated_at | |
40 | - consequences_after = timedelta(seconds=row[3]) | |
41 | - consequences_at = updated_at + consequences_after | |
42 | - if consequences_at <= now: | |
43 | - warning = "needs to be done immediately or there will be consequences" | |
44 | - else: | |
45 | - consequences_delta = consequences_at - now | |
46 | - warning = "needs to be done within %d days" % consequences_delta.days | |
47 | - return "{1} ({0}): Last done {2} days ago, {3}".format( | |
48 | - label, html.escape(row[1]), updated_delta.days + 1, warning) | |
49 | - | |
50 | -def formatEvery(row): | |
51 | - description = html.escape(row[0]) | |
52 | - available_every = timedelta(seconds=row[1]).days | |
53 | - consequences_after = timedelta(seconds=row[2]).days | |
54 | - return "{0}: every {1} days, no less than every {2} days".format( | |
55 | - description, available_every, consequences_after) | |
35 | +def prepDates(updated_at_dt, consequences_after_s): | |
36 | + updated_at = datetime.now() - datetime.fromtimestamp(updated_at_dt) | |
37 | + consequences_after = timedelta(seconds=consequences_after_s) | |
38 | + return updated_at, consequences_after - updated_at | |
39 | + | |
40 | +@app.template_filter("deltadays") | |
41 | +def deltaDays(s): return timedelta(seconds=s).days | |
56 | 42 | |
57 | 43 | @app.route("/show/<wheel>") |
58 | 44 | def show(wheel): |
59 | 45 | c = cursor() |
60 | - l = [formatTask(row) for row in c.execute(SHOW_QUERY, (wheel,))] | |
61 | - dets = [formatEvery(row) for row in c.execute(SHOW_ALL_QUERY, (wheel,))] | |
46 | + l = [(row[0], row[1]) + prepDates(row[2], row[3]) | |
47 | + for row in c.execute(SHOW_QUERY, (wheel,))] | |
48 | + dets = c.execute(SHOW_ALL_QUERY, (wheel,)) | |
62 | 49 | return render_template("show.html", wheel=wheel, availableTasks=l, |
63 | 50 | allTasks=dets) |
64 | 51 |
@@ -3,15 +3,23 @@ | ||
3 | 3 | <h1>Tasks for {{ wheel }}</h1> |
4 | 4 | |
5 | 5 | <ol> |
6 | - {% for task in availableTasks %} | |
7 | - <li>{{ task }}</li> | |
6 | + {% for label, description, updated_delta, consequences_delta in availableTasks %} | |
7 | + <li>{{ description }} ({{ label }}): Last done {{ updated_delta.days + 1 | |
8 | + }} days ago, | |
9 | + {% if consequences_delta.total_seconds() is lt(0) %} | |
10 | + needs to be done immediately or there will be consequences | |
11 | + {% else %} | |
12 | + needs to be done within {{ consequences_delta.days }} days | |
13 | + {% endif %} | |
14 | + </li> | |
8 | 15 | {% endfor %} |
9 | 16 | </ol> |
10 | 17 | |
11 | 18 | <details> |
12 | 19 | <ul> |
13 | - {% for task in allTasks %} | |
14 | - <li>{{ task }}</li> | |
20 | + {% for description, available_every, consequences_after in allTasks %} | |
21 | + <li>{{ description }}: every {{ available_every | deltadays }}–{{ | |
22 | + consequences_after | deltadays }} days</li> | |
15 | 23 | {% endfor %} |
16 | 24 | </ul> |
17 | 25 | </details> |