home · contact · privacy
Improve todo accounting.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 29 Feb 2024 03:59:47 +0000 (04:59 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 29 Feb 2024 03:59:47 +0000 (04:59 +0100)
todo.py
todo_templates/calendar.html
todo_templates/calendar_export.html [new file with mode: 0644]
todo_templates/day_todos.html
todo_templates/macros.html
todo_templates/task.html
todo_templates/tasks.html
todo_templates/todo.html
todo_templates/watch_form.html

diff --git a/todo.py b/todo.py
index c3551a44aefb9040cf406cf133628c08a7c60241..94f3882f3c683bee5aa3b80a2922be660f70575c 100644 (file)
--- a/todo.py
+++ b/todo.py
@@ -21,27 +21,31 @@ def today_date(with_time=False):
 
 class AttributeWithHistory:
 
-    def __init__(self, default_if_empty, history=None, then_date='2000-01-01', set_check=None):
+    def __init__(self, parent, name, default_if_empty, history=None, then_date='2000-01-01', set_check=None):
+        self.parent = parent 
+        self.name = name
         self.default = default_if_empty
         self.then_date = then_date
         self.history = history if history else {}
         self.set_check = set_check
 
     def set(self, value):
-        print("DEBUG set", value, "HAS SET CHECK?", self.set_check)
         if self.set_check:
-            print("DEBUG set CALLED SET CHECK")
             self.set_check(value)
         keys = sorted(self.history.keys())
         if len(self.history) == 0 or value != self.history[keys[-1]]:
             self.history[today_date(with_time=True)] = value
 
     def at(self, queried_date):
-        if 0 == len(self.history):
+        end_of_queried_day = f'{queried_date} 23:59:59'
+        sorted_dates = sorted(self.history.keys())
+        if self.parent.forked_task and (0 == len(sorted_dates) or sorted_dates[0] > end_of_queried_day):
+            return getattr(self.parent.forked_task, self.name).at(queried_date)
+        elif 0 == len(sorted_dates):
             return self.default
-        ret = self.history[sorted(self.history.keys())[0]]
+        ret = self.history[sorted_dates[0]]
         for date_key, item in self.history.items():
-            if date_key > f'{queried_date} 23:59:59':
+            if date_key > end_of_queried_day:
                 break
             ret = item
         return ret
@@ -49,7 +53,11 @@ class AttributeWithHistory:
     @property
     def now(self):
         keys = sorted(self.history.keys())
-        return self.default if 0 == len(self.history) else self.history[keys[-1]]
+        if 0 == len(self.history):
+            if self.parent.forked_task:
+                return getattr(self.parent.forked_task, self.name).now
+            return self.default
+        return self.history[keys[-1]]
 
     @property
     def then(self):
@@ -102,12 +110,14 @@ class Task(TaskLike):
             tags_history=None,
             default_effort_history=None,
             dep_ids_history=None,
-            comment=''):
+            comment='',
+            forks_id=None):
         super().__init__(db, id_, comment)
-        self.title = AttributeWithHistory('', title_history, self.db.selected_date)
-        self.tags = AttributeWithHistory(set(), tags_history, self.db.selected_date)
-        self.default_effort = AttributeWithHistory(0.0, default_effort_history, self.db.selected_date)
-        self.dep_ids = AttributeWithHistory(set(), dep_ids_history, self.db.selected_date, set_check=self.dep_loop_checker())
+        self.forks_id = forks_id 
+        self.title = AttributeWithHistory(self, 'title', '', title_history, self.db.selected_date)
+        self.tags = AttributeWithHistory(self, 'tags', set(), tags_history, self.db.selected_date)
+        self.default_effort = AttributeWithHistory(self, 'default_effort', 0.0, default_effort_history, self.db.selected_date)
+        self.dep_ids = AttributeWithHistory(self, 'dep_ids', set(), dep_ids_history, self.db.selected_date, set_check=self.dep_loop_checker())
 
     @classmethod
     def from_dict(cls, db, d, id_):
@@ -118,7 +128,8 @@ class Task(TaskLike):
                {k: set(v) for k, v in d['tags_history'].items()},
                d['default_effort_history'],
                {k: set(v) for k, v in d['deps_history'].items()},
-               d['comment'])
+               d['comment'],
+               d['forks'])
         return t
 
     def to_dict(self):
@@ -128,8 +139,24 @@ class Task(TaskLike):
             'tags_history': {k: list(v) for k, v in self.tags.history.items()},
             'deps_history': {k: list(v) for k, v in self.dep_ids.history.items()},
             'comment': self.comment,
