Skip to content

Commit

Permalink
refactors api
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarfil committed Dec 24, 2024
1 parent a6edd81 commit 2746799
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions openhexa/toolbox/dhis2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ def __init__(self, connection: DHIS2Connection = None, cache_dir: Optional[Union
self.session.mount("https://", adapter)
self.session.mount("http://", adapter)

if connection is None and ("url" not in kwargs and "username" not in kwargs and "password" not in kwargs):
if connection is None and ("url" not in kwargs or "username" not in kwargs or "password" not in kwargs):
raise DHIS2Error("Connection or url, username and password must be provided")

self.url = self.parse_api_url(kwargs.get("url", connection.url))
self.session = self.authenticate(
kwargs.get("username", connection.username), kwargs.get("password", connection.password)
)
if connection:
self.url = self.parse_api_url(connection.url)
self.session = self.authenticate(connection.username, connection.password)
else:
self.url = self.parse_api_url(kwargs["url"])
self.session = self.authenticate(kwargs["username"], kwargs["password"])

self.cache = None
if cache_dir:
Expand Down
2 changes: 1 addition & 1 deletion openhexa/toolbox/dhis2/dhis2.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def datasets(self, fields: str = "id,name,dataSetElements,indicators,organisatio
"pageSize": 10,
},
):
fields_list = fields.split(",")
for ds in page["dataSets"]:
fields_list = fields.split(",")
row = {}
if "data_elements" in fields_list:
row["data_elements"] = [dx["dataElement"]["id"] for dx in ds["dataSetElements"]]
Expand Down

0 comments on commit 2746799

Please sign in to comment.