Skip to content

Commit c532be3

Browse files
authored
adds the contactinfo from dedicated role fields (#1014)
* adds the contactinfo from dedicated role fields, if the role does not already exists in contacts * fix code to consider record as object, also refactor if/else * remove print statement
1 parent 6bb4520 commit c532be3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pycsw/ogc/api/records.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,11 @@ def record2json(record, url, collection, mode='ogcapi-records'):
11961196

11971197
if record.contacts not in [None, '', 'null']:
11981198
rcnt = []
1199+
roles = []
11991200
try:
12001201
for cnt in json.loads(record.contacts):
12011202
try:
1203+
roles.append(cnt.get('role', '').lower())
12021204
rcnt.append({
12031205
'name': cnt['name'],
12041206
'organization': cnt.get('organization', ''),
@@ -1223,6 +1225,13 @@ def record2json(record, url, collection, mode='ogcapi-records'):
12231225
})
12241226
except Exception as err:
12251227
LOGGER.exception(f"failed to parse contact of {record.identifier}: {err}")
1228+
for r2 in "creator,publisher,contributor".split(","): # match role-fields with contacts
1229+
if r2 not in roles and hasattr(record,r2) and record[r2] not in [None,'']:
1230+
rcnt.append({
1231+
'organization': record[r2],
1232+
'roles': [r2]
1233+
})
1234+
12261235
except Exception as err:
12271236
LOGGER.exception(f"failed to parse contacts json of {record.identifier}: {err}")
12281237

0 commit comments

Comments
 (0)