Skip to content

Commit c391e43

Browse files
committed
Derive (beam)line from base element
1 parent d90c318 commit c391e43

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

schema/Line.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from schema.QuadrupoleElement import QuadrupoleElement
88

99

10-
class Line(BaseModel):
10+
class Line(BaseElement):
1111
"""A line of elements and/or other lines"""
1212

1313
# Validate every time a new value is assigned to an attribute,
@@ -67,17 +67,17 @@ def parse_list_of_dicts(cls, value):
6767

6868
def model_dump(self, *args, **kwargs):
6969
"""This makes sure the element name property is moved out and up to a one-key dictionary"""
70-
# Use default dump for non-line fields
70+
# Use base element dump first and return a one-element list of the form
71+
# [{key: value}], where 'key' is the name of the line and 'value' is a
72+
# dictionary with all other properties
7173
data = super().model_dump(*args, **kwargs)
72-
7374
# Reformat 'line' field as list of single-key dicts
7475
new_line = []
7576
for elem in self.line:
7677
# Use custom dump for each line element
7778
elem_dict = elem.model_dump(**kwargs)[0]
7879
new_line.append(elem_dict)
79-
80-
data["line"] = new_line
80+
data[0][self.name]["line"] = new_line
8181
return data
8282

8383

0 commit comments

Comments
 (0)