Skip to content

Commit

Permalink
Backport fixes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Jul 27, 2018
1 parent 6a16176 commit 19f80f9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
20 changes: 15 additions & 5 deletions geonode/maps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,33 @@ def update_from_viewer(self, conf, context=None):
"""

template_name = hookset.update_from_viewer(conf, context=context)

conf = context['config']

self.title = conf['about']['title']
self.abstract = conf['about']['abstract']

center = conf['map']['center'] if 'center' in conf['map'] else settings.DEFAULT_MAP_CENTER
zoom = conf['map']['zoom'] if 'zoom' in conf['map'] else settings.DEFAULT_MAP_ZOOM
center_x = center['x'] if isinstance(center, dict) else center[0]
center_y = center['y'] if isinstance(center, dict) else center[1]
self.set_bounds_from_center_and_zoom(
conf['map']['center'][0],
conf['map']['center'][1],
conf['map']['zoom'])
center_x,
center_y,
zoom)

self.projection = conf['map']['projection']

if self.uuid is None or self.uuid == '':
self.uuid = str(uuid.uuid1())

def source_for(layer):
return conf["sources"][layer["source"]]
try:
return conf["sources"][layer["source"]]
except BaseException:
if 'url' in layer:
return {'url': layer['url']}
else:
return {}

layers = [l for l in conf["map"]["layers"]]
layer_names = set([l.alternate for l in self.local_layers])
Expand Down
2 changes: 1 addition & 1 deletion geonode/tests/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ def test_add_delete_styles(self):
resp = self.api_client.get(default_style_url)
if resp.status_code != 200:
return
except:
except BaseException:
return
self.assertValidJSONResponse(resp)
obj = self.deserialize(resp)
Expand Down
24 changes: 17 additions & 7 deletions geonode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,30 +297,40 @@ def layer_from_viewer_config(map_id, model, layer, source, ordering):
layer_cfg["wrapDateLine"] = True
layer_cfg["displayOutsideMaxExtent"] = True

source_cfg = dict(source)
for k in ["url", "projection"]:
if k in source_cfg:
del source_cfg[k]
source_cfg = dict(source) if source else {}
if source_cfg:
for k in ["url", "projection"]:
if k in source_cfg:
del source_cfg[k]

# We don't want to hardcode 'access_token' into the storage
styles = []
if 'capability' in layer_cfg:
capability = layer_cfg['capability']
if 'styles' in capability:
styles = capability['styles']
for style in styles:
if 'name' in styles:
styles.append(style['name'])
if 'legend' in style:
legend = style['legend']
if 'href' in legend:
legend['href'] = re.sub(
r'\&access_token=.*', '', legend['href'])
if not styles and layer.get("styles", None):
for style in layer.get("styles", None):
if 'name' in style:
styles.append(style['name'])
else:
styles.append(style)

_model = model(
map_id=map_id,
stack_order=ordering,
format=layer.get("format", None),
name=layer.get("name", None),
opacity=layer.get("opacity", 1),
styles=layer.get("styles", None),
styles=styles,
transparent=layer.get("transparent", False),
fixed=layer.get("fixed", False),
group=layer.get('group', None),
Expand Down Expand Up @@ -404,7 +414,7 @@ def layer_config(l, user=None):
return cfg

source_urls = [source['url']
for source in sources.values() if 'url' in source]
for source in sources.values() if source and 'url' in source]

if 'geonode.geoserver' in settings.INSTALLED_APPS:
if len(sources.keys(
Expand All @@ -418,7 +428,7 @@ def layer_config(l, user=None):
def _base_source(source):
base_source = copy.deepcopy(source)
for key in ["id", "baseParams", "title"]:
if key in base_source:
if base_source and key in base_source:
del base_source[key]
return base_source

Expand Down

0 comments on commit 19f80f9

Please sign in to comment.