-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend & ui: inject data authors from literature link
- Loading branch information
Showing
15 changed files
with
420 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# | ||
# Copyright (C) 2019 CERN. | ||
# | ||
# inspirehep is free software; you can redistribute it and/or modify it under | ||
# the terms of the MIT License; see LICENSE file for more details. | ||
|
||
from inspire_dojson.utils import strip_empty_values | ||
from marshmallow import Schema, fields, post_dump | ||
|
||
from inspirehep.records.marshmallow.data.utils import get_authors | ||
|
||
|
||
class DataAuthorsSchema(Schema): | ||
authors = fields.Method("get_authors", dump_only=True) | ||
|
||
def get_authors(self, data): | ||
return get_authors(data) | ||
|
||
@post_dump | ||
def strip_empty(self, data): | ||
return strip_empty_values(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from inspire_dojson.utils import get_recid_from_ref | ||
from inspire_utils.record import get_value | ||
|
||
from inspirehep.records.marshmallow.literature.common.author import AuthorSchemaV1 | ||
from inspirehep.search.api import LiteratureSearch | ||
|
||
|
||
def get_authors(data): | ||
schema = AuthorSchemaV1(many=True) | ||
authors = data.get("authors", []) | ||
if authors: | ||
return schema.dump(authors)[0] | ||
|
||
literature = get_value(data, "literature") | ||
if not literature: | ||
return schema.dump(authors)[0] | ||
|
||
control_number = get_recid_from_ref(get_value(literature[0], "record")) | ||
if not control_number: | ||
return schema.dump(authors)[0] | ||
|
||
literature_record = LiteratureSearch.get_records_by_pids( | ||
[(0, control_number)], source="authors" | ||
) | ||
if not literature_record: | ||
return schema.dump(authors)[0] | ||
|
||
linked_authors = literature_record[0].to_dict().get("authors", []) | ||
return schema.dump(linked_authors)[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.