Skip to content

Commit

Permalink
deposit: improve form in submission process
Browse files Browse the repository at this point in the history
* Removes `classification` from the required fields.
* Adds the possibility to fill a full date for document date field.
* Renames `title` property for publication.
* Removes `pages` from required fields in publication.
* Hides or shows publication depending on document type.
* Adds a placeholder for `pages` property in publications.
* Adds a placeholder for document date.
* Removes `affiliation` from required fields in contributors.
* Closes #rero/sonar-ui#62.
* Closes #rero/sonar-ui#68.

Co-Authored-by: Sébastien Délèze <[email protected]>
Sébastien Délèze committed Jun 3, 2020

Verified

This commit was signed with the committer’s verified signature.
bep Bjørn Erik Pedersen
1 parent c6c9907 commit dd77731
Showing 9 changed files with 1,555 additions and 1,399 deletions.
108 changes: 61 additions & 47 deletions sonar/modules/deposits/api.py
Original file line number Diff line number Diff line change
@@ -134,10 +134,7 @@ def create_document(self):
})

# Languages
metadata['language'] = [{
'value': language,
'type': 'bf:Language'
}]
metadata['language'] = [{'value': language, 'type': 'bf:Language'}]

# Document date
if self['metadata'].get('documentDate'):
@@ -149,31 +146,36 @@ def create_document(self):
}]

# Published in
part_of = {
'numberingYear': self['metadata']['publication']['year'],
'numberingPages': self['metadata']['publication']['pages'],
'document': {
'title': self['metadata']['publication']['publishedIn']
if self['metadata'].get('publication'):
part_of = {
'numberingYear': self['metadata']['publication']['year'],
'document': {
'title': self['metadata']['publication']['publishedIn']
}
}
}
if self['metadata']['publication'].get('volume'):
part_of['numberingVolume'] = self['metadata']['publication'][
'volume']

if self['metadata']['publication'].get('number'):
part_of['numberingIssue'] = self['metadata']['publication'][
'number']
if self['metadata']['publication'].get('pages'):
part_of['numberingPages'] = self['metadata']['publication'][
'pages']

if self['metadata']['publication'].get('editors'):
part_of['document']['contribution'] = self['metadata'][
'publication']['editors']
if self['metadata']['publication'].get('volume'):
part_of['numberingVolume'] = self['metadata']['publication'][
'volume']

if self['metadata']['publication'].get('publisher'):
part_of['document']['publication'] = {
'statement': self['metadata']['publication']['publisher']
}
if self['metadata']['publication'].get('number'):
part_of['numberingIssue'] = self['metadata']['publication'][
'number']

metadata['partOf'] = [part_of]
if self['metadata']['publication'].get('editors'):
part_of['document']['contribution'] = self['metadata'][
'publication']['editors']

if self['metadata']['publication'].get('publisher'):
part_of['document']['publication'] = {
'statement': self['metadata']['publication']['publisher']
}

metadata['partOf'] = [part_of]

# Other electronic versions
if self['metadata'].get('otherElectronicVersions'):
@@ -190,18 +192,21 @@ def create_document(self):
'specificCollections']

# Classification
metadata['classification'] = [{
'type':
'bf:ClassificationUdc',
'classificationPortion':
self['metadata']['classification']
}]
if self['metadata'].get('classification'):
metadata['classification'] = [{
'type':
'bf:ClassificationUdc',
'classificationPortion':
self['metadata']['classification']
}]

# Abstracts
if self['metadata'].get('abstracts'):
metadata['abstracts'] = [{
'language': abstract.get('language', language),
'value': abstract['abstract']
'language':
abstract.get('language', language),
'value':
abstract['abstract']
} for abstract in self['metadata']['abstracts']]

# Subjects
@@ -214,21 +219,30 @@ def create_document(self):
} for subject in self['metadata']['subjects']]

# Contributors
metadata['contribution'] = [{
'agent': {
'type': 'bf:Person',
'preferred_name': contributor['name']
},
'role': ['cre'],
'affiliation': contributor['affiliation']
} for contributor in self['contributors']]

# Resolve controlled affiliations
for contributor in metadata['contribution']:
affiliations = DocumentRecord.get_affiliations(
contributor['affiliation'])
if affiliations:
contributor['controlledAffiliation'] = affiliations
contributors = []
for contributor in self['contributors']:
data = {
'agent': {
'type': 'bf:Person',
'preferred_name': contributor['name']
},
'role': ['cre'],
'affiliation': contributor.get('affiliation')
}

# Resolve controlled affiliations
if data.get('affiliation'):
affiliations = DocumentRecord.get_affiliations(
data['affiliation'])
if affiliations:
data['controlledAffiliation'] = affiliations
else:
data.pop('affiliation', None)

contributors.append(data)

if contributors:
metadata['contribution'] = contributors

