sort laboratory list by name and hide numeric id.
This commit is contained in:
parent
593caa82ec
commit
1ffafd25ba
@ -19,4 +19,5 @@ class LaboratoryApi(BaseApi):
|
||||
ret = Laboratories()
|
||||
for data in response.json():
|
||||
ret.append(parse_obj_as(Laboratory, data))
|
||||
ret.sort()
|
||||
return ret
|
||||
|
@ -28,13 +28,15 @@ class LabsCommand(BaseCommand):
|
||||
length["pi_name"] = max(length["pi_name"], len(laboratory.pi_name))
|
||||
length["full_name"] = max(length["full_name"], len(laboratory.full_name))
|
||||
header = (
|
||||
f"{label['id']:{length['id']}}\t{label['name']:{length['name']}}\t"
|
||||
# f"{label['id']:{length['id']}}\t{label['name']:{length['name']}}\t"
|
||||
f"{label['name']:{length['name']}}\t"
|
||||
f"{label['pi_name']:{length['pi_name']}}\t{label['full_name']:{length['full_name']}}"
|
||||
)
|
||||
print(header)
|
||||
print("-" * len(header.expandtabs()))
|
||||
for laboratory in laboratories:
|
||||
print(
|
||||
f"{laboratory.id:{length['id']}}\t{laboratory.name:{length['name']}}\t"
|
||||
# f"{laboratory.id:{length['id']}}\t{laboratory.name:{length['name']}}\t"
|
||||
f"{laboratory.name:{length['name']}}\t"
|
||||
f"{laboratory.pi_name:{length['pi_name']}}\t{laboratory.full_name:{length['full_name']}}"
|
||||
)
|
||||
|
@ -28,6 +28,9 @@ class Laboratories:
|
||||
def append(self, item: Laboratory) -> None:
|
||||
self.items.append(item)
|
||||
|
||||
def sort(self) -> None:
|
||||
self.items.sort(key=lambda x: x.name)
|
||||
|
||||
def find_by_id(self, id: int) -> Laboratory | None:
|
||||
return next((x for x in self.items if x.id == id), None)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user