Skip to content

Commit

Permalink
[Fixes #8611] Setting style version for upload, re-generate thumbnail (
Browse files Browse the repository at this point in the history
…#8612)

* Setting style version for upload, re-generate thumbnail

* take out the thumbnail generation from the view
  • Loading branch information
lsntdev authored Jan 20, 2022
1 parent 25a3265 commit 024e445
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion geonode/geoserver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from geoserver.support import DimensionInfo
from geoserver.workspace import Workspace
from gsimporter import Client
from lxml import etree
from lxml import etree, objectify
from defusedxml import lxml as dlxml
from owslib.wcs import WebCoverageService
from owslib.wms import WebMapService
Expand Down Expand Up @@ -192,6 +192,22 @@ def _add_sld_boilerplate(symbolizer):
"vectorTimeSeries": "vector_time"
}

STYLES_VERSION = {
"1.0.0" : "sld10",
"1.1.0" : "sld11"
}

def _extract_style_version_from_sld(sld):
"""
Assume: SLD as a byte
"""
root = objectify.fromstring(sld)
try:
return STYLES_VERSION[root.attrib["version"].strip()]
except Exception:
return STYLES_VERSION["1.0.0"]



def _style_name(resource):
return _punc.sub("_", f"{resource.store.workspace.name}:{resource.name}")
Expand Down Expand Up @@ -387,6 +403,7 @@ def set_layer_style(saved_layer, title, sld, base_file=None):
overwrite=True, raw=True,
workspace=saved_layer.workspace)
elif sld:
style.style_format = _extract_style_version_from_sld(sld)
style.update_body(sld)
except Exception as e:
logger.exception(e)
Expand Down

0 comments on commit 024e445

Please sign in to comment.