Skip to content

Commit 6bb4520

Browse files
authored
fix keywords, note that owslib keywords_object is not inserted in db (could be but should be managed in metadata.py) (#1025)
1 parent f42e6e5 commit 6bb4520

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

pycsw/ogc/api/records.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,15 +1147,18 @@ def record2json(record, url, collection, mode='ogcapi-records'):
11471147

11481148
# todo; for keywords with a scheme use the theme property
11491149
if record.topicategory:
1150-
themes = [{
1150+
tctheme = {
11511151
'concepts': [],
11521152
'scheme': 'https://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_TopicCategoryCode'
1153-
}]
1154-
1155-
for rtp in record.topicategory:
1156-
themes['concepts'].append({'id': rtp})
1153+
}
11571154

1158-
record_dict['properties']['themes'] = themes
1155+
if isinstance(record.topicategory, list):
1156+
for rtp in record.topicategory:
1157+
tctheme['concepts'].append({'id': rtp})
1158+
elif isinstance(record.topicategory, str):
1159+
tctheme['concepts'].append({'id': record.topicategory})
1160+
1161+
record_dict['properties']['themes'] = [tctheme]
11591162

11601163
if record.otherconstraints:
11611164
if isinstance(record.otherconstraints, str) and record.otherconstraints not in [None, 'None']:
@@ -1226,15 +1229,15 @@ def record2json(record, url, collection, mode='ogcapi-records'):
12261229
record_dict['properties']['contacts'] = rcnt
12271230

12281231
if record.themes not in [None, '', 'null']:
1229-
ogcapi_themes = []
1232+
ogcapi_themes = record_dict['properties'].get('themes', [])
12301233
# For a scheme, prefer uri over label
12311234
# OWSlib currently uses .keywords_object for keywords with url, see https://github.com/geopython/OWSLib/pull/765
12321235
try:
12331236
for theme in json.loads(record.themes):
12341237
try:
12351238
ogcapi_themes.append({
1236-
'scheme': theme['thesaurus'].get('url', theme['thesaurus'].get('title', '')),
1237-
'concepts': [{'id': c} for c in theme.get('keywords_object', []) if c not in [None, '']]
1239+
'scheme': theme['thesaurus'].get('url') or theme['thesaurus'].get('title'),
1240+
'concepts': [{'id': c.get('name','')} for c in theme.get('keywords', []) if 'name' in c and c['name'] not in [None, '']]
12381241
})
12391242
except Exception as err:
12401243
LOGGER.exception(f"failed to parse theme of {record.identifier}: {err}")

pycsw/ogc/api/templates/item.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ <h2>{{ data.get('properties',{}).get('title',data['id']) }}</h2>
7272
{% for concept in theme['concepts'] %}
7373
<li>
7474
{% if concept['url'] %}
75-
<a href="{{ concept['url'] }}">{{ concept['name'] or concept['url'] }}</a>
75+
<a href="{{ concept['url'] }}">{{ concept['id'] or concept['url'] }}</a>
7676
{% else %}
77-
{{ concept['name'] }}
77+
{{ concept['id'] }}
7878
{% endif %}
7979
</li>
8080
{% endfor %}

0 commit comments

Comments
 (0)