document = DocumentRecord.create(metadata,
dbcommit=True,
41 changes: 22 additions & 19 deletions sonar/modules/deposits/jsonschemas/deposits/deposit-v1.0.0_src.json
Original file line number Diff line number Diff line change
@@ -249,8 +249,7 @@
"required": [
"language",
"title",
"documentType",
"classification"
"documentType"
],
"propertiesOrder": [
"documentType",
@@ -304,17 +303,16 @@
"type": "string",
"minLength": 1,
"pattern": "^[0-9]{4}(-[0-9]{2}-[0-9]{2})?$",
"template": {
"type": "date"
"form": {
"placeholder": "Example: 2019 or 2019-05-05"
}
},
"publication": {
"title": "Publication",
"title": "Part of (host document)",
"type": "object",
"required": [
"publishedIn",
"year",
"pages"
"year"
],
"additionalProperties": false,
"propertiesOrder": [
@@ -323,12 +321,13 @@
"volume",
"number",
"pages",
"editors",
"publisher"
"publisher",
"editors"
],
"properties": {
"publishedIn": {
"title": "Published in",
"title": "Document",
"description": "Host document, for example a journal for an article, or a book for a book chapter.",
"type": "string",
"minLength": 1
},
@@ -340,18 +339,23 @@
"volume": {
"title": "Volume",
"type": "string",
"minLength": 1
"minLength": 1,
"hideExpression": "!['coar:c_beb9', 'coar:c_6501', 'coar:c_998f', 'coar:c_dcae04bc'].includes(field.parent.parent.model.documentType)"
},
"number": {
"title": "Number",
"type": "string",
"minLength": 1
"minLength": 1,
"hideExpression": "!['coar:c_beb9', 'coar:c_6501', 'coar:c_998f', 'coar:c_dcae04bc'].includes(field.parent.parent.model.documentType)"
},
"pages": {
"title": "Pages",
"type": "string",
"minLength": 1,
"pattern": "^[0-9]+(-[0-9]+)?$"
"pattern": "^[0-9]+(-[0-9]+)?$",
"form": {
"placeholder": "Examples: 135, 5-27, …"
}
},
"editors": {
"title": "Editors",
@@ -368,7 +372,8 @@
"type": "string",
"minLength": 1
}
}
},
"hideExpression": "!['coar:c_3248', 'coar:c_5794', 'coar:c_6670', 'coar:c_beb9', 'coar:c_6501', 'coar:c_998f', 'coar:c_dcae04bc'].includes(field.parent.model.documentType)"
},
"otherElectronicVersions": {
"title": "Other electronic versions",
@@ -431,7 +436,7 @@
"title": "Abstract",
"type": "string",
"minLength": 1,
"template": {
"form": {
"type": "textarea",
"rows": 3
}
@@ -484,8 +489,7 @@
"title": "Contributor",
"type": "object",
"required": [
"name",
"affiliation"
"name"
],
"propertiesOrder": [
"name",
@@ -496,8 +500,7 @@
"title": "Name",
"description": "Last name, first name, ex: Doe, John",
"type": "string",
"minLength": 1,
"pattern": "^[^,]+, [^,]+$"
"minLength": 1
},
"affiliation": {
"title": "Affiliation",
2 changes: 1 addition & 1 deletion sonar/modules/pdf_extractor/utils.py
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ def format_extracted_data(data):
author_data['name'] = ', '.join(name)

if author_data.get('name'):
author_data['affiliation'] = '[Unknown]'
author_data['affiliation'] = None

affiliations = force_list(author.get('affiliation', []))

559 changes: 295 additions & 264 deletions sonar/translations/de/LC_MESSAGES/messages.po

Large diffs are not rendered by default.

559 changes: 295 additions & 264 deletions sonar/translations/en/LC_MESSAGES/messages.po

Large diffs are not rendered by default.

559 changes: 295 additions & 264 deletions sonar/translations/fr/LC_MESSAGES/messages.po

Large diffs are not rendered by default.

559 changes: 295 additions & 264 deletions sonar/translations/it/LC_MESSAGES/messages.po

Large diffs are not rendered by default.

543 changes: 279 additions & 264 deletions sonar/translations/messages.pot

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions tests/ui/deposits/test_deposits_api.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ def test_create_document(app, deposit_fixture):
document = deposit_fixture.create_document()

assert document['documentType'] == 'coar:c_816b'

assert document['title'] == [{
'type':
'bf:Title',
@@ -39,14 +38,11 @@ def test_create_document(app, deposit_fixture):
'value': 'Subtitle of the document'
}]
}]

assert document['language'] == [{'value': 'eng', 'type': 'bf:Language'}]

assert document['provisionActivity'] == [{
'type': 'bf:Publication',
'startDate': '2020-01-01'
}]

assert document['partOf'] == [{
'numberingYear': '2019',
'numberingPages': '1-12',
@@ -60,29 +56,24 @@ def test_create_document(app, deposit_fixture):
'numberingVolume': '12',
'numberingIssue': '2'
}]

assert document['otherEdition'] == [{
'document': {
'electronicLocator': 'https://some.url/document.pdf'
},
'publicNote': 'Published version'
}]

assert document['specificCollections'] == ['Collection 1', 'Collection 2']

assert document['classification'] == [{
'type': 'bf:ClassificationUdc',
'classificationPortion': '543'
}]

assert document['abstracts'] == [{
'language': 'eng',
'value': 'Abstract of the document'
}, {
'language': 'fre',
'value': 'Résumé du document'
}]

assert document['subjects'] == [{
'label': {
'language': 'eng',
@@ -94,7 +85,6 @@ def test_create_document(app, deposit_fixture):
'value': ['Sujet 1', 'Sujet 2']
}
}]

assert document['contribution'] == [{
'affiliation':
'University of Bern, Switzerland',
@@ -105,8 +95,18 @@ def test_create_document(app, deposit_fixture):
'controlledAffiliation': ['Uni of Bern and Hospital'],
'role': ['cre']
}]

assert document.files['main.pdf']['restricted'] == 'organisation'
assert document.files['main.pdf']['embargo_date'] == '2021-01-01'

assert len(document.files) == 6

# Test without affiliation
deposit_fixture['contributors'][0]['affiliation'] = None
document = deposit_fixture.create_document()

assert document['contribution'] == [{
'agent': {
'preferred_name': 'Takayoshi, Shintaro',
'type': 'bf:Person'
},
'role': ['cre']
}]

0 comments on commit dd77731

Please sign in to comment.