Skip to content

Commit

Permalink
templating: Document detail
Browse files Browse the repository at this point in the history
NEW Format and show information on document detail page.

Signed-off-by: Sébastien Délèze <sebastien.deleze@rero.ch>
  • Loading branch information
Sébastien Délèze committed Jul 23, 2019
1 parent f32d9be commit 272f6d3
Show file tree
Hide file tree
Showing 17 changed files with 545 additions and 80 deletions.
4 changes: 2 additions & 2 deletions sonar/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ def _(x):
'documents': dict(
aggs=dict(
institution=dict(terms=dict(field='institution.pid')),
language=dict(terms=dict(field='languages.language')),
language=dict(terms=dict(field='languages.name')),
author=dict(terms=dict(field='facet_authors')),
subject=dict(terms=dict(field='facet_subjects'))
),
filters={
_('institution'): terms_filter('institution.pid'),
_('language'): terms_filter('languages.language'),
_('language'): terms_filter('languages.name'),
_('author'): terms_filter('facet_authors'),
_('subject'): terms_filter('facet_subjects'),
}
Expand Down
15 changes: 15 additions & 0 deletions sonar/modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,18 @@
"""SONAR configuration."""

SONAR_APP_API_URL = 'https://localhost:5000/api/'

SONAR_APP_LANGUAGES_MAP = dict(
fre='fr',
ger='de',
eng='en',
ita='it',
spa='sp',
ara='ar',
chi='zh',
lat='la',
heb='iw',
jpn='ja',
por='pt',
rus='ru'
)
52 changes: 34 additions & 18 deletions sonar/modules/documents/dojson/contrib/marc21tojson/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,29 @@
import sys

import requests
from babel import Locale
from dojson import Overdo, utils
from flask import current_app

marc21tojson = Overdo()


def remove_punctuation(data):
"""Remove punctuation from data."""
try:
if data[-1:] == ',':
data = data[:-1]
if data[-2:] == ' :':
data = data[:-2]
if data[-2:] == ' ;':
data = data[:-2]
if data[-2:] == ' /':
data = data[:-2]
if data[-2:] == ' -':
data = data[:-2]
except Exception:
pass
if not isinstance(data, str):
return data

if data[-1:] == ',':
data = data[:-1]
if data[-2:] == ' :':
data = data[:-2]
if data[-2:] == ' ;':
data = data[:-2]
if data[-2:] == ' /':
data = data[:-2]
if data[-2:] == ' -':
data = data[:-2]

return data


Expand Down Expand Up @@ -150,7 +153,12 @@ def marc21_to_languages(self, key, value):
languages: 008 and 041 [$a, repetitive]
"""
language = value.strip()[35:38]
to_return = [{'language': language}]
code = current_app.config.get('SONAR_APP_LANGUAGES_MAP')[language]

to_return = [{
'code': language,
'name': Locale(code).get_language_name().capitalize()
}]
return to_return


Expand All @@ -165,7 +173,7 @@ def marc21_to_translatedFrom(self, key, value):
languages = self.get('languages', [])
unique_lang = []
if languages != []:
unique_lang.append(languages[0]['language'])
unique_lang.append(languages[0]['code'])

language = value.get('a')
if language:
Expand All @@ -175,7 +183,11 @@ def marc21_to_translatedFrom(self, key, value):

languages = []
for lang in unique_lang:
languages.append({'language': lang})
code = current_app.config.get('SONAR_APP_LANGUAGES_MAP')[lang]
languages.append({
'code': lang,
'name': Locale(code).get_language_name().capitalize()
})

self['languages'] = languages
translated = value.get('h')
Expand Down Expand Up @@ -327,7 +339,10 @@ def marc21_to_abstracts(self, key, value):
abstract: [520$a repetitive]
"""
return ', '.join(utils.force_list(value.get('a')))
return {
'language': value.get('9'),
'value': ', '.join(utils.force_list(value.get('a')))
}


@marc21tojson.over('identifiers', '^020..')
Expand Down Expand Up @@ -380,11 +395,12 @@ def marc21_to_is_part_of(self, key, value):


@marc21tojson.over('subjects', '^6....')
@utils.for_each_value
@utils.ignore_value
def marc21_to_subjects(self, key, value):
"""Get subjects.
subjects: 6xx [duplicates could exist between several vocabularies,
if possible deduplicate]
"""
return value.get('a').split(' ; ')
return dict(language=value.get('9'), value=value.get('a').split(' ; '))
86 changes: 76 additions & 10 deletions sonar/modules/documents/jsonschemas/documents/document-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,38 @@
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"minLength": 3
"type": "object",
"additionalProperties": false,
"required": [
"language", "value"
],
"properties": {
"language": {
"title": "Abstract language",
"description": "Language of abstract.",
"type": "string",
"enum": [
"fre",
"ger",
"eng",
"ita",
"spa",
"ara",
"chi",
"lat",
"heb",
"jpn",
"por",
"rus"
]
},
"value": {
"title": "Abstract content",
"description": "Text content of abstract.",
"type": "string",
"minLength": 1
}
}
}
},
"identifiers": {
Expand Down Expand Up @@ -67,15 +97,21 @@
"items": {
"type": "object",
"required": [
"language"
"name", "code"
],
"properties": {
"language": {
"title": "Language",
"description": "Required. Language of the resource, primary or not.",
"name": {
"title": "Language name",
"description": "Name value of the language.",
"type": "string",
"default": "Français"
},
"code": {
"title": "Bibliographic language code",
"description": "Bibligraphic code of language.",
"type": "string",
"default": "fre",
"validationMessage": "Required. Language of the resource, primary or not.",
"validationMessage": "Bibliographic language code is required.",
"enum": [
"fre",
"ger",
Expand Down Expand Up @@ -161,10 +197,40 @@
"title": "Subject",
"description": "Subject of the resource.",
"type": "array",
"minItems": 1,
"additionalProperties": false,
"items": {
"type": "string",
"minLength": 1
"type": "object",
"additionalProperties": false,
"required": [
"language", "value"
],
"properties": {
"language": {
"title": "Subject language",
"description": "Language of subject.",
"type": "string",
"enum": [
"fre",
"ger",
"eng",
"ita",
"spa",
"ara",
"chi",
"lat",
"heb",
"jpn",
"por",
"rus"
]
},
"value": {
"title": "Subjects list",
"description": "A list of subjects.",
"type": "array",
"minLength": 1
}
}
}
},
"notes": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
"type": "text"
},
"abstracts": {
"type": "text"
"type": "object"
},
"subjects": {
"type": "text",
"copy_to": "facet_subjects"
"type": "object",
"properties": {
"value": {
"type": "text",
"copy_to": "facet_subjects"
}
}
},
"facet_subjects": {
"type": "keyword"
Expand All @@ -41,7 +46,7 @@
"languages": {
"type": "object",
"properties": {
"language": {
"name": {
"type": "keyword"
}
}
Expand Down
2 changes: 1 addition & 1 deletion sonar/modules/documents/marshmallow/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DocumentMetadataSchemaV1(StrictKeysMixin):

pid = PersistentIdentifier()
title = SanitizedUnicode(required=True)
abstracts = fields.List(fields.Str())
abstracts = fields.List(fields.Dict())
authors = fields.Dict(dump_only=True)
institution = fields.Dict(dump_only=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
-->

<div ng-repeat="record in vm.invenioSearchResults.hits.hits track by $index">
<p class="m-0"><i>{{record.metadata.institution.name}}</i></p>
<h2 class="mb-3"><a target="_self" ng-href="/organization/{{config.ir}}/documents/{{ record.id }}">{{ record.metadata.title }}</a></h2>
<p><span class="badge badge-secondary text-light mr-2 p-2" ng-repeat="author in record.metadata.authors">{{author.name}}</span></p>
<p class="text-justify">
{{record.metadata.abstracts[0]}}
<p class="m-0"><i>{{ record.metadata.institution.name }}</i></p>
<h2 class="mb-3"><a target="_self"
ng-href="/organization/{{ config.ir }}/documents/{{ record.id }}">{{ record.metadata.title }}</a></h2>
<p><span class="badge badge-secondary text-light mr-2 p-2"
ng-repeat="author in record.metadata.authors">{{ author.name }}</span></p>
<p class="text-justify" ng-repeat="abstract in record.metadata.abstracts" ng-if="$first">
{{ abstract.value }}
</p>
<hr />
</div>
57 changes: 56 additions & 1 deletion sonar/modules/documents/templates/documents/record.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

{%- extends config.RECORDS_UI_BASE_TEMPLATE %}

{% from 'sonar/macros/macro.html' import dl %}

{%- macro record_content(data) %}
{% for key, value in data.items() recursive %}
<li class="list-group-item">
Expand Down Expand Up @@ -38,9 +40,62 @@
{%- endmacro %}

{%- block page_body %}
<h2>{{record.title}}</h2>
<!--
<ul class="list-group">
{{ record_content(record.replace_refs()) }}
</ul>
-->
{% set record = record.replace_refs() %}
<h1 class="text-primary">{{ record.title }}</h1>
{% if record.institution %}
<h5 class="text-secondary">{{ record.institution.name }}</h5>
{% endif %}

<section class="mt-3">
<dl class="row">
<!-- AUTHORS -->
{% if record.authors|length > 0 %}
{{ dl(_('Authors'), record.authors | authors_format) }}
{% endif %}

<!-- ABSTRACTS -->
{% if record.abstracts|length > 0 %}
{{ dl(_('Abstract'), record.abstracts | translate_content(current_i18n.language) | nl2br ) }}
{% endif %}

<!-- PHYSICAL DESCRIPTION -->
{% if record.extent or record.otherMaterialCharacteristics or record.formats %}
{% set formats = ', '.join(record.formats) %}
{% set description = ', '.join([record.extent, record.otherMaterialCharacteristics, formats]|select) %}
{{ dl(_('Physical description'), description) }}
{% endif %}

<!-- SUBJECTS -->
{% if record.subjects|length > 0 %}
{{ dl(_('Subject'), record.subjects | translate_content(current_i18n.language) | join(', ')) }}
{% endif %}

<!-- LANGUAGE -->
{% if record.languages|length > 0 %}
{{ dl(_('Language'), record.languages[0].name) }}
{% endif %}

<!-- NOTES -->
{% if record.notes|length > 0 %}
{{ dl(_('Notes'), record.notes | join('\n') | nl2br) }}
{% endif %}

<!-- IDENTIFIERS -->
{% if record.identifiers %}
{% if record.identifiers.isbn %}
{{ dl(_('ISBN'), record.identifiers.isbn) }}
{% endif %}
{% endif %}

<!-- PERMANENT LINK -->
{% set link = url_for('invenio_records_ui.document', pid_value=record.pid, ir=g.ir|default('sonar'), _external=True) %}
{{ dl(_('Permalink'), '<a href="' + link + '">' + link + '</a>') }}
</dl>
</section>
{%- endblock %}

Loading

0 comments on commit 272f6d3

Please sign in to comment.