From ec309dce437d6ca39462cc9d9fd32adde490c93c Mon Sep 17 00:00:00 2001 From: Cristiano Singulani Date: Wed, 11 Dec 2024 15:10:15 +0000 Subject: [PATCH] Added column sorting --- src/pzserver/communicate.py | 10 ++++++++-- src/pzserver/core.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pzserver/communicate.py b/src/pzserver/communicate.py index 9e1e37c..2f62efa 100644 --- a/src/pzserver/communicate.py +++ b/src/pzserver/communicate.py @@ -491,18 +491,24 @@ def get_entities(self) -> list: return list(resp.keys()) - def get_all(self, entity) -> list: + def get_all(self, entity, ordering=None) -> list: """ Returns a list with all records of the entity. Args: entity (str): entity name e.g. "releases", "products", "product-types" + ordering (None or str): column name to be ordered Returns: list: list of records """ - resp = self._get_request(f"{self._base_api_url}{entity}/") + uri = f"{self._base_api_url}{entity}/" + + if ordering: + uri += f"?ordering={ordering}" + + resp = self._get_request(uri) if "success" in resp and resp["success"] is False: raise requests.exceptions.RequestException(resp["message"]) diff --git a/src/pzserver/core.py b/src/pzserver/core.py index 3c4d3b8..fcb3e64 100644 --- a/src/pzserver/core.py +++ b/src/pzserver/core.py @@ -59,7 +59,7 @@ def get_product_types(self) -> list: Returns: product types list """ - return self.api.get_all("product-types") + return self.api.get_all("product-types", ordering="order") def display_product_types(self): """