Skip to content
Snippets Groups Projects
Commit 53280622 authored by Hock, Benedikt's avatar Hock, Benedikt
Browse files

fix to_dict()

parent 27b06a89
No related branches found
No related tags found
No related merge requests found
...@@ -65,24 +65,13 @@ class LegoComponent: ...@@ -65,24 +65,13 @@ class LegoComponent:
return current_assembly return current_assembly
def to_dict(self) -> Dict: def to_dict(self) -> Dict:
ATTRIBUTES = [ dict_ = {
"uuid", "uuid": self.uuid,
"name", "label": self.label,
"category", "properties": self.properties,
"lego_id", "layer": self.layer,
"cost", }
"mass", return {"component": dict_}
"delivery_time",
"layer",
"properties",
]
dict_ = {}
# store attributes
for attr in ATTRIBUTES:
dict_[attr] = getattr(self, attr)
dict_ = {"component": dict_}
return dict_
# TODO good string representation # TODO good string representation
def __str__(self): def __str__(self):
...@@ -169,15 +158,15 @@ class LegoAssembly: ...@@ -169,15 +158,15 @@ class LegoAssembly:
return False return False
def to_dict(self) -> Dict: def to_dict(self) -> Dict:
ATTRIBUTES = ["uuid", "name", "layer", "properties"] dict_ = {
dict_ = {} "uuid": self.uuid,
# store attributes "label": self.label,
for attr in ATTRIBUTES: "properties": self.properties,
dict_[attr] = getattr(self, attr) "layer": self.layer,
}
# store components # store components
dict_["components"] = [component.to_dict() for component in self.components] dict_["components"] = [component.to_dict() for component in self.components]
dict_["assemblies"] = [assembly.to_dict() for assembly in self.assemblies] dict_["assemblies"] = [assembly.to_dict() for assembly in self.assemblies]
return {"assembly": dict_} return {"assembly": dict_}
# TODO find good string representation # TODO find good string representation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment