<input type="submit" name="add_taxes" value="add taxes" />
<input type="submit" name="add_taxes2" value="add taxes2" />
<input type="submit" name="add_sink" value="add sink" />
+<input name="replace_from" />
+<input type="submit" name="replace" value="-> replace ->" />
+<input name="replace_to" />
<br />
<input name="date" value="{{date|e}}" size=9 />
<input name="description" value="{{desc|e}}" list="descriptions" />
lines += [f'Assets {amount:.2f} {currency}']
except PlomException:
pass
- if 'add_taxes' in postvars.keys():
+ elif 'add_taxes' in postvars.keys():
lines += self.add_taxes(lines, finish=False)
elif 'add_taxes2' in postvars.keys():
lines += self.add_taxes(lines, finish=True)
+ elif 'replace' in postvars.keys():
+ for i, line in enumerate(lines):
+ lines[i] = line.replace(postvars['replace_from'][0], postvars['replace_to'][0])
return lines, add_empty_line
{% endfor %}
<table>
<tr><th colspan=2></th><th>date</th><td colspan=2><input name="today_date" value="{{ db.today_date }}" size=8 /></td><th>archive?</th><td><input type="checkbox" name="archive_today" /></td><td>{{ db.today.todos_sum|round(2) }}</td><th>comment:</th><td><input name="comment" value="{{ db.today.comment|e }}"></td></tr>
-<tr><th>weight</th><th>title</th><th>tags</th><th>today?</th><th>done?</th><th colspan=2>day weight</th></tr>
+<tr><th>default<br />weight</th><th>title</th><th>tags</th><th>today?</th><th>done?</th><th colspan=2>day<br />weight</th></tr>
{% for uuid, t in db.tasks.items() | sort(attribute='1.title', reverse=True) %}
{% if t.visible %}
<input name="t_uuid" value="{{ uuid }}" type="hidden" >
<td><input name="t_tags" value="{{ t.tags_joined|e }}" >
<td><input name="do_today" type="checkbox" value="{{ uuid }}" {% if uuid in db.today.todos.keys() %}checked{% endif %} ></td>
<td><input name="done" type="checkbox" value="{{ uuid }}" {% if uuid in db.today.todos.keys() and db.today.todos[uuid].done %}checked{% endif %} ></td>
-<td colspan=2><input name="day_weight" type="number" step=0.1 size=5 value="{% if uuid in db.today.todos.keys() and db.today.todos[uuid].day_weight %}{{ db.today.todos[uuid].day_weight }}{% endif %}" ></td>
+<td colspan=2><input name="weight" type="number" step=0.1 size=5 value="{% if uuid in db.today.todos.keys() and db.today.todos[uuid].weight %}{{ db.today.todos[uuid].weight }}{% endif %}" ></td>
</tr>
{% endif %}
{% endfor %}
def title(self):
return self._last_of_history(self.title_history, '')
+ def title_at(self, queried_date):
+ ret = self.title_history[sorted(self.title_history.keys())[0]]
+ for date_key, title in self.title_history.items():
+ if date_key > f'{queried_date} 23:59:59':
+ break
+ ret = title
+ return ret
+
def set_tags(self, tags):
self._set_with_history(self.tags_history, set(tags))
@property
def todos_sum(self):
s = 0
- for todo in [todo for todo in self.todos.values() if (todo.done or todo.day_weight)]:
+ for todo in [todo for todo in self.todos.values() if todo.done]:
s += todo.weight
return s
class Todo:
- def __init__(self, done=False, day_weight=None):
+ def __init__(self, done=False, weight=None):
self.done = done
- self.day_weight = day_weight
+ self.weight = weight
@classmethod
def from_dict(cls, d):
- return cls(d['done'], d['day_weight'])
+ return cls(d['done'], d['weight'])
def to_dict(self):
- return {'done': self.done, 'day_weight': self.day_weight}
+ return {'done': self.done, 'weight': self.weight}
class TodoDB(PlomDB):
def write(self):
self.write_text_to_db(json.dumps(self.to_dict()))
+ def save_today(self):
+ if self.today_date in self.old_days.keys():
+ raise PlomException('cannot use same date twice')
+ for task_uuid, todo in [(task_uuid, todo) for task_uuid, todo in self.today.todos.items()
+ if not todo.weight]:
+ todo.weight = self.tasks[task_uuid].default_weight
+ self.old_days[self.today_date] = self.today
+
def reset_today(self, date=None):
if date:
self.today_date = date
for i, uuid in enumerate(postvars['t_uuid']):
if uuid in postvars['do_today']:
done = 'done' in postvars and uuid in postvars['done']
- day_weight = float(postvars['day_weight'][i]) if postvars['day_weight'][i] else None
- db.today.todos[uuid] = Todo(done, day_weight)
+ weight = float(postvars['weight'][i]) if postvars['weight'][i] else None
+ db.today.todos[uuid] = Todo(done, weight)
db.today_date = postvars['today_date'][0]
db.today.comment = postvars['comment'][0]
switch_edited_day = None
switch_edited_day = date
break
if 'archive_today' in postvars.keys() or switch_edited_day:
- if db.today_date in db.old_days.keys():
- raise PlomException('cannot use same date twice')
- db.old_days[db.today_date] = db.today
+ db.save_today()
if switch_edited_day:
db.reset_today(date)
else:
db = TodoDB(t_filter_and, t_filter_not)
for i in range(10):
db.tasks[f'new{i}'] = Task()
- for task_uuid, todo in db.today.todos.items():
- todo.weight = todo.day_weight if todo.day_weight else db.tasks[task_uuid].default_weight
for date, day in db.old_days.items():
for task_uuid, todo in day.todos.items():
- todo.title = db.tasks[task_uuid].title
- todo.weight = todo.day_weight if todo.day_weight else db.tasks[task_uuid].default_weight
+ todo.title = db.tasks[task_uuid].title_at(date)
page = Template(tmpl).render(db=db)
self.send_HTML(page)