Change str function to use json string dump.
This commit is contained in:
+3
-8
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user