Create update_username functions for category and table.
This commit is contained in:
@@ -188,3 +188,27 @@ class Category:
|
||||
str: string of json representation of Category
|
||||
"""
|
||||
return json.dumps(self.to_dict(), indent=4)
|
||||
|
||||
def update_username(self, old_username: str, new_username: str) -> bool:
|
||||
"""
|
||||
Checks score map for old username. Pops old username to remove from map.
|
||||
Updates score's username and calls self.add_score with new score to add back
|
||||
to map and sort.
|
||||
|
||||
Args:
|
||||
old_username (str): Username to replace
|
||||
new_username (str): Username to replace with
|
||||
|
||||
Returns:
|
||||
bool: True indicating a score was updated, False otherwise
|
||||
"""
|
||||
|
||||
ret_val: bool = False
|
||||
|
||||
if old_username in self._scores_map:
|
||||
ret_val = True
|
||||
score: Score = self._scores_map.pop(old_username)
|
||||
score.user = new_username
|
||||
self.add_score(score)
|
||||
|
||||
return ret_val
|
||||
|
||||
Reference in New Issue
Block a user