Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documents: improve detail views #258

Merged
merged 1 commit into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 103 additions & 22 deletions data/complete_document_sample.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"documentType": "coar:c_3248",
"identifiedBy": [
{
"value": "urn:nbn:ch:rero-006-108713",
Expand All @@ -15,18 +16,72 @@
"type": "bf:Language"
}
],
"classification": [
{
"classificationPortion": "621.38",
"type": "bf:ClassificationUdc"
}
],
"contribution": [
{
"agent": {
"type": "bf:Person",
"preferred_name": "John, Doe",
"preferred_name": "Brenda, Collins",
"date_of_birth": "1960",
"date_of_death": "2000"
},
"role": [
"cre"
],
"affiliation": "Institute for Research"
},
{
"agent": {
"type": "bf:Person",
"preferred_name": "Esther, Owens",
"identifiedBy": {
"source": "ORCID",
"type": "bf:Doi",
"value": "1111-2222-3333-4444"
}
},
"role": [
"cre"
],
"controlledAffiliation": [
"HEP Vaud"
],
"affiliation": "Haute école Pédagogique de Lausanne"
},
{
"agent": {
"type": "bf:Person",
"preferred_name": "Joe, Holloway"
},
"role": [
"cre"
],
"affiliation": "Institute for Research"
},
{
"agent": {
"type": "bf:Person",
"preferred_name": "Edgar, Sowards"
},
"role": [
"cre"
],
"affiliation": "Institute for Research"
},
{
"agent": {
"type": "bf:Person",
"preferred_name": "Lauren, Sena"
},
"role": [
"ctb"
],
"affiliation": "Institute for Research"
}
],
"title": [
Expand All @@ -50,16 +105,51 @@
"abstracts": [
{
"language": "eng",
"value": "Abstract of the document"
"value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum id ex vitae ipsum fermentum auctor vitae eget sem. Nam sed facilisis metus. Nullam dignissim massa vel leo euismod, quis rutrum neque cursus. Quisque fermentum libero ut urna tincidunt interdum. Fusce condimentum accumsan ipsum vel mattis. Sed ultricies tellus sed ultrices semper. Vestibulum hendrerit risus at dui gravida, nec pulvinar mauris imperdiet. Cras iaculis massa a pellentesque vulputate. Mauris ac tellus sit amet risus suscipit ullamcorper. Donec fermentum tellus in ligula ullamcorper, eu condimentum elit tincidunt. Suspendisse lacinia porta velit, quis mattis quam posuere eu. Nam feugiat massa magna, bibendum vestibulum eros feugiat nec. Ut quis semper lectus, in porttitor nibh."
},
{
"language": "fre",
"value": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum id ex vitae ipsum fermentum auctor vitae eget sem. Nam sed facilisis metus. Nullam dignissim massa vel leo euismod, quis rutrum neque cursus. Quisque fermentum libero ut urna tincidunt interdum. Fusce condimentum accumsan ipsum vel mattis. Sed ultricies tellus sed ultrices semper. Vestibulum hendrerit risus at dui gravida, nec pulvinar mauris imperdiet. Cras iaculis massa a pellentesque vulputate. Mauris ac tellus sit amet risus suscipit ullamcorper. Donec fermentum tellus in ligula ullamcorper, eu condimentum elit tincidunt. Suspendisse lacinia porta velit, quis mattis quam posuere eu. Nam feugiat massa magna, bibendum vestibulum eros feugiat nec. Ut quis semper lectus, in porttitor nibh."
}
],
"subjects": [
{
"language": "eng",
"value": [
"Time series models",
"GARCH models"
]
"label": {
"language": "eng",
"value": [
"Time series models",
"GARCH models"
]
},
"source": "Source"
},
{
"label": {
"language": "fre",
"value": [
"Sujet 1",
"Sujet 2"
]
}
}
],
"partOf": [
{
"document": {
"contribution": [
"Renato, Ferrari",
"Albano, Mesta"
],
"publication": {
"startDate": "2019-05-05",
"statement": "John Doe Publications inc."
},
"title": "Journal du dimanche"
},
"numberingPages": "135-139",
"numberingYear": "2020",
"numberingVolume": "6",
"numberingIssue": "12"
}
],
"provisionActivity": [
Expand Down Expand Up @@ -125,24 +215,15 @@
"value": "Zeng Lingliang zhu bian"
}
},
"copyrightDate": [
"© 1971"
],
"series": [
"otherEdition": [
{
"name": "Collection One",
"number": "5"
},
{
"name": "Collection Two",
"number": "123"
"document": {
"electronicLocator": "https://www.rero.ch"
},
"publicNote": "Published version"
}
],
"notes": [
"Note 1",
"Note 2"
],
"organisation": {
"$ref": "https://sonar.ch/api/organisations/org"
"$ref": "https://sonar.ch/api/organisations/rero"
}
}
2 changes: 1 addition & 1 deletion sonar/modules/deposits/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def create_document(self):
# ORCID for contributor
if contributor.get('orcid'):
data['agent']['identifiedBy'] = {
'type': 'bf:Doi',
'type': 'bf:Local',
'source': 'ORCID',
'value': contributor['orcid']
}
Expand Down
17 changes: 17 additions & 0 deletions sonar/modules/documents/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import csv
from functools import partial

