-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
items: Add call number validation to ItemSchema
- Loading branch information
1 parent
65a6bb2
commit 0b32a02
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# CDS-ILS is free software; you can redistribute it and/or modify it under | ||
# the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""CDS-ILS items module.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# CDS-ILS is free software; you can redistribute it and/or modify it under | ||
# the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""CDS-ILS items loaders.""" | ||
|
||
from invenio_app_ils.items.loaders.jsonschemas.items import ( | ||
ItemSchemaV1 as ILSItemSchemaV1, | ||
) | ||
from invenio_app_ils.records.loaders import ils_marshmallow_loader | ||
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema | ||
from marshmallow import ValidationError, fields | ||
|
||
|
||
def validate_call_number_exists(identifiers): | ||
"""Check if Call number exists.""" | ||
for identifier in identifiers: | ||
if identifier["scheme"] == "CALL_NUMBER": | ||
return | ||
raise ValidationError("The Call number identifier field is mandatory.") | ||
|
||
|
||
class ItemSchemaV1(ILSItemSchemaV1): | ||
"""Item schema.""" | ||
|
||
identifiers = fields.List( | ||
fields.Nested(IdentifierSchema), | ||
required=True, | ||
validate=validate_call_number_exists, | ||
) | ||
|
||
|
||
item_loader = ils_marshmallow_loader(ItemSchemaV1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters