Skip to content

Commit

Permalink
[Hardening] fixup Legend links
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Nov 15, 2019
1 parent 4892b24 commit 012ac64
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions geonode/base/management/commands/set_all_layers_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#
#########################################################################

from geonode.geoserver.helpers import ogc_server_settings
from django.core.management.base import BaseCommand
from geonode.base.models import Link
from geonode.layers.models import Layer
Expand Down Expand Up @@ -104,6 +105,21 @@ def handle(self, *args, **options):
while _links.count() > 1:
_links.last().delete()
print '.',
# fixup Legend links
legend_url_template = ogc_server_settings.PUBLIC_LOCATION + \
'ows?service=WMS&request=GetLegendGraphic&format=image/png&WIDTH=20&HEIGHT=20&LAYER=' + \
'{alternate}&STYLE={style_name}' + \
'&legend_options=fontAntiAliasing:true;fontSize:12;forceLabels:on'
if 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=legend_url_template.format(
alternate=layer.alternate,
style_name=layer.default_style.name),
mime='image/png',
link_type='image')
except BaseException as e:
import traceback
traceback.print_exc()
Expand Down
4 changes: 2 additions & 2 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,12 +1107,12 @@ def get_legend_url(self, style_name=None):

if legend.count() > 0:
if not style_name:
return legend[0].url
return legend.first().url
else:
for _legend in legend:
if style_name in _legend.url:
return _legend.url
return legend.url
return None

def get_ows_url(self):
"""Return URL for OGC WMS server None if it does not exist.
Expand Down
2 changes: 1 addition & 1 deletion geonode/layers/templates/layers/layer_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ <h5 class="modal-title" id="myModalLabel">{% trans "Attribute Information" %}</h
<h4 class="list-group-item-heading">{%trans "Legend" %}</h4>
{% if resource.default_style %}
{% for style in resource.styles.all %}
{% if resource.default_style == style %}
{% if resource.default_style == style or resource.default_style.name == style.name or resource.default_style.sld_title == style.sld_title %}
{% for legend in resource.get_legend %}
{% with "STYLE="|add:style.name as style_name %}
{% if legend.link_type == 'image' and style_name in legend.url %}
Expand Down

0 comments on commit 012ac64

Please sign in to comment.