-
- import pprint
- pp = pprint.PrettyPrinter(indent=4)
- pp.pprint(postvars)
-
- db.t_filter_and = set()
- db.t_filter_not = set()
- if 't_filter_and' in postvars.keys():
- for target in postvars['t_filter_and']:
- db.t_filter_and.add(target)
- if 't_filter_not' in postvars.keys():
- for target in postvars['t_filter_not']:
- db.t_filter_not.add(target)
- if 't_uuid' in postvars.keys():
- new_postvars_t_uuid = postvars['t_uuid'].copy()
- for i, uuid in enumerate(postvars['t_uuid']):
- if len(uuid) < 36 and len(postvars['t_title'][i]) > 0:
- t = Task()
- new_uuid = str(uuid4())
- db.tasks[new_uuid] = t
- new_postvars_t_uuid[i] = new_uuid
- for key in [k for k in postvars.keys() if not k == 't_uuid']:
- if uuid in postvars[key]:
- uuid_index = postvars[key].index(uuid)
- postvars[key][uuid_index] = new_uuid
- postvars['t_uuid'] = new_postvars_t_uuid
- for i, uuid in enumerate(postvars['t_uuid']):
- if len(uuid) < 36:
- continue
- t = db.tasks[uuid]
- t.set_title(postvars['t_title'][i])
- t.tags_from_joined_string(postvars['t_tags'][i])
- t.set_default_weight(float(postvars['t_default_weight'][i]))
- if uuid in db.today.todos.keys() and ((not 'do_today' in postvars) or uuid not in postvars['do_today']):
- del db.today.todos[uuid]
- if 'do_today' in postvars.keys():
- for i, uuid in enumerate(postvars['t_uuid']):
- if uuid in postvars['do_today']:
- done = 'done' in postvars and uuid in postvars['done']
- 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
- for date in db.old_days.keys():
- if f'edit_{date}' in postvars.keys():
- switch_edited_day = date
- break
- if 'archive_today' in postvars.keys() or switch_edited_day:
- db.save_today()
- if switch_edited_day:
- db.reset_today(date)
- else:
- db.reset_today()
+ parsed_url = urlparse(self.path)
+ db = TodoDB(prefix=app_config['prefix'])
+ params_to_encode = []
+ for param_name, filter_db_name in {('t_and', 't_filter_and'), ('t_not', 't_filter_not')}:
+ filter_db = getattr(db, filter_db_name)
+ if param_name in postvars.keys():
+ for target in postvars[param_name]:
+ if len(target) > 0 and not target in filter_db:
+ filter_db += [target]
+ if len(filter_db) == 0:
+ params_to_encode += [(param_name, '-')]
+ params_to_encode += [(param_name, f) for f in filter_db]
+
+ def collect_checked(prefix, postvars):
+ tags_checked = []
+ for k in postvars.keys():
+ if k.startswith(prefix):
+ tags_checked += [k[len(prefix):]]
+ return tags_checked
+
+ if parsed_url.path == app_config['prefix'] + '/calendar':
+ params_to_encode += [('start', postvars['start'][0] if len(postvars['start'][0]) > 0 else '-')]
+ params_to_encode += [('end', postvars['end'][0] if len(postvars['end'][0]) > 0 else '-')]
+
+ elif parsed_url.path == app_config['prefix'] + '/todo':
+ task_uuid = postvars['task_uuid'][0]
+ date = postvars['date'][0]
+ params_to_encode += [('task', task_uuid), ('date', date)]
+ db.update_todo(task_uuid, date, postvars['day_effort'][0], 'done' in postvars.keys(), postvars['comment'][0], postvars['joined_day_tags'][0], collect_checked('day_tag_', postvars), postvars['importance'][0])
+
+ elif parsed_url.path == app_config['prefix'] + '/task':
+ id_ = postvars['id'][0]
+ params_to_encode += [('id', id_)]
+ if 'title' in postvars.keys():
+ db.update_task(id_, postvars['title'][0], postvars['default_effort'][0], postvars['joined_tags'][0], collect_checked('tag_', postvars), collect_checked('link_', postvars))
+
+ elif parsed_url.path == app_config['prefix'] + '/day':
+ # always store the two hide params in the URL if possible … TODO: find out if really necessary
+ if 'expect_unchosen_done' in postvars.keys():
+ params_to_encode += [('hide_unchosen', int('hide_unchosen' in postvars.keys()))] + [('hide_done', int('hide_done' in postvars.keys()))]
+
+ if 'selected_date' in postvars.keys():
+ db.selected_date = postvars['selected_date'][0]
+ if 'day_comment' in postvars.keys():
+ db.selected_day.comment = postvars['day_comment'][0]
+ params_to_encode += [('selected_date', db.selected_date)]
+
+ # handle todo list updates via task UUIDs
+ if 't_uuid' in postvars.keys():
+ for i, uuid in enumerate(postvars['t_uuid']):
+ task = db.tasks[uuid]
+ old_todo = None if not uuid in db.selected_day.todos.keys() else db.selected_day.todos[uuid]
+ selects_as_todo = 'choose' in postvars and uuid in postvars['choose']
+ too_much_keepworthy_data = ('done' in postvars and uuid in postvars['done']) or postvars['day_effort'][i] != '' or (old_todo and not old_todo.internals_empty())
+ if old_todo and too_much_keepworthy_data and not selects_as_todo:
+ raise PlomException('cannot deselect task as todo of preserve-worthy values')
+ elif old_todo and not selects_as_todo:
+ del db.selected_day.todos[uuid]
+ else:
+ done = ('done' in postvars) and (uuid in postvars['done'])
+ day_effort_input = postvars['day_effort'][i]
+ day_effort = float(day_effort_input) if len(day_effort_input) > 0 else None
+ importance = float(postvars['importance'][i])
+ if old_todo and old_todo.done == done and old_todo.day_effort == day_effort and old_todo.importance == importance:
+ continue
+ db.update_todo_mini(uuid, db.selected_date, day_effort, done, importance)
+
+ if 'referer' in postvars.keys() and len(postvars['referer'][0]) > 0:
+ homepage = postvars['referer'][0]
+ else:
+ encoded_params = urlencode(params_to_encode)
+ homepage = f'{parsed_url.path}?{encoded_params}'