from flask import current_app

from ..api import SonarIndexer, SonarRecord, SonarSearch
from ..fetchers import id_fetcher
from ..minters import id_minter
Expand Down Expand Up @@ -94,6 +96,21 @@ def get_affiliations(full_affiliation):

return controlled_affiliations

@staticmethod
def get_permanent_link(host, pid, org=None):
"""Return the permanent link for the document.

:param host: Application server host.
:param org: Organisation key.
:param pid: PID of the document.
:returns: Document's full URL as string.
"""
if not org:
org = current_app.config.get('SONAR_APP_DEFAULT_ORGANISATION')

return current_app.config.get('SONAR_DOCUMENTS_PERMALINK').format(
host=host, org=org, pid=pid)

@classmethod
def get_record_by_identifier(cls, identifiers):
"""Get a record by its identifier.
Expand Down
3 changes: 3 additions & 0 deletions sonar/modules/documents/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@

SONAR_DOCUMENTS_ORGANISATIONS_EXTERNAL_FILES = ['csal']
"""Display external files URL for these organisations."""

SONAR_DOCUMENTS_PERMALINK = '{host}organisation/{org}/documents/{pid}'
"""Permalink for accessing documents details."""
Original file line number Diff line number Diff line change
Expand Up @@ -1066,13 +1066,18 @@
"title": "Type",
"type": "string",
"enum": [
"bf:Doi"
"bf:Doi",
"bf:Local"
],
"form": {
"options": [
{
"label": "bf:Doi",
"value": "bf:Doi"
},
{
"label": "bf:Local",
"value": "bf:Local"
}
]
}
Expand Down
46 changes: 45 additions & 1 deletion sonar/modules/documents/marshmallow/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from functools import partial

from flask import request
from flask_security import current_user
from invenio_records_rest.schemas import Nested, StrictKeysMixin
from invenio_records_rest.schemas.fields import GenFunction, \
Expand All @@ -29,7 +30,8 @@

from sonar.modules.documents.api import DocumentRecord
from sonar.modules.documents.permissions import DocumentPermission
from sonar.modules.documents.views import is_file_restricted
from sonar.modules.documents.views import create_publication_statement, \
is_file_restricted, part_of_format
from sonar.modules.serializers import schema_from_context
from sonar.modules.users.api import current_user_record

Expand Down Expand Up @@ -96,6 +98,7 @@ class DocumentMetadataSchemaV1(StrictKeysMixin):
data_key="$schema",
deserialize=schema_from_document)
permissions = fields.Dict(dump_only=True)
permalink = fields.Dict(dump_only=True)

@pre_dump
def add_files_restrictions(self, item):
Expand Down Expand Up @@ -135,6 +138,34 @@ def add_permissions(self, item):

return item

@pre_dump
def add_permalink(self, item):
"""Add permanent link to document."""
item['permalink'] = DocumentRecord.get_permanent_link(
request.host_url, item['pid'])
return item

@pre_dump
def add_formatted_texts(self, item):
"""Add formatted texts for objects which are processing in backend.

:param item: Dict of record data.
:returns: Modified data.
"""
# Provision activity processing
for index, provision_activity in enumerate(
item.get('provisionActivity', [])):
item['provisionActivity'][index][
'text'] = create_publication_statement(provision_activity)

# Part of proccessing
for index, part_of in enumerate(
item.get('partOf', [])):
item['partOf'][index][
'text'] = part_of_format(part_of)

return item

@pre_load
def guess_organisation(self, data, **kwargs):
"""Guess organisation from current logged user.
Expand All @@ -152,6 +183,19 @@ def guess_organisation(self, data, **kwargs):

return data

@pre_load
def remove_formatted_texts(self, data):
"""Removes formatted texts from `provisionActivity` and `partOf` fields.

:param data: Dict of record data.
:returns: Modified data.
"""
for provision_activity in data.get('provisionActivity', []):
provision_activity.pop('text', None)

for part_of in data.get('partOf', []):
part_of.pop('text', None)


class DocumentSchemaV1(StrictKeysMixin):
"""Document schema."""
Expand Down
Loading