Skip to content

Commit

Permalink
[Fixes #70] Bug: creating a map via the GeoNode API leads to a map wh…
Browse files Browse the repository at this point in the history
…ich is not visable on the web UI
  • Loading branch information
mwallschlaeger committed Nov 1, 2024
1 parent e7f8d42 commit eb374dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions geonoderest/apiconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ def from_env_vars() -> "GeonodeApiConf":
auth_basic = os.getenv("GEONODE_API_BASIC_AUTH", "")
verify = True if "True" == os.getenv("GEONODE_API_VERIFY", "True") else False
return GeonodeApiConf(url=url, auth_basic=auth_basic, verify=verify)

def get_geonode_base_url(self) -> str:
if self.url.endswith("/api/v2/"):
return self.url[:-8]
18 changes: 18 additions & 0 deletions geonoderest/maps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pathlib import Path
import json
import logging
from typing import List, Dict, Optional

from geonoderest.cmdprint import print_json, json_decode_error_handler
from geonoderest.datasets import GeonodeDatasetsHandler
from geonoderest.resources import GeonodeResourceHandler
from geonoderest.geonodetypes import (
GeonodeCmdOutListKey,
Expand Down Expand Up @@ -81,9 +83,25 @@ def create(
maplayers_list = []
if maplayers is not None:
maplayers_list = [{"pk": pk} for pk in maplayers]

# download map template from mapstore config statics of remote geonode instance
geonode_base_url = self.gn_credentials.get_geonode_base_url()
blob = self.http_get_download(
f"{geonode_base_url}/static/mapstore/configs/map.json"
)

# add maplayers to map.blob
gnResourceHandler = GeonodeResourceHandler(self.gn_credentials)
for maplayer_pk in maplayers:
try:
blob["map"]["layers"].append(gnResourceHandler.get(pk=maplayer_pk))
except Exception as err:
logging.error(f"dataset {maplayer_pk} not found ...")

base_json_content = {
"ressource_type": self.SINGULAR_RESOURCE_NAME,
"title": title,
"blob": blob,
"maplayers": maplayers_list,
}

Expand Down

0 comments on commit eb374dc

Please sign in to comment.