Skip to content

Commit

Permalink
openaire: grant links generation and test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Ioannidis <a.ioannidis@cern.ch>
  • Loading branch information
slint committed Jun 1, 2017
1 parent 31b6972 commit e131d50
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion tests/unit/records/test_schemas_openaire_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_grants(app, db, minimal_oai_record, recid_pid):
minimal_oai_record['grants'] = [
{
'acronym': 'WorkAble',
'title': 'Making Capabilities/Design Work',
'identifiers': {
'eurepo': 'info:eu-repo/grantAgreement/EC/FP7/244909/'
},
Expand All @@ -103,7 +104,8 @@ def test_grants(app, db, minimal_oai_record, recid_pid):
obj = openaire_json_v1.transform_record(
recid_pid, Record(minimal_oai_record))
assert obj['linksToProjects'] == [
'info:eu-repo/grantAgreement/EC/FP7/244909///WorkAble'
'info:eu-repo/grantAgreement/EC/FP7/244909/'
'/Making Capabilities%2FDesign Work/WorkAble'
]


Expand Down
2 changes: 1 addition & 1 deletion zenodo/modules/deposit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
from invenio_pidstore.resolver import Resolver
from invenio_records_files.models import RecordsBuckets

from zenodo.modules.deposit.utils import delete_record
from zenodo.modules.records.permissions import record_permission_factory

from .api import ZenodoDeposit
from .fetchers import zenodo_deposit_fetcher
from .forms import RecordDeleteForm
from .tasks import datacite_inactivate, datacite_register
from zenodo.modules.deposit.utils import delete_record

blueprint = Blueprint(
'zenodo_deposit',
Expand Down
1 change: 1 addition & 0 deletions zenodo/modules/openaire/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def openaire_original_id(record, oatype):

return prefix, value


def openaire_link(record):
"""Compute an OpenAIRE link."""
oatype = openaire_type(record)
Expand Down
15 changes: 7 additions & 8 deletions zenodo/modules/openaire/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@

from __future__ import absolute_import, print_function

from collections import namedtuple

from flask import current_app
from marshmallow import Schema, fields, missing

from zenodo.modules.records.models import ObjectType
from zenodo.modules.records.serializers.fields import DateString

from .helpers import openaire_original_id, openaire_type
from .helpers import openaire_original_id


class RecordSchemaOpenAIREJSON(Schema):
Expand Down Expand Up @@ -123,11 +121,12 @@ def get_links_to_projects(self, obj):
grants = metadata.get('grants', [])
links = []
for grant in grants:
# Add grant acronynm to the link:
# [info:eu-repo/grantAgreement/EC/FP6/027819/] + [//ICEA]
eurepo = grant.get('identifiers', {}).get('eurepo')
links.append('{eurepo}//{acronym}'.format(
eurepo=eurepo, acronym=grant.get('acronym', '')))
eurepo = grant.get('identifiers', {}).get('eurepo', '')
if eurepo:
links.append('{eurepo}/{title}/{acronym}'.format(
eurepo=eurepo,
title=grant.get('title', '').replace('/', '%2F'),
acronym=grant.get('acronym', '')))
return links or missing

def get_pids(self, obj):
Expand Down

0 comments on commit e131d50

Please sign in to comment.