Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion task_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ def add_task_account(username, is_official, lms_enabled):


def get_taskCurrent(username):
task_current = get_user(username).current_task()
if not task_current:
__unset_current_task_after_task_move(username)
return None
return get_user(username).current_task()


Expand All @@ -234,9 +238,28 @@ def get_taskCurrent(username):


def get_taskCurrent_tier(username, tier):
task_current = get_user(username).current_task_for_tier(tier)
if not task_current:
__unset_current_task_after_task_move(username)
return None
return get_user(username).current_task_for_tier(tier)


def __unset_current_task_after_task_move(username: str):
task_coll = mydb["taskLists"]
user_current_task = task_coll.find_one({"username": username}, {"_id": 0, "tiers": 1})
included_tiers = {"easy", "medium", "hard", "elite", "master"}
for possible_tier in included_tiers:
current_task_info = user_current_task.get("tiers", {}).get(possible_tier, {}).get("currentTask")
if current_task_info:
removed_task_id = current_task_info.get("id")
confirm_before_unset = tasklists.list_for_tier(possible_tier)
if not any(task.id == removed_task_id for task in confirm_before_unset):
print(f"Task with ID {removed_task_id} not found in tier {possible_tier}. Unsetting current task.")
task_coll.update_one(
{"username": username},
{"$unset": {f"tiers.{possible_tier}.currentTask": ""}},
)

def __set_current_task(username: str, tier: str, task_id: str, current: bool):
task_coll = mydb["taskLists"]
cleaned_tier = tier.replace("Tasks", "")
Expand Down
5 changes: 4 additions & 1 deletion user_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def current_task_for_tier(self, tier: str) -> tuple | None:
if user_task_list.current_task is None:
return None
task = task_info_for_id(tasklists.list_for_tier(tier), user_task_list.current_task.id)
if not task:
return None
# TODO Fix this format
return task.name, task.image_link, tier, task.id, task.tip, task.wiki_link, task.image_link

Expand Down Expand Up @@ -216,10 +218,11 @@ def status_sort_key(task: PageTask, has_current_for_name: bool) -> int:
def task_info_for_id(task_list: list[TaskData], task_id: str) -> tasklists.TaskData:
filtered = list(filter(lambda x: x.id == task_id, task_list))
if len(filtered) == 0:
raise Exception("No id found in list " + task_id)
return None
return filtered[0]



'''
convert_database_user

Expand Down