Skip to content

Commit

Permalink
CSW get_template_path_and_values works even if the layer is not in Ge…
Browse files Browse the repository at this point in the history
…oServer

Fix #285
  • Loading branch information
jirik committed Mar 10, 2021
1 parent 490c08e commit fac23e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- [#273](https://github.com/jirik/layman/issues/273) New endpoints [GET Layers](doc/rest.md#get-layers) and [GET Layers](doc/rest.md#get-maps) to query publications in all [workspaces](doc/models.md#workspace).
- [#273](https://github.com/jirik/layman/issues/273) All Layer(s) and Map(s) endpoints with `<workspace_name>` in their URL were renamed to 'Workspace Layer...' and 'Workspace Map' in the documentation.

## v1.10.1
2021-03-10
### Changes
- [#285](https://github.com/jirik/layman/issues/285) Fix upgrade 1.10.0 error (CSW get_template_path_and_values now works even if the layer is not in GeoServer).

## v1.10.0
2021-03-04
Expand Down
28 changes: 19 additions & 9 deletions src/layman/layer/micka/csw.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
from layman.layer import db
from layman.layer.geoserver import wms
from layman.layer.geoserver import wfs
from layman.layer.geoserver.util import get_gs_proxy_base_url
from layman.layer import LAYER_TYPE
from layman import settings, patch_mode, LaymanError
from layman.util import url_for
from layman.util import url_for, get_publication_info
from requests.exceptions import HTTPError, ConnectionError
from urllib.parse import urljoin
from lxml import etree as ET

PATCH_MODE = patch_mode.NO_DELETE
Expand Down Expand Up @@ -126,13 +124,25 @@ def csw_insert(username, layername):
def get_template_path_and_values(username, layername, http_method=None):
assert http_method in ['post', 'patch']
wmsi = wms.get_wms_proxy(username)
wms_layer = wmsi.contents[layername]
wms_layer = wmsi.contents.get(layername) if wmsi else None
publ_info = get_publication_info(username, LAYER_TYPE, layername, context={
'keys': ['title'],
})
title = publ_info['title']

if wms_layer:
abstract = wms_layer.abstract
extent = wms_layer.boundingBoxWGS84
else:
abstract = None
extent = [-180, -90, 180, 90]

uuid_file_path = get_publication_uuid_file(LAYER_TYPE, username, layername)
publ_datetime = datetime.fromtimestamp(os.path.getmtime(uuid_file_path))
revision_date = datetime.now()
md_language = next(iter(common_language.get_languages_iso639_2(' '.join([
wms_layer.title or '',
wms_layer.abstract or ''
title or '',
abstract or ''
]))), None)
languages = db.get_text_languages(username, layername)
scale_denominator = db.guess_scale_denominator(username, layername)
Expand All @@ -141,14 +151,14 @@ def get_template_path_and_values(username, layername, http_method=None):
username=username,
layername=layername,
uuid=get_layer_uuid(username, layername),
title=wms_layer.title,
abstract=wms_layer.abstract or None,
title=title,
abstract=abstract or None,
publication_date=publ_datetime.strftime('%Y-%m-%d'),
revision_date=revision_date.strftime('%Y-%m-%d'),
md_date_stamp=date.today().strftime('%Y-%m-%d'),
identifier=url_for('rest_workspace_layer.get', username=username, layername=layername),
identifier_label=layername,
extent=wms_layer.boundingBoxWGS84,
extent=extent,
wms_url=wms.get_wms_url(username, external_url=True),
wfs_url=wfs.get_wfs_url(username, external_url=True),
md_organisation_name=None,
Expand Down

0 comments on commit fac23e5

Please sign in to comment.