From eb0a81c18fd37f596667bcd8db64d9150d075da0 Mon Sep 17 00:00:00 2001 From: Philipp Gualdi Date: Wed, 27 Sep 2023 09:02:06 +0200 Subject: [PATCH] modification: resource type translate --- .../records/fields/resourcetype.py | 9 +++++++++ .../resources/serializers/ui/fields/metadata.py | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 invenio_records_marc21/records/fields/resourcetype.py diff --git a/invenio_records_marc21/records/fields/resourcetype.py b/invenio_records_marc21/records/fields/resourcetype.py new file mode 100644 index 00000000..538b4975 --- /dev/null +++ b/invenio_records_marc21/records/fields/resourcetype.py @@ -0,0 +1,9 @@ +from enum import Enum + + +class ResourceTypeEnum(Enum): + """Enum defining resource type.""" + + HSMASTER = "HS-MASTER" + + HSDISS = "HS-DISS" diff --git a/invenio_records_marc21/resources/serializers/ui/fields/metadata.py b/invenio_records_marc21/resources/serializers/ui/fields/metadata.py index 8935d606..45fbbce2 100644 --- a/invenio_records_marc21/resources/serializers/ui/fields/metadata.py +++ b/invenio_records_marc21/resources/serializers/ui/fields/metadata.py @@ -9,13 +9,17 @@ # details. """Metadata field for marc21 records.""" + import re from contextlib import suppress from dataclasses import dataclass from typing import Dict, List +from flask_babelex import gettext as _ from marshmallow.fields import Field +from .....records.fields.resourcetype import ResourceTypeEnum + class Marc21Controlfield: """Marc21Controlfield.""" @@ -215,8 +219,14 @@ def get_description(self, fields): def get_resource_type(self, fields): """Get resource type.""" resource_type = fields.get_values("970", "2", "_", subfield_notation="d") + resource_types = { + ResourceTypeEnum.HSMASTER.value: _("Masterthesis"), + ResourceTypeEnum.HSDISS.value: _("Dissertation"), + } - if resource_type: - return resource_type[0] + if not resource_type: + return "" + if resource_type[0] in resource_types.keys(): + return resource_types.get(resource_type[0]) - return "" + return resource_type[0]