Skip to content

Commit

Permalink
utils: added swh link renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandromumo authored and slint committed Nov 30, 2023
1 parent 033a98c commit 1f4e4a8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
8 changes: 6 additions & 2 deletions invenio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ from invenio_records_resources.services.records.queryparser import (
QueryParser,
SearchFieldTransformer,
)
from invenio_rdm_records.services.components.signal import SignalComponent
from invenio_rdm_records.services.components import DefaultRecordsComponents
from invenio_oauthclient.views.client import auto_redirect_login

Expand Down Expand Up @@ -588,7 +589,8 @@ from zenodo_rdm.utils import (
f1000_link_render,
github_link_render,
openaire_link_render,
reana_link_render
reana_link_render,
swh_link_render
)

APP_RDM_RECORD_LANDING_PAGE_EXTERNAL_LINKS = [
Expand All @@ -597,6 +599,8 @@ APP_RDM_RECORD_LANDING_PAGE_EXTERNAL_LINKS = [
{ "id": "github", "render": github_link_render},
{ "id": "briefideas", "render": briefideas_link_render},
{ "id": "openaire", "render": openaire_link_render},
{ "id": "softwareheritage", "render": swh_link_render},

]

APP_RDM_DEPOSIT_FORM_DEFAULTS = {
Expand Down Expand Up @@ -662,7 +666,7 @@ OPENAIRE_PORTAL_URL = "https://explore.openaire.eu"
OPENAIRE_DIRECT_INDEXING_ENABLED = True
"""Enable sending published records for direct indexing at OpenAIRE."""

RDM_RECORDS_SERVICE_COMPONENTS = DefaultRecordsComponents + [OpenAIREComponent]
RDM_RECORDS_SERVICE_COMPONENTS = DefaultRecordsComponents + [OpenAIREComponent, SignalComponent]
"""Addd OpenAIRE component to records service."""

RDM_SEARCH_SORT_BY_VERIFIED = True
Expand Down
1 change: 1 addition & 0 deletions site/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ install_requires =
nameparser>=1.1.1
pyinstrument>=4.5.1
sqltap>=0.3.11
invenio_swh>=0.20.0,<1.0.0

[options.extras_require]
tests =
Expand Down
36 changes: 36 additions & 0 deletions site/zenodo_rdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import idutils
from flask import current_app, url_for
from invenio_app_rdm.records_ui.utils import dump_external_resource
from invenio_rdm_records.proxies import current_rdm_records_service as service
from invenio_swh.proxies import current_swh_service as service_swh

from invenio_i18n import _

from zenodo_rdm.openaire.utils import openaire_link
Expand Down Expand Up @@ -130,3 +133,36 @@ def openaire_link_render(record):
)
)
return ret


def swh_link_render(record):
"""Render the swh link."""

if not current_app.config.get("SWH_ENABLED"):
return None

ret = []

pid = service.record_cls.pid.resolve(record["id"])
d_res = service_swh.get_record_deposit(pid.id)
if not d_res.deposit:
return None

swhid = d_res.deposit.swhid
if not swhid:
return None

base_url = current_app.config.get("SWH_UI_BASE_URL")
swh_stripped = swhid.split(":")[3]
swh_link = f"{base_url}/browse/directory/{swh_stripped}/"
if swh_link:
ret.append(
dump_external_resource(
swh_link,
title=f"Software Heritage",
subtitle=swhid,
section=_("Archived in"),
icon=url_for("static", filename="images/swh.png"),
)
)
return ret
Binary file added static/images/swh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1f4e4a8

Please sign in to comment.