diff --git a/mdrsclient/api/laboratory.py b/mdrsclient/api/laboratory.py index 8bc28ed..4a5e2bf 100644 --- a/mdrsclient/api/laboratory.py +++ b/mdrsclient/api/laboratory.py @@ -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 diff --git a/mdrsclient/commands/labs.py b/mdrsclient/commands/labs.py index f2b65e7..87a0b9d 100644 --- a/mdrsclient/commands/labs.py +++ b/mdrsclient/commands/labs.py @@ -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']}}" ) diff --git a/mdrsclient/models/laboratory.py b/mdrsclient/models/laboratory.py index 8f098f9..af449dc 100644 --- a/mdrsclient/models/laboratory.py +++ b/mdrsclient/models/laboratory.py @@ -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)