Skip to content

Commit

Permalink
build the URL right in the beginning of internal view functions
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
nhoening committed Mar 13, 2024
1 parent 2fbe73b commit 52d0f76
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions flexmeasures/ui/crud/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def get(
query: dict[str, Any] | None = None,
do_not_raise_for: list | None = None,
) -> requests.Response:
url_root = self._url_root()
full_url = f"{self._url_root()}{url}"
current_app.logger.debug(
f"{self._log_prefix} Calling GET to {url_root}{url} with query {query} ..."
f"{self._log_prefix} Calling GET to {full_url} with query {query} ..."
)
response = requests.get(
f"{url_root}{url}",
full_url,
params=query,
headers=self._auth_headers(),
)
Expand All @@ -75,12 +75,12 @@ def post(
args: dict | None = None,
do_not_raise_for: list | None = None,
) -> requests.Response:
url_root = self._url_root()
full_url = f"{self._url_root()}{url}"
current_app.logger.debug(
f"{self._log_prefix} Call POST to {url_root}{url} with json data {args} ..."
f"{self._log_prefix} Call POST to {full_url} with json data {args} ..."
)
response = requests.post(
f"{url_root}{url}",
full_url,
headers=self._auth_headers(),
json=args if args else {},
)
Expand All @@ -93,12 +93,12 @@ def patch(
args: dict | None = None,
do_not_raise_for: list | None = None,
) -> requests.Response:
url_root = self._url_root()
full_url = f"{self._url_root()}{url}"
current_app.logger.debug(
f"{self._log_prefix} Calling PATCH to {url_root}{url} with json data {args} ..."
f"{self._log_prefix} Calling PATCH to {full_url} with json data {args} ..."
)
response = requests.patch(
f"{url_root}{url}",
full_url,
headers=self._auth_headers(),
json=args if args else {},
)
Expand All @@ -110,12 +110,10 @@ def delete(
url: str,
do_not_raise_for: list | None = None,
) -> requests.Response:
url_root = self._url_root()
current_app.logger.debug(
f"{self._log_prefix} Calling DELETE to {url_root}{url} ..."
)
full_url = f"{self._url_root()}{url}"
current_app.logger.debug(f"{self._log_prefix} Calling DELETE to {full_url} ...")
response = requests.delete(
f"{url_root}{url}",
full_url,
headers=self._auth_headers(),
)
self._maybe_raise(response, do_not_raise_for)
Expand Down

0 comments on commit 52d0f76

Please sign in to comment.