Skip to content

Commit

Permalink
Merge pull request #4176 from GeoNode/ogc_links_in_layers_list
Browse files Browse the repository at this point in the history
show OGC links inside layers list from the API
  • Loading branch information
Alessio Fabiani authored Jan 25, 2019
2 parents 81255d5 + 3101ce0 commit 704b8d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 14 additions & 5 deletions geonode/api/resourcebase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,12 +744,11 @@ def format_objects(self, objects):
formatted_obj['default_style'] = self.default_style.dehydrate(
bundle, for_list=True)

if self.links.use_in == 'all' or self.links.use_in == 'list':
formatted_obj['links'] = self.dehydrate_links(
bundle)
# Add resource uri
formatted_obj['resource_uri'] = self.get_resource_uri(bundle)

formatted_obj['links'] = self.dehydrate_ogc_links(bundle)

if 'site_url' not in formatted_obj or len(formatted_obj['site_url']) == 0:
formatted_obj['site_url'] = settings.SITEURL

Expand All @@ -770,7 +769,7 @@ def format_objects(self, objects):
formatted_objects.append(formatted_obj)
return formatted_objects

def dehydrate_links(self, bundle):
def _dehydrate_links(self, bundle, link_types=None):
"""Dehydrate links field."""

dehydrated = []
Expand All @@ -782,12 +781,22 @@ def dehydrate_links(self, bundle):
'mime',
'url'
]
for l in obj.link_set.all():

links = obj.link_set.all()
if link_types:
links = links.filter(link_type__in=link_types)
for l in links:
formatted_link = model_to_dict(l, fields=link_fields)
dehydrated.append(formatted_link)

return dehydrated

def dehydrate_links(self, bundle):
return self._dehydrate_links(bundle)

def dehydrate_ogc_links(self, bundle):
return self._dehydrate_links(bundle, ['OGC:WMS', 'OGC:WFS', 'OGC:WCS'])

def dehydrate_gtype(self, bundle):
return bundle.obj.gtype

Expand Down
2 changes: 0 additions & 2 deletions geonode/tests/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,8 +1582,6 @@ def test_layer_interaction(self):
objects = self.deserialize(resp)['objects']
self.assertEqual(len(objects), 1)
obj = objects[0]
# Should not have links
self.assertFalse('links' in obj)
# Should not have styles
self.assertTrue('styles' not in obj)
# Should have default_style
Expand Down

0 comments on commit 704b8d5

Please sign in to comment.