Skip to content

Commit

Permalink
contrib: added meeting custom field
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandromumo authored and kpsherva committed Mar 6, 2023
1 parent d096879 commit 86c92b7
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
13 changes: 13 additions & 0 deletions invenio_rdm_records/contrib/meeting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Copyright (C) 2023 CERN.
#
# Invenio-RDM-Records is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
"""Meeting contrib module."""
from .custom_fields import (
MEETING_CUSTOM_FIELDS,
MEETING_CUSTOM_FIELDS_UI,
MEETING_NAMESPACE,
)

__all__ = (MEETING_CUSTOM_FIELDS, MEETING_CUSTOM_FIELDS_UI, MEETING_NAMESPACE)
121 changes: 121 additions & 0 deletions invenio_rdm_records/contrib/meeting/custom_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#
# Copyright (C) 2023 CERN.
#
# Invenio-RDM-Records is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
"""Meeting custom fields.
Implements the following fields:
- meeting.acronym
- meeting.dates
- meeting.place
- meeting.session_part
- meeting.session
- meeting.title
- meeting.url
"""

from invenio_i18n import lazy_gettext as _
from invenio_records_resources.services.custom_fields import BaseCF
from marshmallow import fields, validate
from marshmallow_utils.fields import SanitizedUnicode

from invenio_rdm_records.services.schemas.metadata import _valid_url


class MeetingCF(BaseCF):
"""Nested custom field."""

@property
def field(self):
"""Meeting fields definitions."""
return fields.Nested(
{
"acronym": SanitizedUnicode(),
"dates": SanitizedUnicode(),
"place": SanitizedUnicode(),
"session_part": SanitizedUnicode(),
"session": SanitizedUnicode(),
"title": SanitizedUnicode(),
"url": SanitizedUnicode(
validate=_valid_url(error_msg="You must provide a valid URL."),
),
}
)

@property
def mapping(self):
"""Meeting search mappings."""
return {
"type": "object",
"properties": {
"acronym": {"type": "keyword"},
"dates": {"type": "keyword"},
"place": {"type": "text"},
"session_part": {"type": "keyword"},
"session": {"type": "keyword"},
"title": {"type": "text"},
"url": {"type": "keyword"},
},
}


MEETING_NAMESPACE = {
# Meeting
"meeting": "",
}


MEETING_CUSTOM_FIELDS = [
MeetingCF(name="meeting:meeting"),
]

MEETING_CUSTOM_FIELDS_UI = {
"section": _("Conference"),
"fields": [
{
"field": "meeting:meeting",
"ui_widget": "Meeting",
"template": "meeting.html",
"props": {
"label": _("Conference"),
"title": {
"label": _("Conference title"),
"placeholder": _(""),
"description": _("Conference title"),
},
"acronym": {
"label": _("Acronym"),
"placeholder": _(""),
"description": _("Acronym that represents the conference"),
},
"dates": {
"label": _("Dates"),
"placeholder": _("e.g. 21-22 November 2022"),
"description": _("Dates on which the conference took place"),
},
"place": {
"label": _("Place"),
"placeholder": _(""),
"description": _("Location where the conference took place"),
},
"url": {
"label": _("Website"),
"placeholder": _(""),
"description": _("e.g. https://zenodo.org"),
},
"session": {
"label": _("Session"),
"placeholder": _("e.g. VI"),
"description": _("Number of session within the conference."),
},
"session_part": {
"label": _("Part"),
"placeholder": _("e.g. 1"),
"description": _("Conference session's part number."),
},
},
}
],
}
36 changes: 36 additions & 0 deletions invenio_rdm_records/templates/semantic-ui/meeting.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@


{% if field_value.get('title') %}
<dt class="ui tiny header">{{ _("Title")}}</dt>
<dd>{{field_value.get('title')}}</dd>
{% endif %}

{% if field_value.get('acronym') %}
<dt class="ui tiny header">{{ _("Acronym")}}</dt>
<dd>{{field_value.get('acronym')}}</dd>
{% endif %}

{% if field_value.get('dates') %}
<dt class="ui tiny header">{{ _("Dates")}}</dt>
<dd>{{field_value.get('dates')}}</dd>
{% endif %}

{% if field_value.get('place') %}
<dt class="ui tiny header">{{ _("Place")}}</dt>
<dd>{{field_value.get('place')}}</dd>
{% endif %}

{% if field_value.get('url') %}
<dt class="ui tiny header">{{ _("Website")}}</dt>
<dd>{{field_value.get('url')}}</dd>
{% endif %}

{% if field_value.get('session') %}
<dt class="ui tiny header">{{ _("Session")}}</dt>
<dd>{{field_value.get('session')}}</dd>
{% endif %}

{% if field_value.get('session_part') %}
<dt class="ui tiny header">{{ _("Session part")}}</dt>
<dd>{{field_value.get('session_part')}}</dd>
{% endif %}

0 comments on commit 86c92b7

Please sign in to comment.