<a href="{{prefix}}/all">all</a> | edit day:
<a href="{{prefix}}/day">choose</a>
<a href="{{prefix}}/day?hide_unchosen=1">do</a>
+<a href="{{prefix}}/coming">coming</a>
<hr />
"""
-
form_footer = '\n</form>'
+form_header_tmpl = """
+<form action="{{action|e}}" method="POST">
+"""
archived_days_tmpl = """
<table>
-{% for date, day in db.days.items() | sort(reverse=True) %}
+{% for date, day in days.items() | sort(reverse=True) %}
{% if day.archived %}
-<tr><td>{{ date }} ({{ day.todos_sum |round(2) }}) {{ day.comment|e }} <input type="submit" name="edit_{{date}}" value="edit" /></td></tr>
+<tr><td>{{ date }} {{ day.weekday }} ({{ day.todos_sum|round(2) }}) {{ day.comment|e }} <input type="submit" name="edit_{{date}}" value="edit" /></td></tr>
{% for task, todo in day.todos.items() | sort(attribute='1.title', reverse=True) %}
<tr><td>{{ todo.title }}</td><td>{% if todo.done %}✓{% endif %}</td><td>{{ todo.weight }}</td></tr>
{% endfor %}
{% endfor %}
</table>
"""
-
selected_day_tmpl = """
-<form action="{{action|e}}" method="POST">
hiden unchosen: <input name="hide_unchosen" type="checkbox" {% if db.hide_unchosen %}checked{% endif %} /><br />
mandatory tags: {% for t_tag in db.t_tags | sort %}
<input name="t_filter_and" type="checkbox" value="{{ t_tag }}" {% if t_tag in db.t_filter_and %} checked {% endif %} >{{ t_tag }}
d['days'][date] = day.to_dict()
return d
+ @property
+ def selected_day(self):
+ return self.days[self.selected_day_date]
+
def write(self):
self.write_text_to_db(json.dumps(self.to_dict()))
self.selected_day_date = date
else:
self.selected_day_date = str(datetime.now())[:10]
- if not self.selected_day_date in self.days.keys():
- self.days[self.selected_day_date] = self.add_day()
+ if not self.selected_day_date in self.days.keys():
+ self.days[self.selected_day_date] = self.add_day()
self.selected_day.archived = False
def add_task(self, id_=None, dict_source=None, return_id=False):
for date, day in self.days.items():
for task_uuid, todo in day.todos.items():
todo.title = self.tasks[task_uuid].title_at(date)
- return Template(selected_day_tmpl + archived_days_tmpl + form_footer).render(db=self, action=self.prefix+'/all')
-
- @property
- def selected_day(self):
- return self.days[self.selected_day_date]
+ return Template(form_header_tmpl + selected_day_tmpl + archived_days_tmpl + form_footer).render(db=self, action=self.prefix+'/all', days=self.days)
def show_selected_day(self):
- return Template(selected_day_tmpl + form_footer).render(db=self, action=self.prefix+'/day')
+ return Template(form_header_tmpl + selected_day_tmpl + form_footer).render(db=self, action=self.prefix+'/day')
+
+ def show_coming(self):
+ from datetime import timedelta
+ todays_date = str(datetime.now())[:10]
+ days_to_show = self.days.copy()
+ for day in days_to_show.values():
+ day.archived = False
+ last_date = sorted(days_to_show.keys())[-1]
+ start_date = datetime.strptime(todays_date, '%Y-%m-%d')
+ end_date = datetime.strptime(last_date, '%Y-%m-%d')
+ for n in range(int((end_date - start_date).days) + 1):
+ current_date_obj = start_date + timedelta(n)
+ current_date = current_date_obj.strftime('%Y-%m-%d')
+ if current_date not in days_to_show.keys():
+ days_to_show[current_date] = self.add_day()
+ days_to_show[current_date].archived = True
+ days_to_show[current_date].weekday = datetime.strptime(current_date, '%Y-%m-%d').strftime('%A')
+ for task_uuid, todo in days_to_show[current_date].todos.items():
+ todo.title = self.tasks[task_uuid].title_at(current_date)
+ return Template(form_header_tmpl + archived_days_tmpl + form_footer).render(db=self, action=self.prefix+'/day', days=days_to_show)
class TodoHandler(PlomHandler):
day_weight = float(postvars['day_weight'][i]) if postvars['day_weight'][i] else None
db.selected_day.add_todo(uuid, {'done': done, 'day_weight': day_weight})
- db.selected_day.comment = postvars['comment'][0]
- new_selected_day_date = postvars['selected_day_date'][0]
- if new_selected_day_date != db.selected_day_date:
- if new_selected_day_date in db.days.keys():
- raise PlomException('cannot use same date twice')
- else:
- db.days[new_selected_day_date] = db.selected_day
- del db.days[db.selected_day_date]
- db.selected_day_date = new_selected_day_date
+ if 'comment' in postvars.keys():
+ db.selected_day.comment = postvars['comment'][0]
+ if 'selected_day_date' in postvars.keys():
+ new_selected_day_date = postvars['selected_day_date'][0]
+ try:
+ datetime.strptime(new_selected_day_date, '%Y-%m-%d')
+ except ValueError:
+ raise PlomException(f"{prefix} bad date string: {new_selected_day_date}")
+ if new_selected_day_date != db.selected_day_date:
+ if new_selected_day_date in db.days.keys():
+ raise PlomException('cannot use same date twice')
+ else:
+ db.days[new_selected_day_date] = db.selected_day
+ del db.days[db.selected_day_date]
+ db.selected_day_date = new_selected_day_date
switch_edited_day = None
- for date in db.days.keys():
- if f'edit_{date}' in postvars.keys():
- switch_edited_day = date
+ day_edit_prefix = 'edit_'
+ for k in postvars.keys():
+ if k.startswith(day_edit_prefix):
+ switch_edited_day = k[len(day_edit_prefix):]
break
if 'archive_day' in postvars.keys() or switch_edited_day:
- if switch_edited_day:
- db.switch_to_day(date)
- else:
- db.switch_to_day()
+ db.switch_to_day(switch_edited_day)
db.write()
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))]
encoded_params = urlencode(data)
db = TodoDB(prefix, t_filter_and, t_filter_not, hide_unchosen)
if parsed_url.path == prefix + '/day':
page = db.show_selected_day()
+ elif parsed_url.path == prefix + '/coming':
+ page = db.show_coming()
else:
page = db.show_all()
header = Template(html_head).render(prefix=prefix)