def _create_layer_legend_link(self, geonode_layer): """Get the layer's legend and save it locally Regardless of the service being INDEXED or CASCADED we're always creating the legend by making a request directly to the original service. """ cleaned_url, service, version, request = WmsServiceHandler.get_cleaned_url_params(self.url) _p_url = urlparse(self.url) legend_url = get_legend_url( geonode_layer, "", service_url=f"{_p_url.scheme}://{_p_url.netloc}{_p_url.path}", layer_name=geonode_layer.name, version=version, params=_p_url.query ) logger.debug(f"legend_url: {legend_url}") try: Link.objects.get_or_create( resource=geonode_layer.resourcebase_ptr, url=legend_url, name='Legend', defaults={ "extension": 'png', "name": 'Legend', "url": legend_url, "mime": 'image/png', "link_type": 'image', } ) except ResourceBase.DoesNotExist as e: logger.exception(e) return legend_url
def _create_layer_legend_link(self, geonode_service, geonode_layer): """Get the layer's legend and save it locally Regardless of the service being INDEXED or CASCADED we're always creating the legend by making a request directly to the original service. """ legend_url = get_legend_url(geonode_layer, "", service_url=geonode_service.base_url, layer_name=geonode_layer.name, version=geonode_service.version, params=geonode_service.extra_queryparams) logger.debug(f"legend_url: {legend_url}") try: Link.objects.get_or_create(resource=geonode_layer.resourcebase_ptr, url=legend_url, name='Legend', defaults={ "extension": 'png', "name": 'Legend', "url": legend_url, "mime": 'image/png', "link_type": 'image', }) except ResourceBase.DoesNotExist as e: logger.exception(e) return legend_url
def remove_duplicate_links(resource): """ Makes a scan of Links related to the resource and removes the duplicates. It also regenerates the Legend link in case this is missing for some reason. """ for _n in _names: _links = Link.objects.filter(resource__id=resource.id, name=_n) _cnt = _links.count() while _cnt > 1: _links.last().delete() _cnt -= 1 if isinstance(resource, Dataset): # fixup Legend links layer = resource if layer.default_style and not layer.get_legend_url(style_name=layer.default_style.name): Link.objects.update_or_create( resource=layer.resourcebase_ptr, name='Legend', extension='png', url=get_legend_url(layer, layer.default_style.name), mime='image/png', link_type='image')