Skip to content

Commit

Permalink
fix keywords, note that owslib keywords_object is not inserted in db …
Browse files Browse the repository at this point in the history
…(could be but should be managed in metadata.py) (#1025)
  • Loading branch information
pvgenuchten authored Sep 30, 2024
1 parent f42e6e5 commit 6bb4520
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions pycsw/ogc/api/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,15 +1147,18 @@ def record2json(record, url, collection, mode='ogcapi-records'):

# todo; for keywords with a scheme use the theme property
if record.topicategory:
themes = [{
tctheme = {
'concepts': [],
'scheme': 'https://standards.iso.org/iso/19139/resources/gmxCodelists.xml#MD_TopicCategoryCode'
}]

for rtp in record.topicategory:
themes['concepts'].append({'id': rtp})
}

record_dict['properties']['themes'] = themes
if isinstance(record.topicategory, list):
for rtp in record.topicategory:
tctheme['concepts'].append({'id': rtp})
elif isinstance(record.topicategory, str):
tctheme['concepts'].append({'id': record.topicategory})

record_dict['properties']['themes'] = [tctheme]

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

if record.themes not in [None, '', 'null']:
ogcapi_themes = []
ogcapi_themes = record_dict['properties'].get('themes', [])
# For a scheme, prefer uri over label
# OWSlib currently uses .keywords_object for keywords with url, see https://github.com/geopython/OWSLib/pull/765
try:
for theme in json.loads(record.themes):
try:
ogcapi_themes.append({
'scheme': theme['thesaurus'].get('url', theme['thesaurus'].get('title', '')),
'concepts': [{'id': c} for c in theme.get('keywords_object', []) if c not in [None, '']]
'scheme': theme['thesaurus'].get('url') or theme['thesaurus'].get('title'),
'concepts': [{'id': c.get('name','')} for c in theme.get('keywords', []) if 'name' in c and c['name'] not in [None, '']]
})
except Exception as err:
LOGGER.exception(f"failed to parse theme of {record.identifier}: {err}")
Expand Down
4 changes: 2 additions & 2 deletions pycsw/ogc/api/templates/item.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ <h2>{{ data.get('properties',{}).get('title',data['id']) }}</h2>
{% for concept in theme['concepts'] %}
<li>
{% if concept['url'] %}
<a href="{{ concept['url'] }}">{{ concept['name'] or concept['url'] }}</a>
<a href="{{ concept['url'] }}">{{ concept['id'] or concept['url'] }}</a>
{% else %}
{{ concept['name'] }}
{{ concept['id'] }}
{% endif %}
</li>
{% endfor %}
Expand Down

0 comments on commit 6bb4520

Please sign in to comment.