+ 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 show_day(self, task_sort=None):
+ task_sort = task_sort if task_sort else 'title'
+ 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)
+ task_rows = []
+ for uuid, task in self.tasks.items():
+ if not task.visible:
+ continue
+ todo = None
+ if uuid in self.selected_day.todos.keys():
+ todo = self.selected_day.todos[uuid]
+ if not todo.visible:
+ continue
+ task_rows += [{'uuid': uuid, 'task': task, 'todo': todo}]
+ if task_sort == 'title':
+ task_rows.sort(key=lambda r: r['task'].title)
+ elif task_sort == 'default_effort':
+ task_rows.sort(key=lambda r: r['task'].default_effort, reverse=True)
+ elif task_sort == 'done':
+ task_rows.sort(key=lambda r: 0 if not r['todo'] else r['todo'].day_effort if r['todo'].day_effort else r['task'].default_effort if r['todo'].done else 0, reverse=True)
+ elif task_sort == 'importance':
+ task_rows.sort(key=lambda r: 0.0 if not r['todo'] else r['todo'].importance, reverse=True)
+ elif task_sort == 'chosen':
+ task_rows.sort(key=lambda r: False if not r['todo'] else True, reverse=True)
+ elif task_sort == 'comment':
+ task_rows.sort(key=lambda r: '' if not r['todo'] else r['todo'].comment, reverse=True)
+ done_tasks = []
+ for uuid, task in self.tasks.items():
+ if uuid in self.selected_day.todos.keys():
+ todo = self.selected_day.todos[uuid]
+ if todo.done:
+ done_tasks += [todo]
+ done_tasks.sort(key=lambda t: t.effort, reverse=True)
+ return j2env.get_template('day.html').render(db=self, action=self.prefix+'/day', prev_date=prev_date_str, next_date=next_date_str, task_rows=task_rows, sort=task_sort, done_tasks=done_tasks)
+
+ 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_day(self, sort_order=None):
+ prev_date_str, next_date_str = self.neighbor_dates()
+ # 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)
+ 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)
+ 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.task.default_effort, reverse=True)
+ elif sort_order == 'importance':
+ todos.sort(key=lambda t: t.importance, reverse=True)
+ return j2env.get_template('do_day.html').render(
+ day=self.selected_day,
+ 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 = 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, action=self.prefix+'/calendar', start_date=start_date_str, end_date=end_date_str)
+
+ def show_todo(self, id_, return_to):
+ todo = self.todos[id_]
+ # if selected_date not in self.days.keys():
+ # self.days[selected_date] = self.add_day(test_date=f'3:{selected_date}')
+ # # print("DEBUG show_todo", self.days[selected_date].date)
+ # if task_uuid in self.days[selected_date].todos:
+ # todo = self.days[selected_date].todos[task_uuid]
+ # else:
+ # todo = self.days[selected_date].add_todo(task_uuid)
+ return j2env.get_template('todo.html').render(db=self, todo=todo, action=self.prefix+'/todo', return_to=return_to)
+
+ def update_todo_mini(self, task_uuid, date, day_effort, done, importance):
+ if date not in self.days.keys():
+ self.days[date] = self.add_day(test_date=f'Y:{date}')
+ # print("DEBUG update_todo_min", self.days[date].date)
+ if task_uuid in self.days[date].todos.keys():
+ todo = self.days[date].todos[task_uuid]
+ else:
+ todo = self.days[date].add_todo(task_uuid)
+ todo.day_effort = day_effort
+ todo.done = done
+ todo.importance = importance
+ return todo