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:
return current_assembly
def to_dict(self) -> Dict:
ATTRIBUTES = [
"uuid",
"name",
"category",
"lego_id",
"cost",
"mass",
"delivery_time",
"layer",
"properties",
]
dict_ = {}
# store attributes
for attr in ATTRIBUTES:
dict_[attr] = getattr(self, attr)
dict_ = {"component": dict_}
return dict_
dict_ = {
"uuid": self.uuid,
"label": self.label,
"properties": self.properties,
"layer": self.layer,
}
return {"component": dict_}
# TODO good string representation
def __str__(self):
......@@ -169,15 +158,15 @@ class LegoAssembly:
return False
def to_dict(self) -> Dict:
ATTRIBUTES = ["uuid", "name", "layer", "properties"]
dict_ = {}
# store attributes
for attr in ATTRIBUTES:
dict_[attr] = getattr(self, attr)
dict_ = {
"uuid": self.uuid,
"label": self.label,
"properties": self.properties,
"layer": self.layer,
}
# store components
dict_["components"] = [component.to_dict() for component in self.components]
dict_["assemblies"] = [assembly.to_dict() for assembly in self.assemblies]
return {"assembly": dict_}
# 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