Skip to content

Commit

Permalink
custom_field: added subject field to community
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatimah committed Feb 22, 2024
1 parent 95bf1c3 commit 7d99cc6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
10 changes: 9 additions & 1 deletion app_data/vocabularies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ licenses:
data-file: vocabularies/licenses.csv
descriptiontypes:
pid-type: dty
data-file: vocabularies/description_types.yaml
data-file: vocabularies/description_types.yaml
subjects:
pid-type: sub
schemes:
- id: EuroSci
name: Euro Science Vocabulary
uri: "https://op.europa.eu/en/web/eu-vocabularies/dataset/-/resource?uri=http://publications.europa.eu/resource/dataset/euroscivoc"
data-file: vocabularies/subjects.yaml

9 changes: 9 additions & 0 deletions app_data/vocabularies/subjects.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- id: 1_es
scheme: EuroSci
subject: "Mathematics"
- id: 2_es
scheme: EuroSci
subject: "Physics"
- id: 3_es
scheme: EuroSci
subject: "Psychology"
9 changes: 7 additions & 2 deletions invenio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ from invenio_rdm_records.services.components import DefaultRecordsComponents
from invenio_oauthclient.views.client import auto_redirect_login

from invenio_communities.communities.services import facets as community_facets

from zenodo_rdm.custom_fields import CUSTOM_FIELDS_UI, CUSTOM_FIELDS, CUSTOM_FIELDS_FACETS, NAMESPACES
from zenodo_rdm.custom_fields import CUSTOM_FIELDS_UI, CUSTOM_FIELDS, CUSTOM_FIELDS_FACETS, NAMESPACES, COMMUNITY_NAMESPACES,COMMUNITY_FIELDS, COMMUNITY_FIELDS_UI
from zenodo_rdm.views import frontpage_view_function
from zenodo_rdm.permissions import ZenodoCommunityPermissionPolicy, ZenodoRDMRecordPermissionPolicy
from zenodo_rdm.api import ZenodoRDMRecord, ZenodoRDMDraft
Expand Down Expand Up @@ -642,6 +641,12 @@ RDM_CUSTOM_FIELDS = CUSTOM_FIELDS

RDM_CUSTOM_FIELDS_UI = CUSTOM_FIELDS_UI # UI components

COMMUNITIES_CUSTOM_FIELDS_UI = COMMUNITY_FIELDS_UI

COMMUNITIES_CUSTOM_FIELDS = COMMUNITY_FIELDS

COMMUNITIES_NAMESPACES = COMMUNITY_NAMESPACES

# Invenio-Communities
# ==============
COMMUNITIES_GROUPS_ENABLED = False
Expand Down
6 changes: 6 additions & 0 deletions site/zenodo_rdm/custom_fields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
BIODIV_FIELDS,
BIODIVERSITY_FIELDS_UI,
)

from.community_fields import (
COMMUNITY_FIELDS_UI,
COMMUNITY_FIELDS,
COMMUNITY_NAMESPACES,
)
from .legacy import LEGACY_CUSTOM_FIELDS
from .publishing import PUBLISHING_FIELDS_UI

Expand Down
43 changes: 43 additions & 0 deletions site/zenodo_rdm/custom_fields/community_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 CERN.
#
# ZenodoRDM is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Custom fields."""
from invenio_i18n import lazy_gettext as _
from invenio_vocabularies.services.custom_fields import VocabularyCF

COMMUNITY_FIELDS_UI = [{
"section": _("Subjects"),
"fields": [dict(
field="es:subjects",
ui_widget="AutocompleteDropdown",
props=dict(
label="Keywords and subjects",
icon="tag",
description="The subjects related to the community",
placeholder="Search for a subject by name e.g. Psychology ...",
autocompleteFrom="/api/vocabularies/languages",
autocompleteFromAcceptHeader="application/vnd.inveniordm.v1+json",
required=False,
multiple=True,
clearable=True,
),
)]
}]


COMMUNITY_FIELDS = {VocabularyCF(
name="es:subjects",
vocabulary_id="es:subjects",
multiple=True,
dump_options=False,
)
}


COMMUNITY_NAMESPACES = {
"es": "https://op.europa.eu/en/web/eu-vocabularies/dataset/-/resource?uri=http://publications.europa.eu/resource/dataset/euroscivoc",
}

0 comments on commit 7d99cc6

Please sign in to comment.