+            'forks': self.forks_id,
         }
 
+    # def fork(self):
+    #     now = today_date(with_time=True)
+    #     dict_source = {
+    #         'title_history': {now: self},
+    #         'default_effort_history': {now: self}, 
+    #         'tags_history': {now: self},
+    #         'deps_history': {now: self},
+    #         'comment': self.comment,
+    #         'forks': self.id_}
+    #     return self.db.add_task(dict_source=dict_source)
+
+    @property
+    def forked_task(self):
+        return self.db.tasks[self.forks_id] if self.forks_id else None
+
     @property
     def deps(self):
         deps = []
@@ -167,6 +194,15 @@ class Task(TaskLike):
         else:
             return search in self.title.now or search in self.comment or search in '$'.join(self.tags.now)
 
+    @property
+    def latest_effort_date(self):
+        todos = [t for t in self.db.todos.values() if t.task.id_ == self.id_]
+        todos.sort(key=lambda t: t.latest_date)
+        if len(todos) > 0:
+            return todos[-1].latest_date 
+        else:
+            return '' 
+
 
 
 class Day:
@@ -234,6 +270,10 @@ class Day:
             todos = trunk 
         return todos
 
+    @property
+    def visible_in_export(self):
+        return len(self.comment) + len([t for t in self.linked_todos_as_list if t.visible]) > 0
+
 
 
 class Todo(TaskLike):
@@ -251,6 +291,11 @@ class Todo(TaskLike):
         super().__init__(db, id_, comment)
         self.task = task 
         self._done = done
+        for k in efforts.keys():
+            try:
+                datetime.strptime(k, DATE_FORMAT)
+            except ValueError:
+                raise PlomException(f'Todo creation: bad date string: {k}')
         self.efforts = efforts if efforts else {}
         self.day_tags = day_tags if day_tags else set()
         self.importance = importance
@@ -475,7 +520,7 @@ class TodoDB(PlomDB):
                 dep.dependers += [task]
 
         for id_, todo_dict in d['todos'].items():
-            todo = self.add_todo(todo_dict, id_, link_into_day=False)
+            todo = self.add_todo(todo_dict, id_)
             for tag in todo.day_tags:
                 self.t_tags.add(tag)
         for todo in self.todos.values():
@@ -532,41 +577,60 @@ class TodoDB(PlomDB):
         self.tasks[id_] = t
         return t
 
-    def update_task(self, id_, title, default_effort, tags, dep_ids, comment):
+    def fork_task(self, id_):
+        origin = self.tasks[id_]
+        now = today_date(with_time=True)
+        fork_id = str(uuid4())
+        fork = Task(self, fork_id, {}, {}, {}, {}, origin.comment, id_)
+        self.tasks[fork_id] = fork
+        return fork
+
+    def update_task(self, id_, title, default_effort, tags, comment, dep_ids, depender_ids):
         task = self.tasks[id_] if id_ in self.tasks.keys() else self.add_task(id_)
         task.title.set(title)
         task.default_effort.set(default_effort)
         task.tags.set(tags)
         task.dep_ids.set(dep_ids)
         task.comment = comment 
+        for depender in task.dependers:
+            if not depender.id_ in depender_ids:
+                depender_dep_ids = depender.dep_ids.now
+                depender_dep_ids.remove(task.id_)
+                depender.dep_ids.set(depender_dep_ids)
+        for depender_id in depender_ids:
+            depender= self.tasks[depender_id]
+            depender_dep_ids = depender.dep_ids.now
+            depender_dep_ids.add(task.id_)
+            depender.dep_ids.set(depender_dep_ids)
         return task
 
-    def add_todo(self, todo_dict=None, id_=None, task=None, efforts=None, link_into_day=True, adopt_if_possible=True):
+    def add_todo(self, todo_dict=None, id_=None, task=None, efforts=None, parenthood=''):
+        make_children = parenthood != 'childless'
+        adopt_if_possible = parenthood == 'adoption'
         id_ = id_ if id_ else str(uuid4())
         if todo_dict:
             todo = Todo.from_dict(self, todo_dict, id_)
         elif task and efforts:
             todo = Todo(self, id_, task, efforts=efforts)
             deps = []
-            for dep_task in task.deps:
-                # if Todo expects dependencies, adopt any compatibles found in DB.selected_date
-                # before creating new depended Todos
-                dep_todo = None
-                if adopt_if_possible and list(efforts.keys())[0] == self.selected_date:
-                    adoptable_todos = [t for t in self.selected_day.linked_todos_as_list
-                                       if t.task.id_ == dep_task.id_]
-                    if len(adoptable_todos) > 0:
-                        dep_todo = adoptable_todos[0]
-                if not dep_todo:
-                    dep_todo = self.add_todo(task=dep_task, efforts=efforts,
-                                               link_into_day=link_into_day,
-                                               adopt_if_possible=adopt_if_possible)
-                deps += [dep_todo]
-            # todo.dep_ids = [dep.id_ for dep in deps]
+            if make_children and todo.latest_date in self.days.keys():
+                for dep_task in task.deps:
+                    # if Todo expects dependencies, adopt any compatibles found in DB.selected_date
+                    # before creating new depended Todos
+                    dep_todo = None
+                    if adopt_if_possible:
+                        adoptable_todos = [t for t in self.days[todo.latest_date].linked_todos_as_list
+                                           if t.task.id_ == dep_task.id_]
+                        if len(adoptable_todos) > 0:
+                            dep_todo = adoptable_todos[0]
+                    if not dep_todo:
+                        dep_todo = self.add_todo(task=dep_task, efforts=efforts, parenthood=parenthood)
+                    deps += [dep_todo]
             todo.deps = deps 
         self.todos[id_] = todo 
-        if link_into_day:
-            self.selected_day.linked_todos_as_list += [todo] 
+        for date in todo.efforts.keys():
+            if date in self.days.keys():  # possibly not all Days have been initialized yet
+                self.days[date].linked_todos_as_list += [todo] 
         return todo
 
     def _update_todo_shared(self, id_, done, comment, importance):
@@ -618,41 +682,46 @@ class TodoDB(PlomDB):
     def show_message(self, message):
         return j2env.get_template('message.html').render(message=message)
 
-    def show_calendar(self, start_date_str, end_date_str):
-        self.tag_filter_and = ['calendar']
-        self.tag_filter_not = ['deleted']
-
-        todays_date_obj = datetime.strptime(today_date(), DATE_FORMAT) 
-        yesterdays_date_obj = todays_date_obj - timedelta(1)
-        def get_day_limit_obj(index, day_limit_string):
-            date_obj = datetime.strptime(sorted(self.days.keys())[index], DATE_FORMAT)
-            if day_limit_string and len(day_limit_string) > 0:
-                if day_limit_string in {'today', 'yesterday'}:
-                    date_obj = todays_date_obj if day_limit_string == 'today' else yesterdays_date_obj
-                else:
-                    date_obj = datetime.strptime(day_limit_string, DATE_FORMAT)
-            return date_obj
-        start_date_obj = get_day_limit_obj(0, start_date_str)
-        end_date_obj = get_day_limit_obj(-1, end_date_str)
-
-        days_to_show = {}
-        for n in range(int((end_date_obj - start_date_obj).days) + 1):
-            date_obj = start_date_obj + timedelta(n)
-            date_str = date_obj.strftime(DATE_FORMAT)
-            if date_str not in self.days.keys():
-                days_to_show[date_str] = self.add_day(date_str)
-            else:
-                days_to_show[date_str] = self.days[date_str]
-            days_to_show[date_str].month_title = date_obj.strftime('%B') if date_obj.day == 1 else None 
-            days_to_show[date_str].weekday = datetime.strptime(date_str, DATE_FORMAT).strftime('%A')[:2]
+    def show_calendar_export(self, start_date_str, end_date_str):
+        days_to_show = self.init_calendar_items(start_date_str, end_date_str)
+        return j2env.get_template('calendar_export.html').render(days=days_to_show)
 
+    def show_calendar(self, start_date_str, end_date_str):
+        # self.tag_filter_and = ['calendar']
+        # self.tag_filter_not = ['deleted']
+
+        # todays_date_obj = datetime.strptime(today_date(), DATE_FORMAT) 
+        # yesterdays_date_obj = todays_date_obj - timedelta(1)
+        # def get_day_limit_obj(index, day_limit_string):
+        #     date_obj = datetime.strptime(sorted(self.days.keys())[index], DATE_FORMAT)
+        #     if day_limit_string and len(day_limit_string) > 0:
+        #         if day_limit_string in {'today', 'yesterday'}:
+        #             date_obj = todays_date_obj if day_limit_string == 'today' else yesterdays_date_obj
+        #         else:
+        #             date_obj = datetime.strptime(day_limit_string, DATE_FORMAT)
+        #     return date_obj
+        # start_date_obj = get_day_limit_obj(0, start_date_str)
+        # end_date_obj = get_day_limit_obj(-1, end_date_str)
+
+        # days_to_show = {}
+        # for n in range(int((end_date_obj - start_date_obj).days) + 1):
+        #     date_obj = start_date_obj + timedelta(n)
+        #     date_str = date_obj.strftime(DATE_FORMAT)
+        #     if date_str not in self.days.keys():
+        #         days_to_show[date_str] = self.add_day(date_str)
+        #     else:
+        #         days_to_show[date_str] = self.days[date_str]
+        #     days_to_show[date_str].month_title = date_obj.strftime('%B') if date_obj.day == 1 else None 
+        #     days_to_show[date_str].weekday = datetime.strptime(date_str, DATE_FORMAT).strftime('%A')[:2]
+
+        days_to_show = self.init_calendar_items(start_date_str, end_date_str)
         return j2env.get_template('calendar.html').render(
                 selected_date=self.selected_date,
                 days=days_to_show,
                 start_date=start_date_str,
                 end_date=end_date_str)
 
-    def show_day_todos(self, undone_sort_order=None, done_sort_order=None, is_tree_shaped=False):
+    def show_day_todos(self, undone_sort_order=None, done_sort_order=None, is_tree_shaped=False, todo_parenthood=None):
         legal_undone_sort_keys = {'title', 'sort_done', 'default_effort', 'importance'} 
         legal_done_sort_keys = {'title', 'effort_at_selected_date', 'family_effort'} 
 
@@ -686,9 +755,10 @@ class TodoDB(PlomDB):
                 done_todos=done_todos,
                 is_tree_shaped=is_tree_shaped,
                 undone_sort=undone_sort_order,
-                done_sort=done_sort_order)
+                done_sort=done_sort_order,
+                parenthood=todo_parenthood)
 
-    def show_todo(self, id_):
+    def show_todo(self, id_, parenthood):
         todo = self.todos[id_]
         filtered_tasks = [t for t in self.tasks.values()
                           if t != todo.task] 
@@ -723,10 +793,16 @@ class TodoDB(PlomDB):
                 dep_slots=dep_slots,
                 suggested_todos=suggested_todos,
                 additional_deps=additional_deps,
+                parentood=parenthood, 
                 dep_todos=todo.deps)
 
     def show_task(self, id_):
-        task = self.tasks[id_] if id_ else self.add_task()
+        if id_:
+            if not id_ in self.tasks.keys():
+                raise PlomException('no Task for ID')
+            task = self.tasks[id_]
+        else:
+            task = self.add_task()
         if not id_:
             task.default_effort.set(1.0)
         filtered_tasks = [t for t in self.tasks.values()
@@ -754,6 +830,8 @@ class TodoDB(PlomDB):
             filtered_tasks.sort(key=lambda t: t.default_effort.now)
         elif sort_column == 'weight':
             filtered_tasks.sort(key=lambda t: t.deps_weight)
+        elif sort_column == 'latest_effort_date':
+            filtered_tasks.sort(key=lambda t: t.latest_effort_date)
         if reverse:
             filtered_tasks.reverse()
         return j2env.get_template('tasks.html').render(
@@ -764,6 +842,37 @@ class TodoDB(PlomDB):
                 filter_not=self.tag_filter_not,
                 search=search)
 
+    # helpers
+
+    def init_calendar_items(self, start_date_str, end_date_str):
+        self.tag_filter_and = ['calendar']
+        self.tag_filter_not = ['deleted']
+
+        todays_date_obj = datetime.strptime(today_date(), DATE_FORMAT) 
+        yesterdays_date_obj = todays_date_obj - timedelta(1)
+        def get_day_limit_obj(index, day_limit_string):
+            date_obj = datetime.strptime(sorted(self.days.keys())[index], DATE_FORMAT)
+            if day_limit_string and len(day_limit_string) > 0:
+                if day_limit_string in {'today', 'yesterday'}:
+                    date_obj = todays_date_obj if day_limit_string == 'today' else yesterdays_date_obj
+                else:
+                    date_obj = datetime.strptime(day_limit_string, DATE_FORMAT)
+            return date_obj
+        start_date_obj = get_day_limit_obj(0, start_date_str)
+        end_date_obj = get_day_limit_obj(-1, end_date_str)
+
+        days_to_show = {}
+        for n in range(int((end_date_obj - start_date_obj).days) + 1):
+            date_obj = start_date_obj + timedelta(n)
+            date_str = date_obj.strftime(DATE_FORMAT)
+            if date_str not in self.days.keys():
+                days_to_show[date_str] = self.add_day(date_str)
+            else:
+                days_to_show[date_str] = self.days[date_str]
+            days_to_show[date_str].month_title = date_obj.strftime('%B') if date_obj.day == 1 else None 
+            days_to_show[date_str].weekday = datetime.strptime(date_str, DATE_FORMAT).strftime('%A')[:2]
+        return days_to_show
+
 
 
 class ParamsParser:
@@ -883,8 +992,9 @@ class TodoHandler(PlomHandler):
         if site in {'calendar', 'todo'}:
             redir_params += [('end', postvars.get('end', '-'))]
             redir_params += [('start', postvars.get('start', '-'))]
-        # if site in {'tasks', 'pick_tasks'}:
-        #     redir_params += [('search', postvars.get('search', ''))]
+        if site in {'day_todos', 'todo'}:
+            todo_parenthood = postvars.get('parenthood')
+            redir_params += [('parenthood', todo_parenthood)]
         if postvars.has('filter'): 
             postvars.set('return_to', '')
         
@@ -900,10 +1010,6 @@ class TodoHandler(PlomHandler):
             for i, date in enumerate(postvars.get_all('effort_date', [])):
                 if '' == date:
                     continue
-                try:
-                    datetime.strptime(date, DATE_FORMAT)
-                except ValueError:
-                    raise PlomException(f'bad date string')
                 latest_date = date
                 efforts[date] = None
                 if not (old_todo and old_todo.deps):
@@ -928,9 +1034,12 @@ class TodoHandler(PlomHandler):
                 for dep in deps:
                     if not todo_id in [t.id_ for t in dep.dependers]:
                         dep.dependers += [db.todos[todo_id]]
-                tasks_to_birth = [db.tasks[id_] for id_ in postvars.get_all('birth_dep', [])]
+                birth_dep_ids = postvars.get_all('birth_dep', [])
+                for id_ in [id_ for id_ in birth_dep_ids if not id_ in db.tasks.keys()]:
+                    raise PlomException('submitted illegal dep ID')
+                tasks_to_birth = [db.tasks[id_] for id_ in birth_dep_ids]
                 for task in tasks_to_birth:
-                    deps += [db.add_todo(task=task, efforts={latest_date: None})]
+                    deps += [db.add_todo(task=task, efforts={latest_date: None}, parenthood=todo_parenthood)]
                 db.update_todo(id_=todo_id,
                                efforts=efforts,
                                done=postvars.has('done'),
@@ -941,7 +1050,10 @@ class TodoHandler(PlomHandler):
 
         elif 'task' == site:
             task_id = postvars.get('task_id')
-            if postvars.has('delete') and task_id in db.tasks.keys():
+            if (postvars.has('delete') or postvars.has('fork')) and (not task_id in db.tasks.keys()):
+                if not task_id in db.tasks.keys():
+                    raise PlomException('can only do this on Task that already exists')
+            if postvars.has('delete'):
                 if [t for t in db.todos.values() if task_id == t.task.id_]:
                     raise PlomException('will not remove Task describing existing Todos')
                 if postvars.get('title', '')\
@@ -954,15 +1066,40 @@ class TodoHandler(PlomHandler):
                 dep_ids = postvars.get_all('dep', [])
                 for id_ in [id_ for id_ in dep_ids if not id_ in db.tasks.keys()]:
                     raise PlomException('submitted illegal dep ID')
+                depender_ids = postvars.get_all('depender', [])
+                for id_ in [id_ for id_ in depender_ids if not id_ in db.tasks.keys()]:
+                    raise PlomException('submitted illegal dep ID')
                 task = db.update_task(
                         id_=task_id,
                         title=postvars.get('title', ''),
                         default_effort=postvars.get('default_effort', float_if_possible=True), 
                         tags=postvars.get_all('tag', []),
+                        comment=postvars.get('comment', ''),
                         dep_ids=dep_ids,
-                        comment=postvars.get('comment', ''))
+                        depender_ids=depender_ids)
                 if postvars.has('add_as_todo'):
-                    db.add_todo(task=task, efforts={postvars.get('selected_date'): None})
+                    db.add_todo(task=task, efforts={postvars.get('new_todo_date'): None})
+            elif postvars.has('fork'):
+                t = db.fork_task(task_id)
+                task_id = t.id_
+
+                # dep_ids = postvars.get_all('dep', [])
+                # for id_ in [id_ for id_ in dep_ids if not id_ in db.tasks.keys()]:
+                #     raise PlomException('submitted illegal dep ID')
+                # depender_ids = postvars.get_all('depender', [])
+                # for id_ in [id_ for id_ in depender_ids if not id_ in db.tasks.keys()]:
+                #     raise PlomException('submitted illegal dep ID')
+                # task = db.update_task(
+                #         id_=task_id,
+                #         title=postvars.get('title', ''),
+                #         default_effort=postvars.get('default_effort', float_if_possible=True), 
+                #         tags=postvars.get_all('tag', []),
+                #         comment=postvars.get('comment', ''),
+                #         dep_ids=dep_ids,
+                #         depender_ids=depender_ids)
+                # if postvars.has('add_as_todo'):
+                #     db.add_todo(task=task, efforts={postvars.get('new_todo_date'): None})
+
             redir_params += [('id', task_id)]
 
         elif 'day_todos' == site:
@@ -975,7 +1112,7 @@ class TodoHandler(PlomHandler):
                     if task_id not in db.tasks.keys():
                         raise PlomException('illegal task ID entered')
                     db.add_todo(task=db.tasks[task_id], efforts={db.selected_date: None},
-                                adopt_if_possible=(not postvars.has('dont_adopt')))
+                                parenthood=todo_parenthood)
                 for id_ in postvars.get_all('choose_todo', []):
                     db.todos[id_].efforts[db.selected_date] = None
                 for i, todo_id in enumerate(postvars.get_all('todo_id', [])):
@@ -1028,6 +1165,11 @@ class TodoHandler(PlomHandler):
         if site in {'day_todos', 'tasks'}:
             tag_filter_and = params.get_cookied_chain('and_tag', prefix=site)
             tag_filter_not = params.get_cookied_chain('not_tag', prefix=site)
+        if site in {'day_todos', 'todo'}:
+            todo_parenthood = params.get_cookied('parenthood', prefix=site)
+        if site in {'calendar', 'calendar_export', ''}:
+            start_date = params.get_cookied('start', prefix=site)
+            end_date = params.get_cookied('end', prefix=site)
         db = TodoDB(selected_date, tag_filter_and, tag_filter_not)
         if site in {'todo', 'task'}:
             id_ = params.get('id')
@@ -1043,9 +1185,9 @@ class TodoHandler(PlomHandler):
             is_tree_shaped = params.get_cookied('tree', prefix=site, as_bool=True)
             undone_sort_order = params.get_cookied('undone_sort', prefix=site)
             done_sort_order = params.get_cookied('done_sort', prefix=site)
-            page = db.show_day_todos(undone_sort_order, done_sort_order, is_tree_shaped)
+            page = db.show_day_todos(undone_sort_order, done_sort_order, is_tree_shaped, todo_parenthood)
         elif site == 'todo':
-            page = db.show_todo(id_)
+            page = db.show_todo(id_, parenthood=todo_parenthood)
         elif 'task' == site:
             page = db.show_task(id_)
         elif 'tasks' == site:
@@ -1054,9 +1196,9 @@ class TodoHandler(PlomHandler):
             page = db.show_tasks(search, sort_order)
         elif 'add_task' == site:
             page = db.show_task(None)
+        elif 'calendar_export' == site:
+            page = db.show_calendar_export(start_date, end_date)
         else:  # 'calendar' == site
-            start_date = params.get_cookied('start', prefix=site)
-            end_date = params.get_cookied('end', prefix=site)
             page = db.show_calendar(start_date, end_date)
 
         self.set_cookie(config['cookie_name'], config['cookie_path'], cookie_db)
index 343019aa6387b8254a2bd3fce7ef39ec390bfec4..59dd5c57bf58654d9f7f4ce9410fa5b8ee0c518f 100644 (file)
@@ -70,6 +70,10 @@ to: <input name="end" {% if end_date %}value="{{ end_date }}"{% endif %} placeho
 {% endfor %}
 </table>
 
+<p>
+<a href="calendar_export?{% if start_date %}start={{start_date}}&{% endif %}{% if end_date %}end={{end_date}}{% endif %}">exportable</a>
+</p>
+
 </form>
 {% endblock %}
 
diff --git a/todo_templates/calendar_export.html b/todo_templates/calendar_export.html
new file mode 100644 (file)
index 0000000..315b0a0
--- /dev/null
@@ -0,0 +1,31 @@
+{% import 'macros.html' as macros %}
+<html>
+<body>
+<table>
+{% for date, day in days.items() %}
+{% if day.month_title %}
+<tr><td colspan=3>### {{ day.month_title }} ###</td></tr>
+{% endif %}
+{% if day.visible_in_export %}
+<tr><td colspan=3># {{ date }} ({{ day.weekday }}) {{ day.comment|e }}</td></tr>
+{% for todo in day.linked_todos_as_list %}
+{% if todo.visible %}
+<tr>
+<td>
+{% if "cancelled" in todo.tags %}<s>{% endif %}
+{{ macros.doneness_string(todo, true) }}
+{% if "deadline" in todo.tags %}DEADLINE: {% endif %}
+{{ todo.title|e }}
+{%if "cancelled" in todo.tags%}</s>{% endif %}
+</td>
+<td>
+{{ todo.comment|e }}
+</td>
+</tr>
+{% endif %}
+{% endfor %}
+{% endif %}
+{% endfor %}
+</table>
+</body>
+</html>
index 8cf87fbd8c9d00c44d53eda35a89cb521331003e..f2312eefe0a266338dc9d2d6243251795bcb54c6 100644 (file)
@@ -85,7 +85,7 @@ depends on:
 
 {% macro draw_undone_todo_row(todo, title_drawer, indent_or_doneness) %}
 <tr {% if todo.deps_done == false %}class="deps_undone"{% endif %}>
-{% if todo.already_listed %}
+{% if todo.been_observed %}
 <td class="checkbox"><input type="checkbox" disabled /></td>
 <td class="number left"><input type="number" value="{{todo.day_effort}}" size=7 disabled /></td>
 <td class="number"><input type="number" value="{{todo.importance}}" size=7 disabled /></td>
@@ -165,7 +165,7 @@ comment: <input name="day_comment" value="{{day.comment|e}}">
 <h3>undone</h3>
 <p>
 task quick-add: <input name="choose_task" size=50 list="tasks" autocomplete="off">
-don't adopt, make new: <input type="checkbox" name="dont_adopt" />
+{{ macros.parenthood_selector(parenthood) }}
 </p>
 {{ macros.datalist_tasks(all_tasks, with_weight=true) }}
 
@@ -219,6 +219,8 @@ don't adopt, make new: <input type="checkbox" name="dont_adopt" />
 
 {% include 'watch_form.html' %}
 <script>
+inputs_to_ignore += ['parenthood'];
+
 var effort_inputs = document.getElementsByClassName("effort_input");
 for (let i = 0; i < effort_inputs.length; i++) {
     let input = effort_inputs[i];
index 66751ac87543431c672fa8cb64485729cbd56865..6d86b1de72bfbd8b2f3bb4689bac33ca7ac4001a 100644 (file)
 {% endfor %}
 </datalist>
 {% endmacro %}
+
+
+
+{% macro parenthood_selector(parenthood) %}parenthood: <select name="parenthood">
+<option value="childless" {% if parenthood == "childless" %}selected{% endif %}>make childless</option>
+<option value="adoption" {% if parenthood == "adoption" %}selected{% endif %}>favor adoption</option>
+<option value="birth" {% if parenthood == "birth" %}selected{% endif %}>favor birth</option>
+</select>{% endmacro %}
index c26d33a9d8d30d7b4c8efebe938b1aed86bc2b4d..3128d75c6ff1a6cfb7fdca5bfb531d31098fea60 100644 (file)
@@ -35,10 +35,17 @@ tr.lowlevel td, tr.lowlevel th { padding-top: 0em; }
 
 <tr class="toplevel">
 <th>add as todo</th>
-<td><input name="add_as_todo" type="checkbox" /> to {{ selected_date }}</td>
-<input name="selected_date" type="hidden" value="{{ selected_date }}" />
+<td><input name="add_as_todo" type="checkbox" /> to <input name="new_todo_date" value="{{ selected_date }}" />
 </tr>
 
+{% if task.forks_id %}
+<tr class="toplevel">
+<th>forks</th>
+<td><a href="task?id={{task.forks_id}}">{{ task.forked_task.title.now|e }}</td>
+</td>
+</tr>
+{% endif %}
+
 <tr class="toplevel">
 <th>title</th>
 <td class="input">
@@ -91,18 +98,26 @@ add: {{ macros.tagselection(submit_name='tag', selected_tags=task.tags.now, all_
 </td>
 </tr>
 
-{% if task.dependers %}
 <tr class="toplevel">
 <th>dependers</th>
 <td>
-<ul>
-{% for parent in task.dependers %}
-<li><a href="task?id={{parent.id_}}">{{parent.title.now}}</a>
-{% endfor %}
-</ul>
+{% if task.dependers %}
+<table>
+{% for depender in task.dependers %}
+<tr class="lowlevel">
+<td>
+<input name="depender" type="checkbox" value="{{depender.id_}}" checked/>
+</td>
+<td>
+{{ draw_task(depender)}}
 </td>
 </tr>
+{% endfor %}
+</table>
 {% endif %}
+add: <input name="depender" list="tasks" autocomplete="off" />
+</td>
+</tr>
 
 <tr class="toplevel">
 <th>children</th>
@@ -156,6 +171,7 @@ add: <input name="dep" list="tasks" autocomplete="off" />
 </table>
 <input id="update_button" class="update" type="submit" name="update" value="update" />
 <div class="delete">
+<input class="update" type="submit" name="fork" value="fork" />
 <input class="delete" type="submit" name="delete" value="delete" />
 </div>
 </form>
index cd5ef0ff7c7a69247ae415b3d9cf24bdfe64af81..80f5a603efbd123a7d13e0954569bb61f0bbcbb5 100644 (file)
@@ -1,13 +1,6 @@
 {% extends 'base.html' %}
 
-{% block css %}
-table.alternating tr:nth-child(even) {
-    background-color: #cccccc;
-}
-table.alternating tr:nth-child(odd) {
-    background-color: #ffffff;
-}
-{% endblock %}
+
 
 {% block content %}
 <h3>review tasks</h3>
@@ -24,6 +17,7 @@ match: <input name="search" value="{{search|e}}" />
 {{ macros.sort_head(sort, "default_effort", "effort") }}
 {{ macros.sort_head(sort, "weight", "weight") }}
 {{ macros.sort_head(sort, "title", "task") }}
+{{ macros.sort_head(sort, "latest_effort_date", "last todo") }}
 <th>tags</th>
 </tr>
 {% for t in tasks %}
@@ -33,10 +27,11 @@ match: <input name="search" value="{{search|e}}" />
 {{ '{:5.1f}'.format(t.default_effort.now) }}
 </td>
 <td class="number">
-{{ '{:5.1f}'.format(t.subtask_weight) }}
+{{ '{:5.1f}'.format(t.deps_weight) }}
 </td>
 <td>
 <a href="task?id={{ t.id_ }}" />{{ t.title.now|e }}</a></td>
+<td>{{ t.latest_effort_date }}</td>
 <td>{% for tag in t.tags.now | sort %}<a href="tasks?and_tag={{tag|e}}">{{ tag }}</a> {% endfor %}</td>
 </tr>
 {% endif %}
index 5aaf8a0bd71165ef5b36aeeb50cbe728f44d2f0b..e62a09b8c02547bcfb48dabf7f1b5b73f72163f9 100644 (file)
@@ -223,7 +223,7 @@ new: {{ macros.tagselection(submit_name='tag', selected_tags=todo.day_tags, all_
 <tr class="toplevel">
 <th>free add</th>
 <td colspan=2>
-make from task:<br />
+make from task ({{ macros.parenthood_selector(parenthood) }}):<br />
 <input name="birth_dep" list="tasks" size=100 autocomplete="off"><br />
 adopt:<br />
 <input name="adopt_dep" list="todos" size=100 autocomplete="off">
index 75b5223c7c8299e5abb410c7846fba4786bc5e64..c7f396d6356a7dc7c811518a1bfc9a18ca7b3dc7 100644 (file)
@@ -1,5 +1,5 @@
 <script>
-var mere_filter_inputs = ['and_tag', 'not_tag', 'filter'];
+var inputs_to_ignore = ['and_tag', 'not_tag', 'filter'];
 var update_button_names = ['update'];
 var sending_commits = false;
 var changes_to_commit = false;
@@ -8,7 +8,7 @@ for (let i = 0; i < form_to_watch.elements.length; i++) {
     let el = form_to_watch.elements[i];
     if (['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName)) {
         el.addEventListener('change', function(event) {
-            if (!mere_filter_inputs.includes(event.target.name)) { 
+            if (!inputs_to_ignore.includes(event.target.name)) { 
               changes_to_commit = true; 
            };
        });
@@ -20,7 +20,7 @@ form_to_watch.addEventListener('keydown', function(event) {
            && ['INPUT', 'SELECT'].includes(el.tagName)
            && (el.tagName !== 'INPUT' || el.type !== 'submit')) {
         event.preventDefault();
-       if (mere_filter_inputs.includes(el.name)) {
+       if (inputs_to_ignore.includes(el.name)) {
             document.getElementById('filter_button').click(); 
        } else {
             document.getElementById('update_button').click();