+ db = TodoDB(prefix=app_config['prefix'])
+ params_to_encode = []
+ if 't_and' in postvars.keys():
+ for target in postvars['t_and']:
+ if len(target) > 0 and not target in db.t_filter_and:
+ db.t_filter_and += [target]
+ if len(db.t_filter_and) == 0:
+ params_to_encode += [('t_and', '-')]
+ if 't_not' in postvars.keys():
+ for target in postvars['t_not']:
+ if len(target) > 0 and not target in db.t_filter_not:
+ db.t_filter_not += [target]
+ if len(db.t_filter_not) == 0:
+ params_to_encode += [('t_not', '-')]
+ params_to_encode += [('t_and', f) for f in db.t_filter_and] + [('t_not', f) for f in db.t_filter_not]
+
+ 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':
+ start = postvars['start'][0] if len(postvars['start'][0]) > 0 else '-'
+ end = postvars['end'][0] if len(postvars['end'][0]) > 0 else '-'
+ homepage = f'{app_config["prefix"]}/calendar?start={start}&end={end}'
+
+ elif parsed_url.path == app_config['prefix'] + '/todo':
+ task_uuid = postvars['task_uuid'][0]
+ date = postvars['date'][0]
+ db.update_todo(task_uuid, date, postvars['day_weight'][0], 'done' in postvars.keys(), postvars['comment'][0], postvars['joined_day_tags'][0], collect_checked('day_tag_', postvars))
+ homepage = f'{app_config["prefix"]}/todo?task={task_uuid}&date={date}'
+
+ elif parsed_url.path == app_config['prefix'] + '/task':
+ encoded_params = urlencode(params_to_encode)
+ id_ = postvars['id'][0]
+ if 'title' in postvars.keys():
+ db.update_task(id_, postvars['title'][0], postvars['default_weight'][0], postvars['joined_tags'][0], collect_checked('tag_', postvars), collect_checked('link_', postvars))
+ homepage = f'{app_config["prefix"]}/task?id={id_}&{encoded_params}'
+
+ elif parsed_url.path == app_config['prefix'] + '/tasks':
+ encoded_params = urlencode(params_to_encode)
+ homepage = f'{app_config["prefix"]}/tasks?{encoded_params}'
+
+ elif parsed_url.path == app_config['prefix'] + '/day':
+ 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 't_uuid' in postvars.keys():
+ for i, uuid in enumerate(postvars['t_uuid']):
+ t = db.tasks[uuid]
+ if uuid in db.selected_day.todos.keys() and ((not 'choose' in postvars) or uuid not in postvars['choose']):
+ del db.selected_day.todos[uuid]
+ if 'choose' in postvars.keys():
+ for i, uuid in enumerate(postvars['t_uuid']):
+ if uuid in postvars['choose']:
+ done = 'done' in postvars and uuid in postvars['done']
+ db.update_todo_mini(uuid, db.selected_date, postvars['day_weight'][i], done)
+ if 'day_comment' in postvars.keys():
+ db.selected_day.comment = postvars['day_comment'][0]
+ params_to_encode += [('selected_date', db.selected_date)]
+ encoded_params = urlencode(params_to_encode)
+ homepage = f'{app_config["prefix"]}/day?{encoded_params}'
+
+ db.write()