Skip to content

Commit 7ece218

Browse files
committed
custom_fields: added fallback to old thesis format
1 parent c807b72 commit 7ece218

File tree

2 files changed

+49
-38
lines changed
  • invenio_rdm_records
    • assets/semantic-ui/js/invenio_rdm_records/src/deposit/customFields
    • resources/serializers/ui

2 files changed

+49
-38
lines changed

invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/customFields/Thesis.js

+40-30
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export class Thesis extends Component {
2222
icon,
2323
label,
2424
} = this.props;
25+
// For backwards compability added conditional rendering for fields; it is based on their definition in the props in THESIS_CUSTOM_FIELDS_UI
26+
const uniWidth = department && type ? 6 : 16;
2527
return (
2628
<>
2729
{label && (
@@ -31,36 +33,44 @@ export class Thesis extends Component {
3133
</>
3234
)}
3335
<Grid padded>
34-
<Grid.Column width="6">
35-
<Input
36-
fieldPath={`${fieldPath}.university`}
37-
label={university.label}
38-
placeholder={university.placeholder}
39-
/>
40-
{university.description && (
41-
<label className="helptext mb-0">{university.description}</label>
42-
)}
43-
</Grid.Column>
44-
<Grid.Column width="6">
45-
<Input
46-
fieldPath={`${fieldPath}.department`}
47-
label={department.label}
48-
placeholder={department.placeholder}
49-
/>
50-
{department.description && (
51-
<label className="helptext mb-0">{department.description}</label>
52-
)}
53-
</Grid.Column>
54-
<Grid.Column width="4">
55-
<Input
56-
fieldPath={`${fieldPath}.type`}
57-
label={type.label}
58-
placeholder={type.placeholder}
59-
/>
60-
{type.description && (
61-
<label className="helptext mb-0">{type.description}</label>
62-
)}
63-
</Grid.Column>
36+
{university && (
37+
<Grid.Column width={uniWidth}>
38+
<Input
39+
fieldPath={`${fieldPath}.university`}
40+
label={university.label}
41+
placeholder={university.placeholder}
42+
/>
43+
{university.description && (
44+
<label className="helptext mb-0">{university.description}</label>
45+
)}
46+
</Grid.Column>
47+
)}
48+
49+
{department && (
50+
<Grid.Column width={6}>
51+
<Input
52+
fieldPath={`${fieldPath}.department`}
53+
label={department.label}
54+
placeholder={department.placeholder}
55+
/>
56+
{department.description && (
57+
<label className="helptext mb-0">{department.description}</label>
58+
)}
59+
</Grid.Column>
60+
)}
61+
62+
{type && (
63+
<Grid.Column width={4}>
64+
<Input
65+
fieldPath={`${fieldPath}.type`}
66+
label={type.label}
67+
placeholder={type.placeholder}
68+
/>
69+
{type.description && (
70+
<label className="helptext mb-0">{type.description}</label>
71+
)}
72+
</Grid.Column>
73+
)}
6474
</Grid>
6575
</>
6676
);

invenio_rdm_records/resources/serializers/ui/schema.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,13 @@ def _format_imprint(imprint, publisher):
287287
return formatted
288288

289289
def _format_thesis(thesis):
290-
"""Formats a thesis object into a string based on its attributes."""
291-
university = thesis.get("university", "")
292-
department = thesis.get("department", "")
293-
ttype = thesis.get("type", "")
294-
fields = [university, department, ttype]
295-
formatted = ", ".join(filter(None, fields))
296-
return formatted
290+
"""Formats a thesis entry into a string based on its attributes."""
291+
if not isinstance(thesis, dict):
292+
return thesis
293+
294+
fields = ["university", "department", "type"]
295+
formatted = [thesis.get(field, "") for field in fields]
296+
return ", ".join(filter(None, parts))
297297

298298
attr = "custom_fields"
299299
field = obj.get(attr, {})
@@ -302,7 +302,8 @@ def _format_thesis(thesis):
302302
# Retrieve publishing related custom fields
303303
journal = field.get("journal:journal")
304304
imprint = field.get("imprint:imprint")
305-
thesis = field.get("thesis:thesis")
305+
# "thesis:university" is deprecated and kept for compatibility, will be removed later.
306+
thesis = field.get("thesis:thesis") or field.get("thesis:university")
306307

307308
publication_date = obj.get("metadata", {}).get("publication_date", None)
308309
result = {}

0 commit comments

Comments
 (0)