🐛 fix(base.py): sort fields alphabetically before sorting by DIRECT_TYPES
The fields in the Template class were previously sorted by DIRECT_TYPES, which caused issues when fields had the same field_type. Sorting alphabetically first ensures that fields are sorted in a consistent manner before sorting by DIRECT_TYPES.
This commit is contained in:
parent
d9fa17189e
commit
02c6d77b64
1 changed files with 4 additions and 6 deletions
|
|
@ -20,12 +20,10 @@ class Template(BaseModel):
|
|||
format_field_func(field, name)
|
||||
|
||||
def sort_fields(self):
|
||||
# sort fields so that fields that have .field_type in DIRECT_TYPES are first
|
||||
self.fields.sort(
|
||||
key=lambda x: DIRECT_TYPES.index(x.field_type)
|
||||
if x.field_type in DIRECT_TYPES
|
||||
else 100
|
||||
)
|
||||
# first sort alphabetically
|
||||
# then sort fields so that fields that have .field_type in DIRECT_TYPES are first
|
||||
self.fields.sort(key=lambda x: x.name)
|
||||
self.fields.sort(key=lambda x: x.field_type in DIRECT_TYPES, reverse=False)
|
||||
|
||||
def to_dict(self, format_field_func=None):
|
||||
self.process_fields(self.type_name, format_field_func)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue