Adding and removing headers defined on parentless task level now processes all children correctly.

pull/30/head
Hoffelhas 2023-01-13 16:35:00 +01:00
parent bf6ce05ad8
commit 707482cf17
1 changed files with 40 additions and 11 deletions

View File

@ -621,9 +621,11 @@ def check_header(api, model):
if ra: if ra:
header_all_in_level = True header_all_in_level = True
model.content = ra[2] # Local record
api.update_task(task_id=model.id, content=ra[2]) api.update_task(task_id=model.id, content=ra[2])
if rb: if rb:
unheader_all_in_level = True unheader_all_in_level = True
model.content = rb[2] # Local record
api.update_task(task_id=model.id, content=rb[2]) api.update_task(task_id=model.id, content=rb[2])
else: else:
ra = re.search(regex_a, model.name) ra = re.search(regex_a, model.name)
@ -652,21 +654,27 @@ def check_header(api, model):
# Logic for applying and removing headers # Logic for applying and removing headers
def modify_headers(api, task, child_tasks, header_all_in_p, unheader_all_in_p, header_all_in_s, unheader_all_in_s, header_all_in_t, unheader_all_in_t): def modify_task_headers(api, task, section_tasks, header_all_in_p, unheader_all_in_p, header_all_in_s, unheader_all_in_s, header_all_in_t, unheader_all_in_t):
if any([header_all_in_p, header_all_in_s, header_all_in_t]):
if task.content[0] != '*': if any([header_all_in_p, header_all_in_s]):
if task.content[:2] != '* ':
api.update_task(task_id=task.id, content='* ' + task.content) api.update_task(task_id=task.id, content='* ' + task.content)
for ci in child_tasks:
if not ci.content.startswith('*'):
api.update_task(task_id=ci.id, content='* ' + ci.content)
if any([unheader_all_in_p, unheader_all_in_s]): if any([unheader_all_in_p, unheader_all_in_s]):
if task.content[0] == '*': if task.content[:2] == '* ':
api.update_task(task_id=task.id, content=task.content[2:]) api.update_task(task_id=task.id, content=task.content[2:])
if header_all_in_t:
if task.content[:2] != '* ':
api.update_task(task_id=task.id, content='* ' + task.content)
find_and_headerify_all_children(api, task, section_tasks, 1)
if unheader_all_in_t: if unheader_all_in_t:
[api.update_task(task_id=ci.id, content=ci.content[2:]) for ci in child_tasks] if task.content[:2] == '* ':
api.update_task(task_id=task.id, content=task.content[2:])
find_and_headerify_all_children(api, task, section_tasks, 2)
# Check regen mode based on label name # Check regen mode based on label name
@ -829,6 +837,27 @@ def find_and_clean_all_children(task_ids, task, section_tasks):
return task_ids return task_ids
def find_and_headerify_all_children(api, task, section_tasks, mode):
child_tasks = list(filter(lambda x: x.parent_id == task.id, section_tasks))
if child_tasks != []:
for child_task in child_tasks:
# Children found, go deeper
if mode == 1:
if child_task.content[:2] != '* ':
api.update_task(task_id=child_task.id, content='* ' + child_task.content)
elif mode == 2:
if child_task.content[:2] == '* ':
api.update_task(task_id=child_task.id, content=child_task.content[2:])
find_and_headerify_all_children(api, child_task, section_tasks, mode)
return 0
# Contains all main autodoist functionalities # Contains all main autodoist functionalities
@ -970,7 +999,7 @@ def autodoist_magic(args, api, connection):
header_all_in_t, unheader_all_in_t = check_header(api, task) header_all_in_t, unheader_all_in_t = check_header(api, task)
# Modify headers where needed # Modify headers where needed
modify_headers(api, task, child_tasks, header_all_in_p, unheader_all_in_p, header_all_in_s, unheader_all_in_s, header_all_in_t, unheader_all_in_t) modify_task_headers(api, task, section_tasks, header_all_in_p, unheader_all_in_p, header_all_in_s, unheader_all_in_s, header_all_in_t, unheader_all_in_t)
# TODO: Check is regeneration is still needed, now that it's part of core Todoist. Disabled for now. # TODO: Check is regeneration is still needed, now that it's part of core Todoist. Disabled for now.
# Logic for recurring lists # Logic for recurring lists