• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rero / rero-mef / 16621609190

30 Jul 2025 11:43AM UTC coverage: 84.491% (+0.008%) from 84.483%
16621609190

push

github

rerowep
chore: update dependencies

Co-Authored-by: Peter Weber <peter.weber@rero.ch>

4560 of 5397 relevant lines covered (84.49%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.16
/rero_mef/places/serializers.py
1
# RERO MEF
2
# Copyright (C) 2021 RERO
3
#
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU Affero General Public License as published by
6
# the Free Software Foundation, version 3 of the License.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Affero General Public License for more details.
12
#
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15

16
"""Record serialization."""
17

18
from invenio_records_rest.links import default_links_factory_with_additional
1✔
19
from invenio_records_rest.schemas import RecordSchemaJSONV1
1✔
20
from invenio_records_rest.serializers.json import JSONSerializer
1✔
21
from invenio_records_rest.serializers.response import (
1✔
22
    record_responsify,
23
    search_responsify,
24
)
25

26
from .mef.api import PlaceMefRecord
1✔
27

28

29
def add_links(pid, record):
1✔
30
    """Add MEF link to places."""
31
    links = {}
×
32
    for idx, mef_pid in enumerate(
×
33
        PlaceMefRecord.get_mef(record.pid, record.name, pid_only=True)
34
    ):
35
        number = f"-{idx}" if idx else ""
×
36
        links[f"mef{number}"] = "{scheme}://{host}/api/places/mef/" + str(mef_pid)
×
37

38
    link_factory = default_links_factory_with_additional(links)
×
39
    return link_factory(pid)
×
40

41

42
class ReroMefSerializer(JSONSerializer):
1✔
43
    """Mixin serializing records as JSON."""
44

45
    def serialize(self, pid, record, links_factory=None, **kwargs):
1✔
46
        """Serialize a single record and persistent identifier.
47

48
        :param pid: Persistent identifier instance.
49
        :param record: Record instance.
50
        :param links_factory: Factory function for record links.
51
        """
52
        return super().serialize(
×
53
            pid=pid, record=record, links_factory=add_links, **kwargs
54
        )
55

56

57
json_ = ReroMefSerializer(RecordSchemaJSONV1)
1✔
58
"""JSON v1 serializer."""
1✔
59

60
json_place_response = record_responsify(json_, "application/rero+json")
1✔
61
json_place_search = search_responsify(json_, "application/rero+json")
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc