Skip to content

Commit

Permalink
documents: fix publication statement text dumping
Browse files Browse the repository at this point in the history
Closes #2670.

Co-Authored-by: Renaud Michotte <[email protected]>
  • Loading branch information
zannkukai committed Mar 10, 2022
1 parent bae2968 commit dc23eae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
41 changes: 19 additions & 22 deletions rero_ils/modules/documents/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ def get_document_types_from_schema(schema='doc'):
path = current_jsonschemas.url_to_path(get_schema_for_resource(schema))
schema = current_jsonschemas.get_schema(path=path)
schema = _records_state.replace_refs(schema)
schema_types = schema.get(
'properties', {}).get('type', {}).get('items', {}).get('oneOf', [])
schema_types = schema\
.get('properties', {})\
.get('type', {})\
.get('items', {})\
.get('oneOf', [])
doc_types = {}
for schema_type in schema_types:
doc_types[schema_type['title']] = {}
sub_types = schema_type.get(
'properties', {}).get('subtype', {}).get('enum', [])
for sub_type in sub_types:
doc_types[schema_type['title']][sub_type] = True
schema_title = schema_type['title']
sub_types = schema_type\
.get('properties', {})\
.get('subtype', {})\
.get('enum', [])
doc_types[schema_title] = {sub_type: True for sub_type in sub_types}
return doc_types


Expand Down Expand Up @@ -91,26 +95,20 @@ def publication_statement_text(provision_activity):
"""Create publication statement from place, agent and date values."""
punctuation = {
'bf:Place': ' ; ',
'bf:Agent': ', ',
'bf:Agent': ' ; ',
'Date': ', '
}

statement_with_language = {'default': ''}
statement_type = None

last_statement_type = None
# Perform each statement entries to build the best possible string
for statement in provision_activity.get('statement', []):
labels = statement['label']

for label in labels:
for label in statement['label']:
language = label.get('language', 'default')

if not statement_with_language.get(language):
statement_with_language[language] = ''

statement_with_language.setdefault(language, '')
if statement_with_language[language]:
if statement_type == statement['type']:
if last_statement_type == statement['type']:
statement_with_language[language] += punctuation[
statement_type
last_statement_type
]
elif statement['type'] == 'bf:Place':
statement_with_language[language] += ' ; '
Expand All @@ -120,8 +118,7 @@ def publication_statement_text(provision_activity):
statement_with_language[language] += ' : '

statement_with_language[language] += label['value']
statement_type = statement['type']

last_statement_type = statement['type']
# date field: remove ';' and append
statement_text = []
for key, value in statement_with_language.items():
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_documents_dojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ def test_marc21_to_provisionActivity_unknown_place_2_agents():
}
]
assert create_publication_statement(data.get('provisionActivity')[0]) == [
'[Lieu de publication non identifié] : Labor, Nathan, 1968'
'[Lieu de publication non identifié] : Labor ; Nathan, 1968'
]


Expand Down

0 comments on commit dc23eae

Please sign in to comment.