Change str function to use json string dump.

This commit is contained in:
alwayscompiling
2022-07-31 10:19:23 -04:00
parent 0fc0fc33da
commit 6ddba14908
+3 -8
View File
@@ -1,6 +1,7 @@
"""File for Category class."""
from typing import Optional
import json
from data.score import Score, ScoreTime # pylint: disable=import-error
@@ -21,14 +22,7 @@ class Category:
def __str__(self) -> str:
"""Creates a string from the class."""
ret_str = f"{self.name}\n"
ret_str += f"ascending: {self.ascending}\n"
ret_str += f"time_record: {self.time_record}"
for score in self.scores:
ret_str += f"{score}\n"
return ret_str
return json.dumps(self.to_dict(), indent=4)
@property
def ascending(self) -> bool:
@@ -87,6 +81,7 @@ class Category:
data = {}
data["ascending"] = self.ascending
data["time_record"] = self.time_record
data["scores"] = {}
for score in self.scores:
data["scores"][score.user] = score.score