Skip to content

Commit

Permalink
thesis: add department and type
Browse files Browse the repository at this point in the history
  • Loading branch information
tmorrell committed Mar 20, 2024
1 parent d39a640 commit 712c50c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class Thesis extends Component {
const {
fieldPath, // injected by the custom field loader via the `field` config property
university,
department,
type,
icon,
label,
} = this.props;
Expand All @@ -29,16 +31,36 @@ export class Thesis extends Component {
</>
)}
<Grid padded>
<Grid.Column width="16">
<Grid.Column width="6">
<Input
fieldPath={fieldPath}
fieldPath={`${fieldPath}.university`}
label={university.label}
placeholder={university.placeholder}
/>
{university.description && (
<label className="helptext mb-0">{university.description}</label>
)}
</Grid.Column>
<Grid.Column width="6">
<Input
fieldPath={`${fieldPath}.department`}
label={department.label}
placeholder={department.placeholder}
/>
{department.description && (
<label className="helptext mb-0">{department.description}</label>
)}
</Grid.Column>
<Grid.Column width="4">
<Input
fieldPath={`${fieldPath}.type`}
label={type.label}
placeholder={type.placeholder}
/>
{type.description && (
<label className="helptext mb-0">{type.description}</label>
)}
</Grid.Column>
</Grid>
</>
);
Expand All @@ -48,6 +70,8 @@ export class Thesis extends Component {
Thesis.propTypes = {
fieldPath: PropTypes.string.isRequired,
university: PropTypes.object.isRequired,
department: PropTypes.object.isRequired,
type: PropTypes.object.isRequired,
icon: PropTypes.string,
label: PropTypes.string,
};
Expand Down
50 changes: 46 additions & 4 deletions invenio_rdm_records/contrib/thesis/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,56 @@
Implements the following fields:
- thesis.university
- thesis.department
- thesis.type
"""
from invenio_i18n import lazy_gettext as _
from invenio_records_resources.services.custom_fields import TextCF
from invenio_records_resources.services.custom_fields import BaseCF
from marshmallow import fields
from marshmallow_utils.fields import SanitizedUnicode


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

@property
def field(self):
"""Thesis fields definitions."""
return fields.Nested(
{
"university": SanitizedUnicode(),
"department": SanitizedUnicode(),
"type": SanitizedUnicode(),
}
)

@property
def mapping(self):
"""Thesis search mappings."""
return {
"type": "object",
"properties": {
"university": {"type": "keyword"},
"department": {"type": "keyword"},
"type": {"type": "keyword"},
},
}


THESIS_NAMESPACE = {
# Thesis
"thesis": None,
"thesis": "",
}

THESIS_CUSTOM_FIELDS = [
TextCF(name="thesis:university"),
ThesisCF(name="thesis:thesis"),
]

THESIS_CUSTOM_FIELDS_UI = {
"section": _("Thesis"),
"fields": [
{
"field": "thesis:university",
"field": "thesis:thesis",
"ui_widget": "Thesis",
"props": {
"label": _("Thesis"),
Expand All @@ -36,6 +68,16 @@
"placeholder": "",
"description": "",
},
"department": {
"label": _("Awarding department"),
"placeholder": "",
"description": "",
},
"type": {
"label": _("Thesis type"),
"placeholder": "PhD",
"description": "The type of thesis (e.g. Masters, PhD, Engineers, Bachelors)",
},
},
}
],
Expand Down
14 changes: 12 additions & 2 deletions invenio_rdm_records/resources/serializers/ui/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,23 @@ def _format_imprint(imprint, publisher):

return formatted

def _format_thesis(thesis):
"""Formats a thesis object into a string based on its attributes."""
university = thesis.get("university", "")
department = thesis.get("department", "")
ttype = thesis.get("type", "")
fields = [university, department, ttype]
formatted = ", ".join(filter(None, fields))
return formatted

attr = "custom_fields"
field = obj.get(attr, {})
publisher = obj.get("metadata", {}).get("publisher")

# Retrieve publishing related custom fields
journal = field.get("journal:journal")
imprint = field.get("imprint:imprint")
thesis = field.get("thesis:university")
thesis = field.get("thesis:thesis")

publication_date = obj.get("metadata", {}).get("publication_date", None)
result = {}
Expand All @@ -287,7 +296,8 @@ def _format_imprint(imprint, publisher):
result.update({"imprint": imprint_string})

if thesis:
result.update({"thesis": thesis})
thesis_string = _format_thesis(thesis)
result.update({"thesis": thesis_string})

if len(result.keys()) == 0:
return missing
Expand Down

0 comments on commit 712c50c

Please sign in to comment.